ViveBaseStationHide.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using System;
  2. using UnityEngine;
  3. using Valve.VR;
  4. public class ViveBaseStationHide : AVRTrackingObjectsMgr
  5. {
  6. private void Awake()
  7. {
  8. this.m_TrackObjs = base.GetComponentsInChildren<SteamVR_TrackedObject>(true);
  9. }
  10. private void OnEnable()
  11. {
  12. this.OnTrackedDeviceRoleChanged(new object[0]);
  13. for (int i = 0; i < SteamVR.connected.Length; i++)
  14. {
  15. if (SteamVR.connected[i])
  16. {
  17. this.OnDeviceConnected(new object[]
  18. {
  19. i,
  20. true
  21. });
  22. }
  23. }
  24. SteamVR_Utils.Event.Listen("device_connected", new SteamVR_Utils.Event.Handler(this.OnDeviceConnected));
  25. SteamVR_Utils.Event.Listen("TrackedDeviceRoleChanged", new SteamVR_Utils.Event.Handler(this.OnTrackedDeviceRoleChanged));
  26. SteamVR_Utils.Event.Listen("render_model_loaded", new SteamVR_Utils.Event.Handler(this.OnRenderModelLoaded));
  27. }
  28. private void OnDisable()
  29. {
  30. SteamVR_Utils.Event.Remove("device_connected", new SteamVR_Utils.Event.Handler(this.OnDeviceConnected));
  31. SteamVR_Utils.Event.Remove("TrackedDeviceRoleChanged", new SteamVR_Utils.Event.Handler(this.OnTrackedDeviceRoleChanged));
  32. SteamVR_Utils.Event.Remove("render_model_loaded", new SteamVR_Utils.Event.Handler(this.OnRenderModelLoaded));
  33. }
  34. private void OnTrackedDeviceRoleChanged(params object[] args)
  35. {
  36. this.Refresh();
  37. }
  38. private void OnDeviceConnected(params object[] args)
  39. {
  40. uint num = (uint)((int)args[0]);
  41. bool flag = (bool)args[1];
  42. this.Refresh();
  43. }
  44. private void OnRenderModelLoaded(params object[] args)
  45. {
  46. this.Refresh();
  47. }
  48. public override void Refresh()
  49. {
  50. this.m_TrackObjs = base.GetComponentsInChildren<SteamVR_TrackedObject>(true);
  51. this.m_listTrackTracker.Clear();
  52. for (int i = 0; i < this.m_TrackObjs.Length; i++)
  53. {
  54. CVRSystem system = OpenVR.System;
  55. if (system != null)
  56. {
  57. SteamVR_TrackedObject.EIndex index = this.m_TrackObjs[i].index;
  58. if (system.GetTrackedDeviceClass((uint)index) == ETrackedDeviceClass.TrackingReference)
  59. {
  60. MeshRenderer component = this.m_TrackObjs[i].GetComponent<MeshRenderer>();
  61. if (component != null)
  62. {
  63. component.enabled = false;
  64. }
  65. }
  66. else
  67. {
  68. MeshRenderer component2 = this.m_TrackObjs[i].GetComponent<MeshRenderer>();
  69. if (component2 != null)
  70. {
  71. component2.enabled = true;
  72. }
  73. }
  74. if (system.GetTrackedDeviceClass((uint)index) == (ETrackedDeviceClass)3 && this.m_TrackObjs[i].isValid)
  75. {
  76. this.m_listTrackTracker.Add(this.m_TrackObjs[i].transform);
  77. }
  78. }
  79. }
  80. }
  81. private void Update()
  82. {
  83. }
  84. private SteamVR_TrackedObject[] m_TrackObjs;
  85. }