Assignment for RMIT Mixed Reality in 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

130 lines
5.4 KiB

  1. // HyperealVR Headset|SDK_HyperealVR|003
  2. namespace VRTK
  3. {
  4. #if VRTK_DEFINE_SDK_HYPEREALVR
  5. using UnityEngine;
  6. using System.Collections.Generic;
  7. using Hypereal;
  8. #endif
  9. /// <summary>
  10. /// The HyperealVR Headset SDK script provides a bridge to the HyperealVR SDK.
  11. /// </summary>
  12. [SDK_Description(typeof(SDK_HyperealVRSystem))]
  13. public class SDK_HyperealVRHeadset
  14. #if VRTK_DEFINE_SDK_HYPEREALVR
  15. : SDK_BaseHeadset
  16. #else
  17. : SDK_FallbackHeadset
  18. #endif
  19. {
  20. #if VRTK_DEFINE_SDK_HYPEREALVR
  21. /// <summary>
  22. /// The ProcessUpdate method enables an SDK to run logic for every Unity Update
  23. /// </summary>
  24. /// <param name="options">A dictionary of generic options that can be used to within the update.</param>
  25. public override void ProcessUpdate(Dictionary<string, object> options)
  26. {
  27. }
  28. /// <summary>
  29. /// The ProcessFixedUpdate method enables an SDK to run logic for every Unity FixedUpdate
  30. /// </summary>
  31. /// <param name="options">A dictionary of generic options that can be used to within the fixed update.</param>
  32. public override void ProcessFixedUpdate(Dictionary<string, object> options)
  33. {
  34. }
  35. /// <summary>
  36. /// The GetHeadset method returns the Transform of the object that is used to represent the headset in the scene.
  37. /// </summary>
  38. /// <returns>A transform of the object representing the headset in the scene.</returns>
  39. public override Transform GetHeadset()
  40. {
  41. cachedHeadset = GetSDKManagerHeadset();
  42. if (cachedHeadset == null)
  43. {
  44. GameObject myHeadGO = VRTK_SharedMethods.FindEvenInactiveGameObject<HyHead>(null, true);
  45. cachedHeadset = (myHeadGO != null ? myHeadGO.transform : null);
  46. }
  47. return cachedHeadset;
  48. }
  49. /// <summary>
  50. /// The GetHeadsetCamera method returns the Transform of the object that is used to hold the headset camera in the scene.
  51. /// </summary>
  52. /// <returns>A transform of the object holding the headset camera in the scene.</returns>
  53. public override Transform GetHeadsetCamera()
  54. {
  55. GameObject myHeadsetCameraGO = VRTK_SharedMethods.FindEvenInactiveGameObject<HyCamera>(null, true);
  56. cachedHeadsetCamera = (myHeadsetCameraGO != null ? myHeadsetCameraGO.transform : null);
  57. return cachedHeadsetCamera;
  58. }
  59. /// <summary>
  60. /// The GetHeadsetType method returns a string representing the type of headset connected.
  61. /// </summary>
  62. /// <returns>The string of the headset connected.</returns>
  63. public override string GetHeadsetType()
  64. {
  65. return CleanPropertyString("hyperealvr");
  66. }
  67. /// <summary>
  68. /// The GetHeadsetVelocity method is used to determine the current velocity of the headset.
  69. /// </summary>
  70. /// <returns>A Vector3 containing the current velocity of the headset.</returns>
  71. public override Vector3 GetHeadsetVelocity()
  72. {
  73. HyTrackingState headsetState = HyperealVR.Instance.GetTrackingState(HyDevice.Device_HMD0);
  74. return headsetState.velocity;
  75. }
  76. /// <summary>
  77. /// The GetHeadsetAngularVelocity method is used to determine the current angular velocity of the headset.
  78. /// </summary>
  79. /// <returns>A Vector3 containing the current angular velocity of the headset.</returns>
  80. public override Vector3 GetHeadsetAngularVelocity()
  81. {
  82. HyTrackingState headsetState = HyperealVR.Instance.GetTrackingState(HyDevice.Device_HMD0);
  83. return headsetState.angularVelocity;
  84. }
  85. /// <summary>
  86. /// The HeadsetFade method is used to apply a fade to the headset camera to progressively change the colour.
  87. /// </summary>
  88. /// <param name="color">The colour to fade to.</param>
  89. /// <param name="duration">The amount of time the fade should take to reach the given colour.</param>
  90. /// <param name="fadeOverlay">Determines whether to use an overlay on the fade.</param>
  91. public override void HeadsetFade(Color color, float duration, bool fadeOverlay = false)
  92. {
  93. VRTK_ScreenFade.Start(color, duration);
  94. }
  95. /// <summary>
  96. /// The HasHeadsetFade method checks to see if the given game object (usually the camera) has the ability to fade the viewpoint.
  97. /// </summary>
  98. /// <param name="obj">The Transform to check to see if a camera fade is available on.</param>
  99. /// <returns>Returns true if the headset has fade functionality on it.</returns>
  100. public override bool HasHeadsetFade(Transform obj)
  101. {
  102. if (obj.GetComponentInChildren<VRTK_ScreenFade>())
  103. {
  104. return true;
  105. }
  106. return false;
  107. }
  108. /// <summary>
  109. /// The AddHeadsetFade method attempts to add the fade functionality to the game object with the camera on it.
  110. /// </summary>
  111. /// <param name="camera">The Transform to with the camera on to add the fade functionality to.</param>
  112. public override void AddHeadsetFade(Transform camera)
  113. {
  114. if (camera != null && !camera.GetComponent<VRTK_ScreenFade>())
  115. {
  116. camera.gameObject.AddComponent<VRTK_ScreenFade>();
  117. }
  118. }
  119. #endif
  120. }
  121. }