19 #if UNITY_2019_1_OR_NEWER && INPUTSYSTEM_AVAILABLE
20 using UnityEngine.InputSystem;
44 [Obsolete(
"WandButton.System is deprecated, please use Wandbutton.T5 instead.")]
46 [Obsolete(
"WandButton.Z is deprecated, please use Wandbutton.Three instead.")]
50 #endregion Public Enums
53 #region Private Fields
55 #if UNITY_2019_1_OR_NEWER && INPUTSYSTEM_AVAILABLE
63 #region Public Functions
77 return TryGetButton(button, out var pressed, controllerIndex, playerIndex) && pressed;
92 if(!
Player.TryGetGlassesHandle(playerIndex, out var glassesHandle))
98 return Wand.TryGetButton(button, out pressed, glassesHandle, controllerIndex);
112 return TryGetButtonDown(button, out var buttonDown, controllerIndex, playerIndex) && buttonDown;
128 if(!
Player.TryGetGlassesHandle(playerIndex, out var glassesHandle))
134 return Wand.TryGetButtonDown(button, out buttonDown, glassesHandle, controllerIndex);
147 return TryGetButtonUp(button, out var buttonUp, controllerIndex, playerIndex) && buttonUp;
165 if(!
Player.TryGetGlassesHandle(playerIndex, out var glassesHandle))
171 return Wand.TryGetButtonUp(button, out buttonUp, glassesHandle, controllerIndex);
199 if(!
Player.TryGetGlassesHandle(playerIndex, out var glassesHandle))
201 stickTilt = Vector2.zero;
204 return Wand.TryGetStickTilt(out stickTilt, glassesHandle, controllerIndex);
216 if(
TryGetTrigger(out var triggerDisplacement, controllerIndex, playerIndex))
218 return triggerDisplacement;
234 if (!
Player.TryGetGlassesHandle(playerIndex, out var glassesHandle))
236 triggerDisplacement = 0f;
239 return Wand.TryGetTrigger(out triggerDisplacement, glassesHandle, controllerIndex);
259 #endregion Public Functions
262 #region Internal Functions
266 var buttonsState = controllerState.ButtonsState;
271 return buttonsState.T5;
273 return buttonsState.One;
275 return buttonsState.Two;
277 return buttonsState.Y;
279 return buttonsState.B;
281 return buttonsState.A;
283 return buttonsState.X;
285 return buttonsState.Three;
287 throw new ArgumentException(
"Invalid WandButton argument - enum value does not exist");
294 return controllerState.ButtonsValid && controllerState.GetButton(button);
297 internal static Vector2 TryGetStick(
this T5_ControllerState controllerState)
299 return controllerState.AnalogValid ? controllerState.Stick : Vector2.zero;
302 internal static float TryGetTrigger(
this T5_ControllerState controllerState)
304 return controllerState.AnalogValid ? controllerState.Trigger : 0f;
307 #if UNITY_2019_1_OR_NEWER && INPUTSYSTEM_AVAILABLE
308 internal static GlassesDevice GetGlassesDevice(
PlayerIndex playerIndex)
310 return glassesDevices[(int)playerIndex - 1];
315 return wandDevices[(int)playerIndex - 1, (
int)controllerIndex];
319 #endregion Internal Functions
322 #region Private Functions
329 #if UNITY_2019_1_OR_NEWER && INPUTSYSTEM_AVAILABLE
330 internal static void AddGlassesDevice(
PlayerIndex playerIndex)
332 var glassesDevices =
Input.glassesDevices;
333 int i = (int)playerIndex - 1;
336 if (glassesDevices[i] ==
null)
338 var preexistingGlassesDevice = InputSystem.GetDevice<GlassesDevice>($
"Player{playerIndex}");
339 if (preexistingGlassesDevice !=
null)
341 glassesDevices[i] = preexistingGlassesDevice;
342 glassesDevices[i].PlayerIndex = playerIndex;
346 glassesDevices[i] = InputSystem.AddDevice<GlassesDevice>($
"T5 Glasses - Player {playerIndex}");
347 glassesDevices[i].PlayerIndex = playerIndex;
348 InputSystem.AddDeviceUsage(glassesDevices[i], $
"Player{playerIndex}");
352 else if (!glassesDevices[i].added)
354 InputSystem.AddDevice(glassesDevices[i]);
360 var wandDevices =
Input.wandDevices;
361 int i = (int)playerIndex - 1;
362 int j = (int)controllerIndex;
367 var handednessLabel = controllerIndex ==
ControllerIndex.Right ?
"Right" :
"Left";
370 if (wandDevices[i, j] !=
null && !wandDevices[i, j].added)
372 var wandDevice = wandDevices[i, j];
373 InputSystem.AddDevice(wandDevice);
374 wandDevice.ControllerIndex = controllerIndex;
375 InputSystem.QueueConfigChangeEvent(wandDevice);
376 InputSystem.AddDevice(wandDevice);
383 WandDevice currentWandDevice = InputSystem.GetDevice<WandDevice>($
"Player{playerIndex}-{handednessLabel}Hand");
386 if (currentWandDevice !=
null)
388 wandDevices[i, j] = currentWandDevice;
393 wandDevices[i, j] = InputSystem.AddDevice<WandDevice>($
"T5 Wand - P{(int)playerIndex} {handednessLabel}");
396 wandDevices[i, j].playerIndex = playerIndex;
397 wandDevices[i, j].ControllerIndex = controllerIndex;
398 InputSystem.AddDeviceUsage(wandDevices[i, j], $
"Player{playerIndex}");
399 InputSystem.AddDeviceUsage(wandDevices[i, j], $
"Player{playerIndex}-{handednessLabel}Hand");
400 InputSystem.AddDeviceUsage(wandDevices[i, j], wandDevices[i, j].
ControllerIndex ==
ControllerIndex.Left ? CommonUsages.LeftHand : CommonUsages.RightHand);
401 InputSystem.QueueConfigChangeEvent(wandDevices[i, j]);
405 internal static void RemoveGlassesDevice(
PlayerIndex playerIndex)
407 var glassesDevices =
Input.glassesDevices;
408 int i = (int)playerIndex - 1;
411 if (glassesDevices[i] !=
null)
413 var preexistingGlassesDevice = InputSystem.GetDevice<GlassesDevice>($
"Player{playerIndex}");
414 if (preexistingGlassesDevice !=
null)
416 InputSystem.RemoveDevice(preexistingGlassesDevice);
417 glassesDevices[i] =
null;
424 var wandDevices =
Input.wandDevices;
425 int i = (int)playerIndex - 1;
426 int j = (int)controllerIndex;
431 var handednessLabel = controllerIndex ==
ControllerIndex.Right ?
"Right" :
"Left";
434 if (wandDevices[i, j] !=
null && !wandDevices[i, j].added)
436 var wandDevice = wandDevices[i, j];
437 InputSystem.RemoveDevice(wandDevice);
438 InputSystem.QueueConfigChangeEvent(wandDevice);
439 wandDevices[i, j] =
null;
446 WandDevice currentWandDevice = InputSystem.GetDevice<WandDevice>($
"Player{playerIndex}-{handednessLabel}Hand");
449 if (currentWandDevice !=
null)
451 InputSystem.RemoveDevice(currentWandDevice);
452 InputSystem.QueueConfigChangeEvent(currentWandDevice);
453 wandDevices[i, j] =
null;
459 #endregion Private Functions
TiltFive.Input.WandButton WandButton
Provides access to player settings and functionality.
static uint MAX_SUPPORTED_PLAYERS
The Wand API and runtime.
static bool TryCheckConnected(out bool connected, PlayerIndex playerIndex, ControllerIndex controllerIndex=ControllerIndex.Right)
Gets the connection status of the indicated wand.
ControllerIndex
Since wands are all physically identical (they have no "handedness"), it doesn't make sense to addres...
PlayerIndex
The Player index (e.g. Player One, Player Two, etc)