Unity SDK Docs 1.5.0-beta.6
Loading...
Searching...
No Matches
GlassesDevice.cs
1/*
2 * Copyright (C) 2020-2023 Tilt Five, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#if UNITY_2019_1_OR_NEWER && INPUTSYSTEM_AVAILABLE
18using UnityEditor;
19using UnityEngine;
20using UnityEngine.InputSystem;
21using UnityEngine.InputSystem.Controls;
22using UnityEngine.InputSystem.Layouts;
23using UnityEngine.InputSystem.LowLevel;
24using UnityEngine.InputSystem.Utilities;
26
27
28namespace TiltFive
29{
30 public struct GlassesState : IInputStateTypeInfo
31 {
32 public FourCC format => new FourCC('T', '5');
33
34 [InputControl(name = "devicePosition", alias = "Position", noisy = true, layout = "Vector3")]
35 [InputControl(name = "centerEyePosition", synthetic = true, useStateFrom = "devicePosition")]
36 public Vector3 devicePosition;
37
38 [InputControl(name = "LeftEyePosition", noisy = true, layout = "Vector3")]
39 public Vector3 LeftEyePosition;
40
41 [InputControl(name = "RightEyePosition", noisy = true, layout = "Vector3")]
42 public Vector3 RightEyePosition;
43
44 [InputControl(name = "Position/Raw", noisy = true, layout = "Vector3")]
45 public Vector3 RawDevicePosition;
46
47 [InputControl(name = "LeftEyePosition/Raw", noisy = true, layout = "Vector3")]
48 public Vector3 RawLeftEyePosition;
49
50 [InputControl(name = "RightEyePosition/Raw", noisy = true, layout = "Vector3")]
51 public Vector3 RawRightEyePosition;
52
53 // This is a neat trick - if we want multiple InputControls to be driven by the same value,
54 // we can stack them like this and mark the duplicates as synthetic controls.
55 [InputControl(name = "deviceRotation", alias = "Rotation", noisy = true, layout = "Quaternion")]
56 [InputControl(name = "centerEyeRotation", synthetic = true, useStateFrom = "deviceRotation", noisy = true)]
57 [InputControl(name = "leftEyeRotation", synthetic = true, useStateFrom = "deviceRotation", noisy = true)]
58 [InputControl(name = "rightEyeRotation", synthetic = true, useStateFrom = "deviceRotation", noisy = true)]
59 public Quaternion deviceRotation;
60
61 [InputControl(name = "Rotation/Raw", noisy = true, layout = "Quaternion")]
62 public Quaternion RawRotation;
63 }
64
65 [InputControlLayout(stateType = typeof(GlassesState), displayName = "Tilt Five Glasses", updateBeforeRender = true)]
66#if UNITY_EDITOR
67 [InitializeOnLoad]
68#endif
69 public class GlassesDevice : UnityEngine.InputSystem.XR.XRHMD
70 {
71 #region Public Fields
72
73 public PlayerIndex PlayerIndex { get; internal set; }
74 public WandDevice LeftWand = null;
75 public WandDevice RightWand = null;
76
77 #endregion
78
79
80 #region Controls
81
82 public new Vector3Control devicePosition { get; private set; }
83 public new Vector3Control leftEyePosition { get; private set; }
84 public new Vector3Control rightEyePosition { get; private set; }
85 public new Vector3Control centerEyePosition { get; private set; }
86
87 public Vector3Control RawPosition { get; private set; }
88 public Vector3Control RawLeftEyePosition { get; private set; }
89 public Vector3Control RawRightEyePosition { get; private set; }
90
91 public new QuaternionControl deviceRotation { get; private set; }
92 public new QuaternionControl leftEyeRotation { get; private set; }
93 public new QuaternionControl rightEyeRotation { get; private set; }
94 public new QuaternionControl centerEyeRotation { get; private set; }
95 public QuaternionControl RawRotation { get; private set; }
96
97 public new ButtonControl isTracked { get; private set; }
98
99 public new IntegerControl trackingState { get; private set; }
100
101 #endregion
102
103
104 #region Overrides
105
106 protected override void FinishSetup()
107 {
108 base.FinishSetup();
109
110 devicePosition = GetChildControl<Vector3Control>("Position");
111 centerEyePosition = GetChildControl<Vector3Control>("centerEyePosition");
112 leftEyePosition = GetChildControl<Vector3Control>("LeftEyePosition");
113 rightEyePosition = GetChildControl<Vector3Control>("RightEyePosition");
114
115 RawPosition = GetChildControl<Vector3Control>("Position/Raw");
116 RawLeftEyePosition = GetChildControl<Vector3Control>("LeftEyePosition/Raw");
117 RawRightEyePosition = GetChildControl<Vector3Control>("RightEyePosition/Raw");
118
119 deviceRotation = GetChildControl<QuaternionControl>("Rotation");
120 leftEyeRotation = GetChildControl<QuaternionControl>("leftEyeRotation");
121 rightEyeRotation = GetChildControl<QuaternionControl>("rightEyeRotation");
122 centerEyeRotation = GetChildControl<QuaternionControl>("centerEyeRotation");
123 RawRotation = GetChildControl<QuaternionControl>("Rotation/Raw");
124
125 isTracked = GetChildControl<ButtonControl>("isTracked");
126 trackingState = GetChildControl<IntegerControl>("trackingState");
127 }
128
129 #endregion
130
131 static GlassesDevice()
132 {
133 InputSystem.RegisterLayout<GlassesDevice>(matches: new InputDeviceMatcher()
134 .WithInterface("GlassesDevice"));
135 }
136 }
137
138}
139
140#endif
PlayerIndex
The Player index (e.g. Player One, Player Two, etc)