19#if UNITY_2019_1_OR_NEWER && INPUTSYSTEM_AVAILABLE
20using 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);
266 return (0 != result);
276 #endregion Public Functions
279 #region Internal Functions
288 return buttonsState.T5;
290 return buttonsState.One;
292 return buttonsState.Two;
294 return buttonsState.Y;
296 return buttonsState.B;
298 return buttonsState.A;
300 return buttonsState.X;
302 return buttonsState.Three;
304 throw new ArgumentException(
"Invalid WandButton argument - enum value does not exist");
311 return controllerState.ButtonsValid && controllerState.GetButton(button);
316 return controllerState.AnalogValid ? controllerState.Stick : Vector2.zero;
321 return controllerState.AnalogValid ? controllerState.Trigger : 0f;
324#if UNITY_2019_1_OR_NEWER && INPUTSYSTEM_AVAILABLE
325 internal static GlassesDevice GetGlassesDevice(
PlayerIndex playerIndex)
327 return glassesDevices[(int)playerIndex - 1];
332 return wandDevices[(int)playerIndex - 1, (
int)controllerIndex];
336 #endregion Internal Functions
339 #region Private Functions
346#if UNITY_2019_1_OR_NEWER && INPUTSYSTEM_AVAILABLE
347 internal static void AddGlassesDevice(
PlayerIndex playerIndex)
349 var glassesDevices =
Input.glassesDevices;
350 int i = (int)playerIndex - 1;
353 if (glassesDevices[i] ==
null)
355 var preexistingGlassesDevice = InputSystem.GetDevice<GlassesDevice>($
"Player{playerIndex}");
356 if (preexistingGlassesDevice !=
null)
358 glassesDevices[i] = preexistingGlassesDevice;
359 glassesDevices[i].PlayerIndex = playerIndex;
363 glassesDevices[i] = InputSystem.AddDevice<GlassesDevice>($
"T5 Glasses - Player {playerIndex}");
364 glassesDevices[i].PlayerIndex = playerIndex;
365 InputSystem.AddDeviceUsage(glassesDevices[i], $
"Player{playerIndex}");
369 else if (!glassesDevices[i].added)
371 InputSystem.AddDevice(glassesDevices[i]);
377 var wandDevices =
Input.wandDevices;
378 int i = (int)playerIndex - 1;
379 int j = (int)controllerIndex;
384 var handednessLabel = controllerIndex == ControllerIndex.Right ?
"Right" :
"Left";
387 if (wandDevices[i, j] !=
null && !wandDevices[i, j].added)
389 var wandDevice = wandDevices[i, j];
390 InputSystem.AddDevice(wandDevice);
391 wandDevice.ControllerIndex = controllerIndex;
392 InputSystem.QueueConfigChangeEvent(wandDevice);
393 InputSystem.AddDevice(wandDevice);
400 WandDevice currentWandDevice = InputSystem.GetDevice<WandDevice>($
"Player{playerIndex}-{handednessLabel}Hand");
403 if (currentWandDevice !=
null)
405 wandDevices[i, j] = currentWandDevice;
410 wandDevices[i, j] = InputSystem.AddDevice<WandDevice>($
"T5 Wand - P{(int)playerIndex} {handednessLabel}");
413 wandDevices[i, j].playerIndex = playerIndex;
414 wandDevices[i, j].ControllerIndex = controllerIndex;
415 InputSystem.AddDeviceUsage(wandDevices[i, j], $
"Player{playerIndex}");
416 InputSystem.AddDeviceUsage(wandDevices[i, j], $
"Player{playerIndex}-{handednessLabel}Hand");
417 InputSystem.QueueConfigChangeEvent(wandDevices[i, j]);
422 #endregion Private Functions
TiltFive.Input.WandButton WandButton
static void Error(string m, params object[] list)
ERROR logging function call.
static int SetRumbleMotor(uint motor, float intensity)
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.
static void ScanForWands()
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)
Contains wand related information (Pose, Buttons, Trigger, Stick, Battery)