-
Notifications
You must be signed in to change notification settings - Fork 3
/
VRTK_DeviceFinder.cs
486 lines (445 loc) · 21.3 KB
/
VRTK_DeviceFinder.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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
// Device Finder|Utilities|90050
namespace VRTK
{
using UnityEngine;
#if UNITY_2017_2_OR_NEWER
using UnityEngine.XR;
#else
using XRDevice = UnityEngine.VR.VRDevice;
#endif
/// <summary>
/// The Device Finder offers a collection of static methods that can be called to find common game devices such as the headset or controllers, or used to determine key information about the connected devices.
/// </summary>
public static class VRTK_DeviceFinder
{
/// <summary>
/// Possible devices.
/// </summary>
public enum Devices
{
/// <summary>
/// The headset.
/// </summary>
Headset,
/// <summary>
/// The left hand controller.
/// </summary>
LeftController,
/// <summary>
/// The right hand controller.
/// </summary>
RightController,
/// <summary>
/// A generic tracker.
/// </summary>
Tracker
}
/// <summary>
/// Possible headsets
/// </summary>
[System.Obsolete("`VRTK_DeviceFinder.Headsets` has been deprecated and has been replaced with a manufacturer string. This enum will be removed in a future version of VRTK.")]
public enum Headsets
{
/// <summary>
/// An unknown headset.
/// </summary>
Unknown,
/// <summary>
/// A summary of all Oculus Rift headset versions.
/// </summary>
OculusRift,
/// <summary>
/// A specific version of the Oculus Rift headset, the Consumer Version 1.
/// </summary>
OculusRiftCV1,
/// <summary>
/// A summary of all HTC Vive headset versions.
/// </summary>
Vive,
/// <summary>
/// A specific version of the HTC Vive headset, the first consumer version.
/// </summary>
ViveMV,
/// <summary>
/// A specific version of the HTC Vive headset, the first consumer version.
/// </summary>
ViveDVT,
/// <summary>
/// A specific version of the Oculus Rift headset, the rare ES07.
/// </summary>
OculusRiftES07
}
/// <summary>
/// Obsolete
/// </summary>
private static string cachedHeadsetType = "";
/// <summary>
/// The GetCurrentControllerType method returns the current used ControllerType based on the SDK and headset being used.
/// </summary>
/// <param name="controllerReference">The reference to the controller to get type of.</param>
/// <returns>The ControllerType based on the SDK and headset being used.</returns>
public static SDK_BaseController.ControllerType GetCurrentControllerType(VRTK_ControllerReference controllerReference = null)
{
return VRTK_SDK_Bridge.GetCurrentControllerType(controllerReference);
}
/// <summary>
/// The GetControllerIndex method is used to find the index of a given controller object.
/// </summary>
/// <param name="controller">The controller object to get the index of a controller.</param>
/// <returns>The index of the given controller.</returns>
public static uint GetControllerIndex(GameObject controller)
{
return VRTK_SDK_Bridge.GetControllerIndex(controller);
}
/// <summary>
/// Returns the index of the tracker.
/// </summary>
/// <param name="tracker"></param>
/// <returns></returns>
public static uint GetTrackerIndex(GameObject tracker)
{
return VRTK_SDK_Bridge.GetTrackerIndex(tracker);
}
/// <summary>
/// The GetControllerByIndex method is used to find a controller based on it's unique index.
/// </summary>
/// <param name="index">The index of the actual controller to find.</param>
/// <param name="getActual">An optional parameter that if true will return the game object that the SDK controller is attached to.</param>
/// <returns>The actual controller GameObject that matches the given index.</returns>
public static GameObject GetControllerByIndex(uint index, bool getActual)
{
return VRTK_SDK_Bridge.GetControllerByIndex(index, getActual);
}
/// <summary>
/// The GetControllerOrigin method is used to find the controller's origin.
/// </summary>
/// <param name="controllerReference">The reference to the controller to get the origin for.</param>
/// <returns>The transform of the controller origin or if an origin is not set then the transform parent.</returns>
public static Transform GetControllerOrigin(VRTK_ControllerReference controllerReference)
{
return VRTK_SDK_Bridge.GetControllerOrigin(controllerReference);
}
/// <summary>
/// The DeviceTransform method returns the transform for a given Devices enum.
/// </summary>
/// <param name="device">The Devices enum to get the transform for.</param>
/// <returns>The transform for the given Devices enum.</returns>
public static Transform DeviceTransform(Devices device)
{
switch (device)
{
case Devices.Headset:
return HeadsetTransform();
case Devices.LeftController:
return GetControllerLeftHand().transform;
case Devices.RightController:
return GetControllerRightHand().transform;
}
return null;
}
/// <summary>
/// The GetControllerHandType method is used for getting the enum representation of ControllerHand from a given string.
/// </summary>
/// <param name="hand">The string representation of the hand to retrieve the type of. `left` or `right`.</param>
/// <returns>A ControllerHand representing either the Left or Right hand.</returns>
public static SDK_BaseController.ControllerHand GetControllerHandType(string hand)
{
switch (hand.ToLower())
{
case "left":
return SDK_BaseController.ControllerHand.Left;
case "right":
return SDK_BaseController.ControllerHand.Right;
default:
return SDK_BaseController.ControllerHand.None;
}
}
/// <summary>
/// The GetControllerHand method is used for getting the enum representation of ControllerHand for the given controller game object.
/// </summary>
/// <param name="controller">The controller game object to check the hand of.</param>
/// <returns>A ControllerHand representing either the Left or Right hand.</returns>
public static SDK_BaseController.ControllerHand GetControllerHand(GameObject controller)
{
if (VRTK_SDK_Bridge.IsControllerLeftHand(controller))
{
return SDK_BaseController.ControllerHand.Left;
}
else if (VRTK_SDK_Bridge.IsControllerRightHand(controller))
{
return SDK_BaseController.ControllerHand.Right;
}
else
{
return SDK_BaseController.ControllerHand.None;
}
}
/// <summary>
/// The GetControllerLeftHand method retrieves the game object for the left hand controller.
/// </summary>
/// <param name="getActual">An optional parameter that if true will return the game object that the SDK controller is attached to.</param>
/// <returns>The left hand controller.</returns>
public static GameObject GetControllerLeftHand(bool getActual = false)
{
return VRTK_SDK_Bridge.GetControllerLeftHand(getActual);
}
/// <summary>
/// The GetControllerRightHand method retrieves the game object for the right hand controller.
/// </summary>
/// <param name="getActual">An optional parameter that if true will return the game object that the SDK controller is attached to.</param>
/// <returns>The right hand controller.</returns>
public static GameObject GetControllerRightHand(bool getActual = false)
{
return VRTK_SDK_Bridge.GetControllerRightHand(getActual);
}
/// <summary>
/// The GetControllerReferenceLeftHand returns a Controller Reference for the left hand controller.
/// </summary>
/// <returns>The Controller Reference for the left hand controller.</returns>
public static VRTK_ControllerReference GetControllerReferenceLeftHand()
{
return VRTK_ControllerReference.GetControllerReference(SDK_BaseController.ControllerHand.Left);
}
/// <summary>
/// The GetControllerReferenceRightHand returns a Controller Reference for the right hand controller.
/// </summary>
/// <returns>The Controller Reference for the right hand controller.</returns>
public static VRTK_ControllerReference GetControllerReferenceRightHand()
{
return VRTK_ControllerReference.GetControllerReference(SDK_BaseController.ControllerHand.Right);
}
/// <summary>
/// The GetControllerReferenceForHand returns a Controller Reference for the given hand controller.
/// </summary>
/// <returns>The Controller Reference for the given hand controller.</returns>
public static VRTK_ControllerReference GetControllerReferenceForHand(SDK_BaseController.ControllerHand hand)
{
return VRTK_ControllerReference.GetControllerReference(hand);
}
/// <summary>
/// The IsControllerOfHand method is used to check if a given controller game object is of the hand type provided.
/// </summary>
/// <param name="checkController">The actual controller object that is being checked.</param>
/// <param name="hand">The representation of a hand to check if the given controller matches.</param>
/// <returns>Is true if the given controller matches the given hand.</returns>
public static bool IsControllerOfHand(GameObject checkController, SDK_BaseController.ControllerHand hand)
{
switch (hand)
{
case SDK_BaseController.ControllerHand.Left:
return (IsControllerLeftHand(checkController));
case SDK_BaseController.ControllerHand.Right:
return (IsControllerRightHand(checkController));
}
return false;
}
/// <summary>
/// The IsControllerLeftHand method is used to check if a given controller game object is the left handed controller.
/// </summary>
/// <param name="checkController">The controller object that is being checked.</param>
/// <returns>Is true if the given controller is the left controller.</returns>
public static bool IsControllerLeftHand(GameObject checkController)
{
return VRTK_SDK_Bridge.IsControllerLeftHand(checkController);
}
/// <summary>
/// The IsControllerRightHand method is used to check if a given controller game object is the right handed controller.
/// </summary>
/// <param name="checkController">The controller object that is being checked.</param>
/// <returns>Is true if the given controller is the right controller.</returns>
public static bool IsControllerRightHand(GameObject checkController)
{
return VRTK_SDK_Bridge.IsControllerRightHand(checkController);
}
/// <summary>
/// The GetOppositeHand method returns the other hand type from the current hand given.
/// </summary>
/// <param name="currentHand">The current hand.</param>
/// <returns>The opposite hand.</returns>
public static SDK_BaseController.ControllerHand GetOppositeHand(SDK_BaseController.ControllerHand currentHand)
{
switch (currentHand)
{
case SDK_BaseController.ControllerHand.Left:
return SDK_BaseController.ControllerHand.Right;
case SDK_BaseController.ControllerHand.Right:
return SDK_BaseController.ControllerHand.Left;
}
return currentHand;
}
/// <summary>
/// The GetActualController method will attempt to get the actual SDK controller object.
/// </summary>
/// <param name="givenController">The GameObject of the controller.</param>
/// <returns>The GameObject that is the actual controller.</returns>
public static GameObject GetActualController(GameObject givenController)
{
if (VRTK_SDK_Bridge.IsControllerLeftHand(givenController, true) || VRTK_SDK_Bridge.IsControllerRightHand(givenController, true))
{
return givenController;
}
if (VRTK_SDK_Bridge.IsControllerLeftHand(givenController, false))
{
return VRTK_SDK_Bridge.GetControllerLeftHand(true);
}
if (VRTK_SDK_Bridge.IsControllerRightHand(givenController, false))
{
return VRTK_SDK_Bridge.GetControllerRightHand(true);
}
return null;
}
/// <summary>
/// The GetScriptAliasController method will attempt to get the object that contains the scripts for the controller.
/// </summary>
/// <param name="givenController">The GameObject of the controller.</param>
/// <returns>The GameObject that is the alias controller containing the scripts.</returns>
public static GameObject GetScriptAliasController(GameObject givenController)
{
if (VRTK_SDK_Bridge.IsControllerLeftHand(givenController, false) || VRTK_SDK_Bridge.IsControllerRightHand(givenController, false))
{
return givenController;
}
if (VRTK_SDK_Bridge.IsControllerLeftHand(givenController, true))
{
return VRTK_SDK_Bridge.GetControllerLeftHand(false);
}
if (VRTK_SDK_Bridge.IsControllerRightHand(givenController, true))
{
return VRTK_SDK_Bridge.GetControllerRightHand(false);
}
return null;
}
/// <summary>
/// Returns the alias of the tracker. Trackers do not use aliases, but this code is necessary to maintain consistency within VRTK.
/// </summary>
/// <param name="givenTracker"></param>
/// <returns></returns>
public static GameObject GetScriptAliasTracker(GameObject givenTracker)
{
return givenTracker;
}
/// <summary>
/// The GetModelAliasController method will attempt to get the object that contains the model for the controller.
/// </summary>
/// <param name="givenController">The GameObject of the controller.</param>
/// <returns>The GameObject that is the alias controller containing the controller model.</returns>
public static GameObject GetModelAliasController(GameObject givenController)
{
return VRTK_SDK_Bridge.GetControllerModel(givenController);
}
/// <summary>
/// The GetModelAliasControllerHand method will return the hand that the given model alias GameObject is for.
/// </summary>
/// <param name="givenObject">The GameObject that may represent a model alias.</param>
/// <returns>The enum of the ControllerHand that the given GameObject may represent.</returns>
public static SDK_BaseController.ControllerHand GetModelAliasControllerHand(GameObject givenObject)
{
if (GetModelAliasController(GetControllerLeftHand()) == givenObject)
{
return SDK_BaseController.ControllerHand.Left;
}
else if (GetModelAliasController(GetControllerRightHand()) == givenObject)
{
return SDK_BaseController.ControllerHand.Right;
}
return SDK_BaseController.ControllerHand.None;
}
/// <summary>
/// The GetControllerVelocity method is used for getting the current velocity of the physical game controller. This can be useful to determine the speed at which the controller is being swung or the direction it is being moved in.
/// </summary>
/// <param name="controllerReference">The reference to the controller.</param>
/// <returns>A 3 dimensional vector containing the current real world physical controller velocity.</returns>
public static Vector3 GetControllerVelocity(VRTK_ControllerReference controllerReference)
{
return VRTK_SDK_Bridge.GetControllerVelocity(controllerReference);
}
/// <summary>
/// The GetControllerAngularVelocity method is used for getting the current rotational velocity of the physical game controller. This can be useful for determining which way the controller is being rotated and at what speed the rotation is occurring.
/// </summary>
/// <param name="controllerReference">The reference to the controller.</param>
/// <returns>A 3 dimensional vector containing the current real world physical controller angular (rotational) velocity.</returns>
public static Vector3 GetControllerAngularVelocity(VRTK_ControllerReference controllerReference)
{
return VRTK_SDK_Bridge.GetControllerAngularVelocity(controllerReference);
}
/// <summary>
/// The GetHeadsetVelocity method is used to determine the current velocity of the headset.
/// </summary>
/// <returns>A Vector3 containing the current velocity of the headset.</returns>
public static Vector3 GetHeadsetVelocity()
{
return VRTK_SDK_Bridge.GetHeadsetVelocity();
}
/// <summary>
/// The GetHeadsetAngularVelocity method is used to determine the current angular velocity of the headset.
/// </summary>
/// <returns>A Vector3 containing the current angular velocity of the headset.</returns>
public static Vector3 GetHeadsetAngularVelocity()
{
return VRTK_SDK_Bridge.GetHeadsetAngularVelocity();
}
/// <summary>
/// The HeadsetTransform method is used to retrieve the transform for the VR Headset in the scene. It can be useful to determine the position of the user's head in the game world.
/// </summary>
/// <returns>The transform of the VR Headset component.</returns>
public static Transform HeadsetTransform()
{
return VRTK_SDK_Bridge.GetHeadset();
}
/// <summary>
/// The HeadsetCamera method is used to retrieve the transform for the VR Camera in the scene.
/// </summary>
/// <returns>The transform of the VR Camera component.</returns>
public static Transform HeadsetCamera()
{
return VRTK_SDK_Bridge.GetHeadsetCamera();
}
/// <summary>
/// The GetHeadsetTypeAsString method returns a string representing the type of headset connected.
/// </summary>
/// <returns>The string of the headset connected.</returns>
public static string GetHeadsetTypeAsString()
{
return VRTK_SDK_Bridge.GetHeadsetType();
}
/// <summary>
/// The GetHeadsetType method returns the type of headset currently connected.
/// </summary>
/// <returns>The Headset type that is connected.</returns>
public static SDK_BaseHeadset.HeadsetType GetHeadsetType()
{
switch (GetHeadsetTypeAsString())
{
case "simulator":
return SDK_BaseHeadset.HeadsetType.Simulator;
case "htcvive":
return SDK_BaseHeadset.HeadsetType.HTCVive;
case "oculusrift":
return SDK_BaseHeadset.HeadsetType.OculusRift;
case "oculusgearvr":
return SDK_BaseHeadset.HeadsetType.OculusGearVR;
case "googledaydream":
return SDK_BaseHeadset.HeadsetType.GoogleDaydream;
case "googlecardboard":
return SDK_BaseHeadset.HeadsetType.GoogleCardboard;
case "hyperealvr":
return SDK_BaseHeadset.HeadsetType.HyperealVR;
case "oculusriftdk1":
return SDK_BaseHeadset.HeadsetType.OculusRiftDK1;
case "oculusriftdk2":
return SDK_BaseHeadset.HeadsetType.OculusRiftDK2;
case "windowsmixedreality":
return SDK_BaseHeadset.HeadsetType.WindowsMixedReality;
}
return SDK_BaseHeadset.HeadsetType.Undefined;
}
/// <summary>
/// The PlayAreaTransform method is used to retrieve the transform for the play area in the scene.
/// </summary>
/// <returns>The transform of the VR Play Area component.</returns>
public static Transform PlayAreaTransform()
{
return VRTK_SDK_Bridge.GetPlayArea();
}
}
}