6 [RequireComponent(typeof(EventSystem))]
7 [AddComponentMenu(
"Event/Extensions/Aimer Input Module")]
30 StandaloneInputModule StandAloneSystem = GetComponent<StandaloneInputModule>();
32 if (StandAloneSystem !=
null && StandAloneSystem.enabled)
34 Debug.LogError(
"Aimer Input Module is incompatible with the StandAloneInputSystem, " +
35 "please remove it from the Event System in this scene or disable it when this module is in use");
46 ProcessInteraction(pointer, pressed, released);
51 RemovePointerData(pointer);
56 PointerEventData pointerData;
61 GetPointerData(-2, out pointerData,
true);
65 pointerData.position =
new Vector2(Screen.width * 0.5f, Screen.height * 0.5f) +
aimerOffset;
67 eventSystem.RaycastAll(pointerData, m_RaycastResultCache);
68 var raycast = FindFirstRaycast(m_RaycastResultCache);
69 pointerData.pointerCurrentRaycast = raycast;
70 m_RaycastResultCache.Clear();
74 private void ProcessInteraction(PointerEventData pointer,
bool pressed,
bool released)
76 var currentOverGo = pointer.pointerCurrentRaycast.gameObject;
78 objectUnderAimer = ExecuteEvents.GetEventHandler<ISubmitHandler>(currentOverGo);
82 pointer.eligibleForClick =
true;
83 pointer.delta = Vector2.zero;
84 pointer.pressPosition = pointer.position;
85 pointer.pointerPressRaycast = pointer.pointerCurrentRaycast;
90 var newPressed = ExecuteEvents.ExecuteHierarchy(currentOverGo, pointer, ExecuteEvents.submitHandler);
93 if (newPressed ==
null)
95 newPressed = ExecuteEvents.ExecuteHierarchy(currentOverGo, pointer, ExecuteEvents.pointerDownHandler);
96 if (newPressed ==
null)
97 newPressed = ExecuteEvents.GetEventHandler<IPointerClickHandler>(currentOverGo);
101 pointer.eligibleForClick =
false;
104 if (newPressed != pointer.pointerPress)
106 pointer.pointerPress = newPressed;
107 pointer.rawPointerPress = currentOverGo;
108 pointer.clickCount = 0;
112 pointer.pointerDrag = ExecuteEvents.GetEventHandler<IDragHandler>(currentOverGo);
114 if (pointer.pointerDrag !=
null)
115 ExecuteEvents.Execute<IBeginDragHandler>(pointer.pointerDrag, pointer, ExecuteEvents.beginDragHandler);
121 ExecuteEvents.Execute(pointer.pointerPress, pointer, ExecuteEvents.pointerUpHandler);
126 var pointerUpHandler = ExecuteEvents.GetEventHandler<IPointerClickHandler>(currentOverGo);
129 if (pointer.pointerPress == pointerUpHandler && pointer.eligibleForClick)
131 float time = Time.unscaledTime;
133 if (time - pointer.clickTime < 0.3f)
134 ++pointer.clickCount;
136 pointer.clickCount = 1;
137 pointer.clickTime = time;
139 ExecuteEvents.Execute(pointer.pointerPress, pointer, ExecuteEvents.pointerClickHandler);
141 else if (pointer.pointerDrag !=
null)
143 ExecuteEvents.ExecuteHierarchy(currentOverGo, pointer, ExecuteEvents.dropHandler);
146 pointer.eligibleForClick =
false;
147 pointer.pointerPress =
null;
148 pointer.rawPointerPress =
null;
150 if (pointer.pointerDrag !=
null)
151 ExecuteEvents.Execute(pointer.pointerDrag, pointer, ExecuteEvents.endDragHandler);
153 pointer.pointerDrag =
null;
159 base.DeactivateModule();