8 #if UNITY_2017_2_OR_NEWER 23 [Obsolete(
"Please use XboxControllerHandlerBase")]
26 [Tooltip(
"Game pad button to press for air tap.")]
27 public string GamePadButtonA =
"XBOX_A";
29 [Tooltip(
"Change this value to give a different source id to your controller.")]
30 public uint GamePadId = 50000;
32 [Tooltip(
"Elapsed time for hold started gesture in seconds.")]
33 public float HoldStartedInterval = 2.0f;
34 [Tooltip(
"Elapsed time for hold completed gesture in seconds.")]
35 public float HoldCompletedInterval = 3.0f;
37 [Tooltip(
"Name of the joystick axis that navigates around X.")]
38 public string NavigateAroundXAxisName =
"CONTROLLER_LEFT_STICK_HORIZONTAL";
40 [Tooltip(
"Name of the joystick axis that navigates around Y.")]
41 public string NavigateAroundYAxisName =
"CONTROLLER_LEFT_STICK_VERTICAL";
43 bool isAPressed =
false;
44 bool holdStarted =
false;
45 bool raiseOnce =
false;
46 bool navigationStarted =
false;
47 bool navigationCompleted =
false;
51 private enum GestureState
61 private GestureState currentGestureState;
70 if (inputManager == null)
72 Debug.LogError(
"Ensure your scene has the InputManager prefab.");
80 if (InteractionManager.numSourceStates > 0)
86 HandleGamepadAPressed();
89 private void HandleGamepadAPressed()
92 if (Input.GetButtonDown(GamePadButtonA))
96 navigationCompleted =
false;
97 currentGestureState = GestureState.APressed;
104 if (!holdStarted && !raiseOnce && !navigationStarted)
107 Invoke(
"HandleHoldStarted", HoldStartedInterval);
111 HandleGamepadAReleased();
115 private void HandleNavigation()
117 if (navigationCompleted)
122 float displacementAlongX = 0.0f;
123 float displacementAlongY = 0.0f;
127 displacementAlongX = Input.GetAxis(NavigateAroundXAxisName);
128 displacementAlongY = Input.GetAxis(NavigateAroundYAxisName);
132 Debug.LogWarningFormat(
"Ensure you have Edit > ProjectSettings > Input > Axes set with values: {0} and {1}",
133 NavigateAroundXAxisName, NavigateAroundYAxisName);
134 navigationCompleted =
true;
138 if (displacementAlongX != 0.0f || displacementAlongY != 0.0f || navigationStarted)
140 Vector3 normalizedOffset =
new Vector3(displacementAlongX, displacementAlongY, 0.0f);
142 if (!navigationStarted)
144 currentGestureState = GestureState.NavigationStarted;
145 navigationStarted =
true;
155 private void HandleGamepadAReleased()
157 if (Input.GetButtonUp(GamePadButtonA))
161 switch (currentGestureState)
163 case GestureState.NavigationStarted:
164 navigationCompleted =
true;
165 CancelInvoke(
"HandleHoldStarted");
166 CancelInvoke(
"HandleHoldCompleted");
171 case GestureState.HoldStarted:
172 CancelInvoke(
"HandleHoldCompleted");
177 case GestureState.HoldCompleted:
183 CancelInvoke(
"HandleHoldStarted");
184 CancelInvoke(
"HandleHoldCompleted");
197 navigationStarted =
false;
200 private void HandleHoldStarted()
202 if (raiseOnce || currentGestureState == GestureState.HoldStarted || currentGestureState == GestureState.NavigationStarted)
209 currentGestureState = GestureState.HoldStarted;
213 Invoke(
"HandleHoldCompleted", HoldCompletedInterval);
216 private void HandleHoldCompleted()
218 currentGestureState = GestureState.HoldCompleted;
221 #region BaseInputSource Events 230 position = Vector3.zero;
236 rotation = Quaternion.identity;
242 pointingRay =
new Ray(Vector3.zero, Vector3.zero);
248 position = Vector3.zero;
254 rotation = Quaternion.identity;
264 public override bool TryGetThumbstick(uint sourceId, out
bool isPressed, out Vector2 position)
267 position = Vector2.zero;
271 public override bool TryGetTouchpad(uint sourceId, out
bool isPressed, out
bool isTouched, out Vector2 position)
275 position = Vector2.zero;
279 public override bool TryGetSelect(uint sourceId, out
bool isPressed, out
double pressedAmount)
286 public override bool TryGetGrasp(uint sourceId, out
bool isPressed)
292 public override bool TryGetMenu(uint sourceId, out
bool isPressed)
297 #endregion BaseInputSource Events