6 [AddComponentMenu(
"Event/Extensions/GamePad Input Module")]
9 private float m_PrevActionTime;
10 Vector2 m_LastMoveVector;
11 int m_ConsecutiveMoveCount = 0;
17 private string m_HorizontalAxis =
"Horizontal";
23 private string m_VerticalAxis =
"Vertical";
29 private string m_SubmitButton =
"Submit";
35 private string m_CancelButton =
"Cancel";
38 private float m_InputActionsPerSecond = 10;
41 private float m_RepeatDelay = 0.1f;
45 get {
return m_InputActionsPerSecond; }
46 set { m_InputActionsPerSecond = value; }
51 get {
return m_RepeatDelay; }
52 set { m_RepeatDelay = value; }
60 get {
return m_HorizontalAxis; }
61 set { m_HorizontalAxis = value; }
69 get {
return m_VerticalAxis; }
70 set { m_VerticalAxis = value; }
75 get {
return m_SubmitButton; }
76 set { m_SubmitButton = value; }
81 get {
return m_CancelButton; }
82 set { m_CancelButton = value; }
87 if (!base.ShouldActivateModule())
90 var shouldActivate =
true;
91 shouldActivate |= Input.GetButtonDown(m_SubmitButton);
92 shouldActivate |= Input.GetButtonDown(m_CancelButton);
93 shouldActivate |= !Mathf.Approximately(Input.GetAxisRaw(m_HorizontalAxis), 0.0f);
94 shouldActivate |= !Mathf.Approximately(Input.GetAxisRaw(m_VerticalAxis), 0.0f);
95 return shouldActivate;
100 StandaloneInputModule StandAloneSystem = GetComponent<StandaloneInputModule>();
102 if (StandAloneSystem && StandAloneSystem.enabled)
104 Debug.LogError(
"StandAloneInputSystem should not be used with the GamePadInputModule, " +
105 "please remove it from the Event System in this scene or disable it when this module is in use");
108 base.ActivateModule();
110 var toSelect = eventSystem.currentSelectedGameObject;
111 if (toSelect ==
null)
112 toSelect = eventSystem.firstSelectedGameObject;
114 eventSystem.SetSelectedGameObject(toSelect, GetBaseEventData());
119 base.DeactivateModule();
126 if (eventSystem.sendNavigationEvents)
141 if (eventSystem.currentSelectedGameObject ==
null)
144 var data = GetBaseEventData();
145 if (Input.GetButtonDown(m_SubmitButton))
146 ExecuteEvents.Execute(eventSystem.currentSelectedGameObject, data, ExecuteEvents.submitHandler);
148 if (Input.GetButtonDown(m_CancelButton))
149 ExecuteEvents.Execute(eventSystem.currentSelectedGameObject, data, ExecuteEvents.cancelHandler);
153 private Vector2 GetRawMoveVector()
155 Vector2 move = Vector2.zero;
156 move.x = Input.GetAxisRaw(m_HorizontalAxis);
157 move.y = Input.GetAxisRaw(m_VerticalAxis);
159 if (Input.GetButtonDown(m_HorizontalAxis))
166 if (Input.GetButtonDown(m_VerticalAxis))
181 float time = Time.unscaledTime;
183 Vector2 movement = GetRawMoveVector();
184 if (Mathf.Approximately(movement.x, 0f) && Mathf.Approximately(movement.y, 0f))
186 m_ConsecutiveMoveCount = 0;
191 bool allow = Input.GetButtonDown(m_HorizontalAxis) || Input.GetButtonDown(m_VerticalAxis);
192 bool similarDir = (Vector2.Dot(movement, m_LastMoveVector) > 0);
197 if (similarDir && m_ConsecutiveMoveCount == 1)
198 allow = (time > m_PrevActionTime + m_RepeatDelay);
201 allow = (time > m_PrevActionTime + 1f / m_InputActionsPerSecond);
206 var axisEventData = GetAxisEventData(movement.x, movement.y, 0.6f);
207 ExecuteEvents.Execute(eventSystem.currentSelectedGameObject, axisEventData, ExecuteEvents.moveHandler);
209 m_ConsecutiveMoveCount = 0;
210 m_ConsecutiveMoveCount++;
211 m_PrevActionTime = time;
212 m_LastMoveVector = movement;
213 return axisEventData.used;
218 if (eventSystem.currentSelectedGameObject ==
null)
221 var data = GetBaseEventData();
222 ExecuteEvents.Execute(eventSystem.currentSelectedGameObject, data, ExecuteEvents.updateSelectedHandler);