17#if UNITY_2019_1_OR_NEWER && INPUTSYSTEM_AVAILABLE
20using UnityEngine.InputSystem;
21using UnityEngine.InputSystem.Controls;
22using UnityEngine.InputSystem.Layouts;
23using UnityEngine.InputSystem.LowLevel;
24using UnityEngine.InputSystem.Utilities;
28 public struct WandState : IInputStateTypeInfo
30 public FourCC format =>
new FourCC(
'T',
'5');
32 [InputControl(name =
"TiltFive", layout =
"Button", bit = 0)]
35 [InputControl(name =
"One", layout =
"Button", bit = 0)]
38 [InputControl(name =
"Two", layout =
"Button", bit = 0)]
41 [InputControl(name =
"A", layout =
"Button", bit = 0)]
44 [InputControl(name =
"B", layout =
"Button", bit = 0)]
47 [InputControl(name =
"X", layout =
"Button", bit = 0)]
50 [InputControl(name =
"Y", layout =
"Button", bit = 0)]
53 [InputControl(name =
"Three", aliases =
new string[]
54 {
"thumbstickClick",
"JoystickOrPadPressed",
"thumbstickClicked",
"thumbstickpressed",
"primary2DAxisClick" },
55 layout =
"Button", bit = 0)]
58 [InputControl(name =
"Stick", aliases =
new string[] {
"Joystick",
"Thumbstick"}, layout =
"Stick")]
59 [InputControl(name =
"Primary2DAxis", synthetic =
true, useStateFrom =
"Stick", layout =
"Vector2")]
62 [InputControl(name =
"Trigger", layout =
"Axis")]
65 [InputControl(name =
"devicePosition", alias =
"Position_Grip", layout =
"Vector3")]
66 public Vector3 devicePosition;
68 [InputControl(name =
"Position_Fingertips", layout =
"Vector3")]
69 public Vector3 FingertipsPosition;
71 [InputControl(name =
"Position_Aim", layout =
"Vector3")]
72 public Vector3 AimPosition;
74 [InputControl(name =
"Position_Grip/Raw", layout =
"Vector3")]
75 public Vector3 RawGripPosition;
77 [InputControl(name =
"Position_Fingertips/Raw", layout =
"Vector3")]
78 public Vector3 RawFingertipsPosition;
80 [InputControl(name =
"Position_Aim/Raw", layout =
"Vector3")]
81 public Vector3 RawAimPosition;
83 [InputControl(name =
"deviceRotation", alias =
"Rotation", layout =
"Quaternion")]
84 public Quaternion deviceRotation;
86 [InputControl(name =
"Rotation/Raw", layout =
"Quaternion")]
87 public Quaternion RawRotation;
89 [InputControl(name =
"isTracked", layout =
"Button")]
90 public bool isTracked;
92 [InputControl(name =
"trackingState", layout =
"Integer")]
93 public int trackingState;
96 [InputControlLayout(stateType = typeof(WandState), displayName =
"Tilt Five Wand",
97 commonUsages =
new string[] {
"LeftHand",
"RightHand" }, updateBeforeRender =
true)]
101 public class WandDevice : UnityEngine.InputSystem.XR.XRControllerWithRumble
103 #region Public Fields
105 public PlayerIndex playerIndex {
get;
internal set; }
113 public ButtonControl
TiltFive {
get;
private set; }
114 public ButtonControl
One {
get;
private set; }
115 public ButtonControl
Two {
get;
private set; }
116 public ButtonControl
Three {
get;
private set; }
117 public ButtonControl A {
get;
private set; }
118 public ButtonControl B {
get;
private set; }
119 public ButtonControl X {
get;
private set; }
120 public ButtonControl Y {
get;
private set; }
122 public StickControl Stick {
get;
private set; }
124 public AxisControl Trigger {
get;
private set; }
126 public new Vector3Control devicePosition {
get;
private set; }
127 public Vector3Control FingertipsPosition {
get;
private set; }
128 public Vector3Control AimPosition {
get;
private set; }
130 public Vector3Control RawGripPosition {
get;
private set; }
131 public Vector3Control RawFingertipsPosition {
get;
private set; }
132 public Vector3Control RawAimPosition {
get;
private set; }
134 public new QuaternionControl deviceRotation {
get;
private set; }
135 public QuaternionControl RawRotation {
get;
private set; }
137 public new ButtonControl isTracked {
get;
private set; }
138 public new IntegerControl trackingState {
get;
private set; }
145 protected override void FinishSetup()
149 TiltFive = GetChildControl<ButtonControl>(
"TiltFive");
150 One = GetChildControl<ButtonControl>(
"One");
151 Two = GetChildControl<ButtonControl>(
"Two");
152 A = GetChildControl<ButtonControl>(
"A");
153 B = GetChildControl<ButtonControl>(
"B");
154 X = GetChildControl<ButtonControl>(
"X");
155 Y = GetChildControl<ButtonControl>(
"Y");
156 Three = GetChildControl<ButtonControl>(
"Three");
158 Stick = GetChildControl<StickControl>(
"Stick");
160 Trigger = GetChildControl<AxisControl>(
"Trigger");
162 devicePosition = GetChildControl<Vector3Control>(
"Position_Grip");
163 FingertipsPosition = GetChildControl<Vector3Control>(
"Position_Fingertips");
164 AimPosition = GetChildControl<Vector3Control>(
"Position_Aim");
166 RawGripPosition = GetChildControl<Vector3Control>(
"Position_Grip/Raw");
167 RawFingertipsPosition = GetChildControl<Vector3Control>(
"Position_Fingertips/Raw");
168 RawAimPosition = GetChildControl<Vector3Control>(
"Position_Aim/Raw");
170 deviceRotation = GetChildControl<QuaternionControl>(
"Rotation");
171 RawRotation = GetChildControl<QuaternionControl>(
"Rotation/Raw");
173 isTracked = GetChildControl<ButtonControl>(
"isTracked");
174 trackingState = GetChildControl<IntegerControl>(
"trackingState");
177 protected override void RefreshConfiguration()
179 switch (ControllerIndex)
182 if (usages.Contains(CommonUsages.RightHand))
184 InputSystem.RemoveDeviceUsage(
this, CommonUsages.RightHand);
186 InputSystem.AddDeviceUsage(
this, CommonUsages.LeftHand);
189 if(usages.Contains(CommonUsages.LeftHand))
191 InputSystem.RemoveDeviceUsage(
this, CommonUsages.LeftHand);
193 InputSystem.AddDeviceUsage(
this, CommonUsages.RightHand);
199 base.RefreshConfiguration();
206 InputSystem.RegisterLayout<WandDevice>(matches:
new InputDeviceMatcher()
207 .WithInterface(
"WandDevice"));
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)