17#if UNITY_2019_1_OR_NEWER && INPUTSYSTEM_AVAILABLE
22using UnityEngine.InputSystem;
23using UnityEngine.InputSystem.Controls;
24using UnityEngine.InputSystem.Layouts;
25using UnityEngine.InputSystem.LowLevel;
26using UnityEngine.InputSystem.Utilities;
30 public struct WandState : IInputStateTypeInfo
32 public FourCC format =>
new FourCC(
'T',
'5');
34 [InputControl(name =
"TiltFive", layout =
"Button", bit = 0)]
37 [InputControl(name =
"One", layout =
"Button", bit = 0)]
40 [InputControl(name =
"Two", layout =
"Button", bit = 0)]
43 [InputControl(name =
"A", layout =
"Button", bit = 0)]
46 [InputControl(name =
"B", layout =
"Button", bit = 0)]
49 [InputControl(name =
"X", layout =
"Button", bit = 0)]
52 [InputControl(name =
"Y", layout =
"Button", bit = 0)]
55 [InputControl(name =
"Three", aliases =
new string[]
56 {
"thumbstickClick",
"JoystickOrPadPressed",
"thumbstickClicked",
"thumbstickpressed",
"primary2DAxisClick" },
57 layout =
"Button", bit = 0)]
60 [InputControl(name =
"Stick", aliases =
new string[] {
"Joystick",
"Thumbstick"}, layout =
"Stick")]
61 [InputControl(name =
"Primary2DAxis", synthetic =
true, useStateFrom =
"Stick", layout =
"Vector2")]
64 [InputControl(name =
"Trigger", layout =
"Axis")]
67 [InputControl(name =
"devicePosition", alias =
"Position_Grip", layout =
"Vector3")]
68 public Vector3 devicePosition;
70 [InputControl(name =
"Position_Fingertips", layout =
"Vector3")]
71 public Vector3 FingertipsPosition;
73 [InputControl(name =
"Position_Aim", layout =
"Vector3")]
74 public Vector3 AimPosition;
76 [InputControl(name =
"Position_Grip/Raw", layout =
"Vector3")]
77 public Vector3 RawGripPosition;
79 [InputControl(name =
"Position_Fingertips/Raw", layout =
"Vector3")]
80 public Vector3 RawFingertipsPosition;
82 [InputControl(name =
"Position_Aim/Raw", layout =
"Vector3")]
83 public Vector3 RawAimPosition;
85 [InputControl(name =
"deviceRotation", alias =
"Rotation", layout =
"Quaternion")]
86 public Quaternion deviceRotation;
88 [InputControl(name =
"Rotation/Raw", layout =
"Quaternion")]
89 public Quaternion RawRotation;
91 [InputControl(name =
"isTracked", layout =
"Button")]
92 public bool isTracked;
94 [InputControl(name =
"trackingState", layout =
"Integer")]
95 public int trackingState;
98 [InputControlLayout(stateType = typeof(WandState), displayName =
"Tilt Five Wand",
99 commonUsages =
new string[] {
"LeftHand",
"RightHand" }, updateBeforeRender =
true)]
103 public class WandDevice : UnityEngine.InputSystem.XR.XRControllerWithRumble
105 #region Public Fields
107 public PlayerIndex playerIndex {
get;
internal set; }
115 public ButtonControl TiltFive {
get;
private set; }
116 public ButtonControl One {
get;
private set; }
117 public ButtonControl Two {
get;
private set; }
118 public ButtonControl Three {
get;
private set; }
119 public ButtonControl A {
get;
private set; }
120 public ButtonControl B {
get;
private set; }
121 public ButtonControl X {
get;
private set; }
122 public ButtonControl Y {
get;
private set; }
124 public StickControl Stick {
get;
private set; }
126 public AxisControl Trigger {
get;
private set; }
128 public new Vector3Control devicePosition {
get;
private set; }
129 public Vector3Control FingertipsPosition {
get;
private set; }
130 public Vector3Control AimPosition {
get;
private set; }
132 public Vector3Control RawGripPosition {
get;
private set; }
133 public Vector3Control RawFingertipsPosition {
get;
private set; }
134 public Vector3Control RawAimPosition {
get;
private set; }
136 public new QuaternionControl deviceRotation {
get;
private set; }
137 public QuaternionControl RawRotation {
get;
private set; }
139 public new ButtonControl isTracked {
get;
private set; }
140 public new IntegerControl trackingState {
get;
private set; }
147 protected override void FinishSetup()
151 TiltFive = GetChildControl<ButtonControl>(
"TiltFive");
152 One = GetChildControl<ButtonControl>(
"One");
153 Two = GetChildControl<ButtonControl>(
"Two");
154 A = GetChildControl<ButtonControl>(
"A");
155 B = GetChildControl<ButtonControl>(
"B");
156 X = GetChildControl<ButtonControl>(
"X");
157 Y = GetChildControl<ButtonControl>(
"Y");
158 Three = GetChildControl<ButtonControl>(
"Three");
160 Stick = GetChildControl<StickControl>(
"Stick");
162 Trigger = GetChildControl<AxisControl>(
"Trigger");
164 devicePosition = GetChildControl<Vector3Control>(
"Position_Grip");
165 FingertipsPosition = GetChildControl<Vector3Control>(
"Position_Fingertips");
166 AimPosition = GetChildControl<Vector3Control>(
"Position_Aim");
168 RawGripPosition = GetChildControl<Vector3Control>(
"Position_Grip/Raw");
169 RawFingertipsPosition = GetChildControl<Vector3Control>(
"Position_Fingertips/Raw");
170 RawAimPosition = GetChildControl<Vector3Control>(
"Position_Aim/Raw");
172 deviceRotation = GetChildControl<QuaternionControl>(
"Rotation");
173 RawRotation = GetChildControl<QuaternionControl>(
"Rotation/Raw");
175 isTracked = GetChildControl<ButtonControl>(
"isTracked");
176 trackingState = GetChildControl<IntegerControl>(
"trackingState");
179 protected override void RefreshConfiguration()
184 if (usages.Contains(CommonUsages.RightHand))
186 InputSystem.RemoveDeviceUsage(
this, CommonUsages.RightHand);
188 InputSystem.AddDeviceUsage(
this, CommonUsages.LeftHand);
191 if(usages.Contains(CommonUsages.LeftHand))
193 InputSystem.RemoveDeviceUsage(
this, CommonUsages.LeftHand);
195 InputSystem.AddDeviceUsage(
this, CommonUsages.RightHand);
201 base.RefreshConfiguration();
204 protected new void SendImpulse(
float amplitude,
float duration){
207 if(!
Player.TryGetGlassesHandle(playerIndex, out var glassesHandle))
209 Log.Error(
"Failed to get glasses handle.");
219 Log.Error(
"Failed to send impulse to wand.");
222 catch (DllNotFoundException e)
224 Log.Info(
"Tilt Five library missing. Could not connect to wand: {0}", e.Message);
229 "Failed to send impulse to wand: {0}",
238 InputSystem.RegisterLayout<WandDevice>(matches:
new InputDeviceMatcher()
239 .WithInterface(
"WandDevice"));
Provides access to player settings and functionality.
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)