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.

190 lines
7.6 KiB

  1. // Base Headset|SDK_Base|005
  2. namespace VRTK
  3. {
  4. using UnityEngine;
  5. using System.Collections.Generic;
  6. #if UNITY_2017_2_OR_NEWER
  7. using UnityEngine.XR;
  8. #else
  9. using XRDevice = UnityEngine.VR.VRDevice;
  10. using XRSettings = UnityEngine.VR.VRSettings;
  11. #endif
  12. /// <summary>
  13. /// The Base Headset SDK script provides a bridge to SDK methods that deal with the VR Headset.
  14. /// </summary>
  15. /// <remarks>
  16. /// This is an abstract class to implement the interface required by all implemented SDKs.
  17. /// </remarks>
  18. public abstract class SDK_BaseHeadset : SDK_Base
  19. {
  20. /// <summary>
  21. /// The connected headset type
  22. /// </summary>
  23. public enum HeadsetType
  24. {
  25. /// <summary>
  26. /// The headset connected is unknown.
  27. /// </summary>
  28. Undefined,
  29. /// <summary>
  30. /// The headset associated with the simulator.
  31. /// </summary>
  32. Simulator,
  33. /// <summary>
  34. /// The HTC Vive headset.
  35. /// </summary>
  36. HTCVive,
  37. /// <summary>
  38. /// The Oculus Rift DK1 headset.
  39. /// </summary>
  40. OculusRiftDK1,
  41. /// <summary>
  42. /// The Oculus Rift DK2 headset.
  43. /// </summary>
  44. OculusRiftDK2,
  45. /// <summary>
  46. /// The Oculus Rift headset.
  47. /// </summary>
  48. OculusRift,
  49. /// <summary>
  50. /// The Oculus GearVR headset.
  51. /// </summary>
  52. OculusGearVR,
  53. /// <summary>
  54. /// The Google Daydream headset.
  55. /// </summary>
  56. GoogleDaydream,
  57. /// <summary>
  58. /// The Google Cardboard headset.
  59. /// </summary>
  60. GoogleCardboard,
  61. /// <summary>
  62. /// The HyperealVR headset.
  63. /// </summary>
  64. HyperealVR,
  65. /// <summary>
  66. /// The Windows Mixed Reality headset.
  67. /// </summary>
  68. WindowsMixedReality
  69. }
  70. protected Transform cachedHeadset;
  71. protected Transform cachedHeadsetCamera;
  72. /// <summary>
  73. /// The ProcessUpdate method enables an SDK to run logic for every Unity Update
  74. /// </summary>
  75. /// <param name="options">A dictionary of generic options that can be used to within the update.</param>
  76. public abstract void ProcessUpdate(Dictionary<string, object> options);
  77. /// <summary>
  78. /// The ProcessFixedUpdate method enables an SDK to run logic for every Unity FixedUpdate
  79. /// </summary>
  80. /// <param name="options">A dictionary of generic options that can be used to within the fixed update.</param>
  81. public abstract void ProcessFixedUpdate(Dictionary<string, object> options);
  82. /// <summary>
  83. /// The GetHeadset method returns the Transform of the object that is used to represent the headset in the scene.
  84. /// </summary>
  85. /// <returns>A transform of the object representing the headset in the scene.</returns>
  86. public abstract Transform GetHeadset();
  87. /// <summary>
  88. /// The GetHeadsetCamera method returns the Transform of the object that is used to hold the headset camera in the scene.
  89. /// </summary>
  90. /// <returns>A transform of the object holding the headset camera in the scene.</returns>
  91. public abstract Transform GetHeadsetCamera();
  92. /// <summary>
  93. /// The GetHeadsetType method returns a string representing the type of headset connected.
  94. /// </summary>
  95. /// <returns>The string of the headset connected.</returns>
  96. public abstract string GetHeadsetType();
  97. /// <summary>
  98. /// The GetHeadsetVelocity method is used to determine the current velocity of the headset.
  99. /// </summary>
  100. /// <returns>A Vector3 containing the current velocity of the headset.</returns>
  101. public abstract Vector3 GetHeadsetVelocity();
  102. /// <summary>
  103. /// The GetHeadsetAngularVelocity method is used to determine the current angular velocity of the headset.
  104. /// </summary>
  105. /// <returns>A Vector3 containing the current angular velocity of the headset.</returns>
  106. public abstract Vector3 GetHeadsetAngularVelocity();
  107. /// <summary>
  108. /// The HeadsetFade method is used to apply a fade to the headset camera to progressively change the colour.
  109. /// </summary>
  110. /// <param name="color">The colour to fade to.</param>
  111. /// <param name="duration">The amount of time the fade should take to reach the given colour.</param>
  112. /// <param name="fadeOverlay">Determines whether to use an overlay on the fade.</param>
  113. public abstract void HeadsetFade(Color color, float duration, bool fadeOverlay = false);
  114. /// <summary>
  115. /// The HasHeadsetFade method checks to see if the given game object (usually the camera) has the ability to fade the viewpoint.
  116. /// </summary>
  117. /// <param name="obj">The Transform to check to see if a camera fade is available on.</param>
  118. /// <returns>Returns true if the headset has fade functionality on it.</returns>
  119. public abstract bool HasHeadsetFade(Transform obj);
  120. /// <summary>
  121. /// The AddHeadsetFade method attempts to add the fade functionality to the game object with the camera on it.
  122. /// </summary>
  123. /// <param name="camera">The Transform to with the camera on to add the fade functionality to.</param>
  124. public abstract void AddHeadsetFade(Transform camera);
  125. protected Transform GetSDKManagerHeadset()
  126. {
  127. VRTK_SDKManager sdkManager = VRTK_SDKManager.instance;
  128. if (sdkManager != null && sdkManager.loadedSetup != null && sdkManager.loadedSetup.actualHeadset != null)
  129. {
  130. cachedHeadset = (sdkManager.loadedSetup.actualHeadset ? sdkManager.loadedSetup.actualHeadset.transform : null);
  131. return cachedHeadset;
  132. }
  133. return null;
  134. }
  135. protected virtual string ScrapeHeadsetType()
  136. {
  137. string model = CleanPropertyString(XRDevice.model);
  138. string deviceName = CleanPropertyString(XRSettings.loadedDeviceName);
  139. switch (model)
  140. {
  141. case "oculusriftcv1":
  142. case "oculusriftes07":
  143. return CleanPropertyString("oculusrift");
  144. case "vivemv":
  145. case "vivedvt":
  146. return CleanPropertyString("htcvive");
  147. case "googleinc-daydreamview":
  148. return "googledaydream";
  149. case "googleinc-defaultcardboard":
  150. return "googlecardboard";
  151. case "galaxynote5":
  152. case "galaxys6":
  153. case "galaxys6edge":
  154. case "galaxys7":
  155. case "galaxys7edge":
  156. case "galaxys8":
  157. case "galaxys8+":
  158. if (deviceName == "oculus")
  159. {
  160. return "oculusgearvr";
  161. }
  162. break;
  163. case "oculusriftdk1":
  164. return CleanPropertyString("oculusriftdk1");
  165. case "oculusriftdk2":
  166. return CleanPropertyString("oculusriftdk2");
  167. case "acermixedreality":
  168. return CleanPropertyString("windowsmixedreality");
  169. }
  170. return "";
  171. }
  172. protected string CleanPropertyString(string inputString)
  173. {
  174. return inputString.Replace(" ", "").Replace(".", "").Replace(",", "").ToLowerInvariant();
  175. }
  176. }
  177. }