Tanoda
TrackerSetup.cs
Go to the documentation of this file.
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using System.Text;
5using UnityEngine;
6#if !UNITY_WEBGL
7using Valve.VR;
8#endif
9
10public class TrackerSetup : MonoBehaviour
11{
12 #if DANA
13 private bool success = false;
14 public SteamVR_TrackedObject[] trackers;
15 void Start()
16 {
17 if (OpenVR.System == null)
18 {
19 return;
20 }
21 byte index = 0;
22 var sb = new StringBuilder(128);
23 ETrackedPropertyError error = ETrackedPropertyError.TrackedProp_Success;
24 for (uint i = 0; i < 16; i++)
25 {
26 sb.Clear();
27 OpenVR.System.GetStringTrackedDeviceProperty(i, ETrackedDeviceProperty.Prop_RenderModelName_String, sb,
28 128, ref error);
29
30 var deviceclass = OpenVR.System.GetTrackedDeviceClass(i);
31 if (deviceclass == ETrackedDeviceClass.GenericTracker)
32 {
33 try
34 {
35 trackers[index].index =
36 (SteamVR_TrackedObject.EIndex) i;
37 index++;
38 trackers[index].gameObject.SetActive(true);
39 success = true;
40 }
41 catch (Exception)
42 {
43 // ignored
44 }
45 }
46 }
47
48 if (!success)
49 StartCoroutine(SlowUpdate());
50 }
51
52 IEnumerator SlowUpdate()
53 {
54 while (!success)
55 {
56 yield return new WaitForSeconds(1);
57
58 byte index = 0;
59 var sb = new StringBuilder(128);
60 ETrackedPropertyError error = ETrackedPropertyError.TrackedProp_Success;
61 for (uint i = 0; i < 16; i++)
62 {
63 sb.Clear();
64 OpenVR.System.GetStringTrackedDeviceProperty(i, ETrackedDeviceProperty.Prop_RenderModelName_String, sb,
65 128, ref error);
66
67 var deviceclass = OpenVR.System.GetTrackedDeviceClass(i);
68 if (deviceclass == ETrackedDeviceClass.GenericTracker)
69 {
70 try
71 {
72 trackers[index].index =
73 (SteamVR_TrackedObject.EIndex) i;
74 index++;
75 trackers[index].gameObject.SetActive(true);
76 success = true;
77 }
78 catch (Exception)
79 {
80 // ignored
81 }
82 }
83 }
84 }
85 }
86#endif
87}