forked from microsoft/MixedRealityToolkit-Unity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDebugPanelControllerInfo.cs
More file actions
183 lines (166 loc) · 9.7 KB
/
DebugPanelControllerInfo.cs
File metadata and controls
183 lines (166 loc) · 9.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
using System;
using UnityEngine;
#if UNITY_WSA && UNITY_2017_2_OR_NEWER
using System.Collections.Generic;
using UnityEngine.XR.WSA.Input;
#endif
namespace HoloToolkit.Unity
{
public class DebugPanelControllerInfo : MonoBehaviour
{
#if UNITY_WSA && UNITY_2017_2_OR_NEWER
private class ControllerState
{
public InteractionSourceHandedness Handedness;
public Vector3 PointerPosition;
public Quaternion PointerRotation;
public Vector3 GripPosition;
public Quaternion GripRotation;
public bool Grasped;
public bool MenuPressed;
public bool SelectPressed;
public float SelectPressedAmount;
public bool ThumbstickPressed;
public Vector2 ThumbstickPosition;
public bool TouchpadPressed;
public bool TouchpadTouched;
public Vector2 TouchpadPosition;
}
private Dictionary<uint, ControllerState> controllers;
#endif
// Text display label game objects
public TextMesh LeftInfoTextPointerPosition;
public TextMesh LeftInfoTextPointerRotation;
public TextMesh LeftInfoTextGripPosition;
public TextMesh LeftInfoTextGripRotation;
public TextMesh LeftInfoTextGripGrasped;
public TextMesh LeftInfoTextMenuPressed;
public TextMesh LeftInfoTextTriggerPressed;
public TextMesh LeftInfoTextTriggerPressedAmount;
public TextMesh LeftInfoTextThumbstickPressed;
public TextMesh LeftInfoTextThumbstickPosition;
public TextMesh LeftInfoTextTouchpadPressed;
public TextMesh LeftInfoTextTouchpadTouched;
public TextMesh LeftInfoTextTouchpadPosition;
public TextMesh RightInfoTextPointerPosition;
public TextMesh RightInfoTextPointerRotation;
public TextMesh RightInfoTextGripPosition;
public TextMesh RightInfoTextGripRotation;
public TextMesh RightInfoTextGripGrasped;
public TextMesh RightInfoTextMenuPressed;
public TextMesh RightInfoTextTriggerPressed;
public TextMesh RightInfoTextTriggerPressedAmount;
public TextMesh RightInfoTextThumbstickPressed;
public TextMesh RightInfoTextThumbstickPosition;
public TextMesh RightInfoTextTouchpadPressed;
public TextMesh RightInfoTextTouchpadTouched;
public TextMesh RightInfoTextTouchpadPosition;
private void Awake()
{
#if UNITY_WSA && UNITY_2017_2_OR_NEWER
controllers = new Dictionary<uint, ControllerState>();
InteractionManager.InteractionSourceDetected += InteractionManager_InteractionSourceDetected;
InteractionManager.InteractionSourceLost += InteractionManager_InteractionSourceLost;
InteractionManager.InteractionSourceUpdated += InteractionManager_InteractionSourceUpdated;
#endif
}
private void Start()
{
if (DebugPanel.Instance != null)
{
DebugPanel.Instance.RegisterExternalLogCallback(GetControllerInfo);
}
}
#if UNITY_WSA && UNITY_2017_2_OR_NEWER
private void InteractionManager_InteractionSourceDetected(InteractionSourceDetectedEventArgs obj)
{
Debug.LogFormat("{0} {1} Detected", obj.state.source.handedness, obj.state.source.kind);
if (obj.state.source.kind == InteractionSourceKind.Controller && !controllers.ContainsKey(obj.state.source.id))
{
controllers.Add(obj.state.source.id, new ControllerState { Handedness = obj.state.source.handedness });
}
}
private void InteractionManager_InteractionSourceLost(InteractionSourceLostEventArgs obj)
{
Debug.LogFormat("{0} {1} Lost", obj.state.source.handedness, obj.state.source.kind);
controllers.Remove(obj.state.source.id);
}
private void InteractionManager_InteractionSourceUpdated(InteractionSourceUpdatedEventArgs obj)
{
ControllerState controllerState;
if (controllers.TryGetValue(obj.state.source.id, out controllerState))
{
obj.state.sourcePose.TryGetPosition(out controllerState.PointerPosition, InteractionSourceNode.Pointer);
obj.state.sourcePose.TryGetRotation(out controllerState.PointerRotation, InteractionSourceNode.Pointer);
obj.state.sourcePose.TryGetPosition(out controllerState.GripPosition, InteractionSourceNode.Grip);
obj.state.sourcePose.TryGetRotation(out controllerState.GripRotation, InteractionSourceNode.Grip);
controllerState.Grasped = obj.state.grasped;
controllerState.MenuPressed = obj.state.menuPressed;
controllerState.SelectPressed = obj.state.selectPressed;
controllerState.SelectPressedAmount = obj.state.selectPressedAmount;
controllerState.ThumbstickPressed = obj.state.thumbstickPressed;
controllerState.ThumbstickPosition = obj.state.thumbstickPosition;
controllerState.TouchpadPressed = obj.state.touchpadPressed;
controllerState.TouchpadTouched = obj.state.touchpadTouched;
controllerState.TouchpadPosition = obj.state.touchpadPosition;
}
}
#endif
private string GetControllerInfo()
{
string toReturn = string.Empty;
#if UNITY_WSA && UNITY_2017_2_OR_NEWER
foreach (ControllerState controllerState in controllers.Values)
{
// Debug message
toReturn += string.Format("Hand: {0}\nPointer: Position: {1} Rotation: {2}\n" +
"Grip: Position: {3} Rotation: {4}\nGrasped: {5} " +
"MenuPressed: {6}\nSelect: Pressed: {7} PressedAmount: {8}\n" +
"Thumbstick: Pressed: {9} Position: {10}\nTouchpad: Pressed: {11} " +
"Touched: {12} Position: {13}\n\n",
controllerState.Handedness, controllerState.PointerPosition, controllerState.PointerRotation.eulerAngles,
controllerState.GripPosition, controllerState.GripRotation.eulerAngles, controllerState.Grasped,
controllerState.MenuPressed, controllerState.SelectPressed, controllerState.SelectPressedAmount,
controllerState.ThumbstickPressed, controllerState.ThumbstickPosition, controllerState.TouchpadPressed,
controllerState.TouchpadTouched, controllerState.TouchpadPosition);
// Text label display
if (controllerState.Handedness.Equals(InteractionSourceHandedness.Left))
{
LeftInfoTextPointerPosition.text = controllerState.Handedness.ToString();
LeftInfoTextPointerRotation.text = controllerState.PointerRotation.ToString();
LeftInfoTextGripPosition.text = controllerState.GripPosition.ToString();
LeftInfoTextGripRotation.text = controllerState.GripRotation.ToString();
LeftInfoTextGripGrasped.text = controllerState.Grasped.ToString();
LeftInfoTextMenuPressed.text = controllerState.MenuPressed.ToString();
LeftInfoTextTriggerPressed.text = controllerState.SelectPressed.ToString();
LeftInfoTextTriggerPressedAmount.text = controllerState.SelectPressedAmount.ToString();
LeftInfoTextThumbstickPressed.text = controllerState.ThumbstickPressed.ToString();
LeftInfoTextThumbstickPosition.text = controllerState.ThumbstickPosition.ToString();
LeftInfoTextTouchpadPressed.text = controllerState.TouchpadPressed.ToString();
LeftInfoTextTouchpadTouched.text = controllerState.TouchpadTouched.ToString();
LeftInfoTextTouchpadPosition.text = controllerState.TouchpadPosition.ToString();
}
else if (controllerState.Handedness.Equals(InteractionSourceHandedness.Right))
{
RightInfoTextPointerPosition.text = controllerState.PointerPosition.ToString();
RightInfoTextPointerRotation.text = controllerState.PointerRotation.ToString();
RightInfoTextGripPosition.text = controllerState.GripPosition.ToString();
RightInfoTextGripRotation.text = controllerState.GripRotation.ToString();
RightInfoTextGripGrasped.text = controllerState.Grasped.ToString();
RightInfoTextMenuPressed.text = controllerState.MenuPressed.ToString();
RightInfoTextTriggerPressed.text = controllerState.SelectPressed.ToString();
RightInfoTextTriggerPressedAmount.text = controllerState.SelectPressedAmount.ToString();
RightInfoTextThumbstickPressed.text = controllerState.ThumbstickPressed.ToString();
RightInfoTextThumbstickPosition.text = controllerState.ThumbstickPosition.ToString();
RightInfoTextTouchpadPressed.text = controllerState.TouchpadPressed.ToString();
RightInfoTextTouchpadTouched.text = controllerState.TouchpadTouched.ToString();
RightInfoTextTouchpadPosition.text = controllerState.TouchpadPosition.ToString();
}
}
#endif
return toReturn.Substring(0, Math.Max(0, toReturn.Length - 2));
}
}
}