forked from Ayfel/MRHand
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MRHand.cs
262 lines (231 loc) · 7.64 KB
/
MRHand.cs
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SpatialTracking;
using UnityEngine.XR.WSA.Input;
[RequireComponent(typeof(TrackedPoseDriver))]
public class MRHand : MonoBehaviour {
TrackedPoseDriver tracker;
InteractionSourceHandedness handedness;
bool triggerpressed;
bool triggerpress;
bool triggerup;
bool touchingtouchpad;
bool touchpadpressed;
bool touchpadpress;
bool touchpadup;
Vector2 touchpadPos;
bool menupressed;
bool menupress;
bool menuup;
bool grasppressed;
bool grasppress;
bool graspup;
bool thumbstickpress;
bool thumbstickpressed;
bool thumbstickup;
Vector2 thumbstickPos;
private void Update()
{
if (GetGraspPress())
Debug.Log("grasppressonce"+handedness.ToString());
if (GetGraspPressed())
Debug.Log("grasppressing" + handedness.ToString());
if (GetGraspUp())
Debug.Log("graspup" + handedness.ToString());
if (GetTouchpadPress())
Debug.Log("touchpadpressonce" + handedness.ToString());
if (GetTouchpadPressed())
Debug.Log("touchpadpressing" + handedness.ToString());
if (GetTouchpadUp())
Debug.Log("touchpadup" + handedness.ToString());
if (GetMenuPress())
Debug.Log("Menupressonce" + handedness.ToString());
if (GetMenuPressed())
Debug.Log("Menupressing" + handedness.ToString());
if (GetMenuUp())
Debug.Log("Menuup" + handedness.ToString());
if (GetTriggerPress())
Debug.Log("Triggerpressonce" + handedness.ToString());
if (GetTriggerPressed())
Debug.Log("Triggerpressing" + handedness.ToString());
if (GetTriggerUp())
Debug.Log("Triggerup" + handedness.ToString());
if (GetThumbStickPress())
Debug.Log("ThumbStickpressonce" + handedness.ToString());
if (GetThumbStickPressed())
Debug.Log("ThumbStickpressing" + handedness.ToString());
if (GetThumbStickUp())
Debug.Log("ThumbStickup" + handedness.ToString());
if (GetTouchTouching())
Debug.Log(TouchPadPosition());
}
void Start()
{
tracker = GetComponent<TrackedPoseDriver>();
if (tracker.poseSource == TrackedPoseDriver.TrackedPose.LeftPose)
handedness = InteractionSourceHandedness.Left;
else
handedness = InteractionSourceHandedness.Right;
InteractionManager.InteractionSourcePressed += InteractionManager_InteractionSourcePressed;
InteractionManager.InteractionSourceReleased += InteractionManager_InteractionSourceReleased;
InteractionManager.InteractionSourceUpdated += InteractionManager_InteractionSourceUpdated;
}
void OnDestroy()
{
InteractionManager.InteractionSourcePressed -= InteractionManager_InteractionSourcePressed;
InteractionManager.InteractionSourceReleased -= InteractionManager_InteractionSourceReleased;
InteractionManager.InteractionSourceUpdated -= InteractionManager_InteractionSourceUpdated;
}
void InteractionManager_InteractionSourcePressed(InteractionSourcePressedEventArgs state)
{
if (state.state.source.handedness == handedness)
{
switch (state.pressType)
{
case InteractionSourcePressType.Select:
triggerpress = true;
triggerpressed = true;
break;
case InteractionSourcePressType.Menu:
menupress = true;
menupressed = true;
break;
case InteractionSourcePressType.Grasp:
grasppress = true;
grasppressed = true;
break;
case InteractionSourcePressType.Touchpad:
touchpadpress = true;
touchpadpressed = true;
break;
case InteractionSourcePressType.Thumbstick:
thumbstickpress = true;
thumbstickpressed = true;
break;
}
}
}
void InteractionManager_InteractionSourceReleased(InteractionSourceReleasedEventArgs state)
{
if (state.state.source.handedness == handedness) {
switch (state.pressType)
{
case InteractionSourcePressType.Select:
triggerpressed = false;
triggerup = true;
break;
case InteractionSourcePressType.Menu:
menupressed = false;
menuup = true;
break;
case InteractionSourcePressType.Grasp:
grasppressed = false;
graspup = true;
break;
case InteractionSourcePressType.Touchpad:
touchpadpressed = false;
touchpadup = true;
break;
case InteractionSourcePressType.Thumbstick:
thumbstickpressed = false;
thumbstickup = true;
break;
}
}
}
private void InteractionManager_InteractionSourceUpdated(InteractionSourceUpdatedEventArgs obj)
{
if (obj.state.source.handedness == handedness)
{
touchingtouchpad = obj.state.touchpadTouched;
touchpadPos = obj.state.touchpadPosition;
thumbstickPos = obj.state.thumbstickPosition;
}
}
public bool GetTriggerPress()
{
return triggerpress;
}
public bool GetTriggerPressed()
{
return triggerpressed;
}
public bool GetTriggerUp()
{
return triggerup;
}
public bool GetMenuPress()
{
return menupress;
}
public bool GetMenuPressed()
{
return menupressed;
}
public bool GetMenuUp()
{
return menuup;
}
public bool GetGraspPress()
{
return grasppress;
}
public bool GetGraspPressed()
{
return grasppressed;
}
public bool GetGraspUp()
{
return graspup;
}
public bool GetTouchpadPress()
{
return touchpadpress;
}
public bool GetTouchpadPressed()
{
return touchpadpressed;
}
public bool GetTouchpadUp()
{
return touchpadup;
}
public bool GetTouchTouching()
{
return touchingtouchpad;
}
public bool GetThumbStickPress()
{
return thumbstickpress;
}
public bool GetThumbStickPressed()
{
return thumbstickpressed;
}
public bool GetThumbStickUp()
{
return thumbstickup;
}
public Vector2 TouchPadPosition()
{
return touchpadPos;
}
public Vector2 ThumbStickPosition()
{
return thumbstickPos;
}
private void LateUpdate()
{
triggerpress = false;
menupress = false;
grasppress = false;
touchpadpress = false;
thumbstickpress = false;
triggerup = false;
menuup = false;
graspup = false;
touchpadup = false;
thumbstickup = false;
}
}