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.

363 lines
12 KiB

  1. namespace VRTK
  2. {
  3. using UnityEngine;
  4. using System.Collections.Generic;
  5. public static class VRTK_SDK_Bridge
  6. {
  7. private static SDK_BaseSystem systemSDK = null;
  8. private static SDK_BaseHeadset headsetSDK = null;
  9. private static SDK_BaseController controllerSDK = null;
  10. private static SDK_BaseBoundaries boundariesSDK = null;
  11. #region Controller Methods
  12. public static void ControllerProcessUpdate(VRTK_ControllerReference controllerReference, Dictionary<string, object> options = null)
  13. {
  14. GetControllerSDK().ProcessUpdate(controllerReference, options);
  15. }
  16. public static void ControllerProcessFixedUpdate(VRTK_ControllerReference controllerReference, Dictionary<string, object> options = null)
  17. {
  18. GetControllerSDK().ProcessFixedUpdate(controllerReference, options);
  19. }
  20. public static SDK_BaseController.ControllerType GetCurrentControllerType(VRTK_ControllerReference controllerReference = null)
  21. {
  22. return GetControllerSDK().GetCurrentControllerType(controllerReference);
  23. }
  24. public static string GetControllerDefaultColliderPath(SDK_BaseController.ControllerHand hand)
  25. {
  26. return GetControllerSDK().GetControllerDefaultColliderPath(hand);
  27. }
  28. public static string GetControllerElementPath(SDK_BaseController.ControllerElements element, SDK_BaseController.ControllerHand hand, bool fullPath = false)
  29. {
  30. return GetControllerSDK().GetControllerElementPath(element, hand, fullPath);
  31. }
  32. public static uint GetControllerIndex(GameObject controller)
  33. {
  34. return GetControllerSDK().GetControllerIndex(controller);
  35. }
  36. public static GameObject GetControllerByIndex(uint index, bool actual)
  37. {
  38. return GetControllerSDK().GetControllerByIndex(index, actual);
  39. }
  40. public static Transform GetControllerOrigin(VRTK_ControllerReference controllerReference)
  41. {
  42. return GetControllerSDK().GetControllerOrigin(controllerReference);
  43. }
  44. [System.Obsolete("GenerateControllerPointerOrigin has been deprecated and will be removed in a future version of VRTK.")]
  45. public static Transform GenerateControllerPointerOrigin(GameObject parent)
  46. {
  47. return GetControllerSDK().GenerateControllerPointerOrigin(parent);
  48. }
  49. public static GameObject GetControllerLeftHand(bool actual)
  50. {
  51. return GetControllerSDK().GetControllerLeftHand(actual);
  52. }
  53. public static GameObject GetControllerRightHand(bool actual)
  54. {
  55. return GetControllerSDK().GetControllerRightHand(actual);
  56. }
  57. public static GameObject GetControllerByHand(SDK_BaseController.ControllerHand hand, bool actual)
  58. {
  59. switch (hand)
  60. {
  61. case SDK_BaseController.ControllerHand.Left:
  62. return GetControllerLeftHand(actual);
  63. case SDK_BaseController.ControllerHand.Right:
  64. return GetControllerRightHand(actual);
  65. }
  66. return null;
  67. }
  68. public static bool IsControllerLeftHand(GameObject controller)
  69. {
  70. return GetControllerSDK().IsControllerLeftHand(controller);
  71. }
  72. public static bool IsControllerRightHand(GameObject controller)
  73. {
  74. return GetControllerSDK().IsControllerRightHand(controller);
  75. }
  76. public static bool IsControllerLeftHand(GameObject controller, bool actual)
  77. {
  78. return GetControllerSDK().IsControllerLeftHand(controller, actual);
  79. }
  80. public static bool IsControllerRightHand(GameObject controller, bool actual)
  81. {
  82. return GetControllerSDK().IsControllerRightHand(controller, actual);
  83. }
  84. public static bool WaitForControllerModel(SDK_BaseController.ControllerHand hand)
  85. {
  86. return GetControllerSDK().WaitForControllerModel(hand);
  87. }
  88. public static GameObject GetControllerModel(GameObject controller)
  89. {
  90. return GetControllerSDK().GetControllerModel(controller);
  91. }
  92. public static GameObject GetControllerModel(SDK_BaseController.ControllerHand hand)
  93. {
  94. return GetControllerSDK().GetControllerModel(hand);
  95. }
  96. public static SDK_BaseController.ControllerHand GetControllerModelHand(GameObject controllerModel)
  97. {
  98. return GetControllerSDK().GetControllerModelHand(controllerModel);
  99. }
  100. public static GameObject GetControllerRenderModel(VRTK_ControllerReference controllerReference)
  101. {
  102. return GetControllerSDK().GetControllerRenderModel(controllerReference);
  103. }
  104. public static void SetControllerRenderModelWheel(GameObject renderModel, bool state)
  105. {
  106. GetControllerSDK().SetControllerRenderModelWheel(renderModel, state);
  107. }
  108. public static void HapticPulse(VRTK_ControllerReference controllerReference, float strength = 0.5f)
  109. {
  110. GetControllerSDK().HapticPulse(controllerReference, strength);
  111. }
  112. public static bool HapticPulse(VRTK_ControllerReference controllerReference, AudioClip clip)
  113. {
  114. return GetControllerSDK().HapticPulse(controllerReference, clip);
  115. }
  116. public static SDK_ControllerHapticModifiers GetHapticModifiers()
  117. {
  118. return GetControllerSDK().GetHapticModifiers();
  119. }
  120. public static Vector3 GetControllerVelocity(VRTK_ControllerReference controllerReference)
  121. {
  122. return GetControllerSDK().GetVelocity(controllerReference);
  123. }
  124. public static Vector3 GetControllerAngularVelocity(VRTK_ControllerReference controllerReference)
  125. {
  126. return GetControllerSDK().GetAngularVelocity(controllerReference);
  127. }
  128. public static bool IsTouchpadStatic(bool isTouched, Vector2 currentAxisValues, Vector2 previousAxisValues, int compareFidelity)
  129. {
  130. return GetControllerSDK().IsTouchpadStatic(isTouched, currentAxisValues, previousAxisValues, compareFidelity);
  131. }
  132. public static Vector2 GetControllerAxis(SDK_BaseController.ButtonTypes buttonType, VRTK_ControllerReference controllerReference)
  133. {
  134. return GetControllerSDK().GetButtonAxis(buttonType, controllerReference);
  135. }
  136. public static float GetControllerSenseAxis(SDK_BaseController.ButtonTypes buttonType, VRTK_ControllerReference controllerReference)
  137. {
  138. return GetControllerSDK().GetButtonSenseAxis(buttonType, controllerReference);
  139. }
  140. public static float GetControllerHairlineDelta(SDK_BaseController.ButtonTypes buttonType, VRTK_ControllerReference controllerReference)
  141. {
  142. return GetControllerSDK().GetButtonHairlineDelta(buttonType, controllerReference);
  143. }
  144. public static bool GetControllerButtonState(SDK_BaseController.ButtonTypes buttonType, SDK_BaseController.ButtonPressTypes pressType, VRTK_ControllerReference controllerReference)
  145. {
  146. return GetControllerSDK().GetControllerButtonState(buttonType, pressType, controllerReference);
  147. }
  148. #endregion
  149. #region Headset Methods
  150. public static void HeadsetProcessUpdate(Dictionary<string, object> options = null)
  151. {
  152. GetHeadsetSDK().ProcessUpdate(options);
  153. }
  154. public static void HeadsetProcessFixedUpdate(Dictionary<string, object> options = null)
  155. {
  156. GetHeadsetSDK().ProcessFixedUpdate(options);
  157. }
  158. public static Transform GetHeadset()
  159. {
  160. return GetHeadsetSDK().GetHeadset();
  161. }
  162. public static Transform GetHeadsetCamera()
  163. {
  164. return GetHeadsetSDK().GetHeadsetCamera();
  165. }
  166. public static string GetHeadsetType()
  167. {
  168. return GetHeadsetSDK().GetHeadsetType();
  169. }
  170. public static Vector3 GetHeadsetVelocity()
  171. {
  172. return GetHeadsetSDK().GetHeadsetVelocity();
  173. }
  174. public static Vector3 GetHeadsetAngularVelocity()
  175. {
  176. return GetHeadsetSDK().GetHeadsetAngularVelocity();
  177. }
  178. public static void HeadsetFade(Color color, float duration, bool fadeOverlay = false)
  179. {
  180. GetHeadsetSDK().HeadsetFade(color, duration, fadeOverlay);
  181. }
  182. public static bool HasHeadsetFade(Transform obj)
  183. {
  184. return GetHeadsetSDK().HasHeadsetFade(obj);
  185. }
  186. public static void AddHeadsetFade(Transform camera)
  187. {
  188. GetHeadsetSDK().AddHeadsetFade(camera);
  189. }
  190. #endregion
  191. #region Boundaries Methods
  192. public static Transform GetPlayArea()
  193. {
  194. return GetBoundariesSDK().GetPlayArea();
  195. }
  196. public static Vector3[] GetPlayAreaVertices()
  197. {
  198. return GetBoundariesSDK().GetPlayAreaVertices();
  199. }
  200. public static float GetPlayAreaBorderThickness()
  201. {
  202. return GetBoundariesSDK().GetPlayAreaBorderThickness();
  203. }
  204. public static bool IsPlayAreaSizeCalibrated()
  205. {
  206. return GetBoundariesSDK().IsPlayAreaSizeCalibrated();
  207. }
  208. public static bool GetDrawAtRuntime()
  209. {
  210. return GetBoundariesSDK().GetDrawAtRuntime();
  211. }
  212. public static void SetDrawAtRuntime(bool value)
  213. {
  214. GetBoundariesSDK().SetDrawAtRuntime(value);
  215. }
  216. #endregion
  217. #region System Methods
  218. public static bool IsDisplayOnDesktop()
  219. {
  220. return GetSystemSDK().IsDisplayOnDesktop();
  221. }
  222. public static bool ShouldAppRenderWithLowResources()
  223. {
  224. return GetSystemSDK().ShouldAppRenderWithLowResources();
  225. }
  226. public static void ForceInterleavedReprojectionOn(bool force)
  227. {
  228. GetSystemSDK().ForceInterleavedReprojectionOn(force);
  229. }
  230. #endregion
  231. public static SDK_BaseSystem GetSystemSDK()
  232. {
  233. if (VRTK_SDKManager.instance != null && VRTK_SDKManager.instance.loadedSetup != null)
  234. {
  235. return VRTK_SDKManager.instance.loadedSetup.systemSDK;
  236. }
  237. if (systemSDK == null)
  238. {
  239. systemSDK = ScriptableObject.CreateInstance<SDK_FallbackSystem>();
  240. }
  241. return systemSDK;
  242. }
  243. public static SDK_BaseHeadset GetHeadsetSDK()
  244. {
  245. if (VRTK_SDKManager.instance != null && VRTK_SDKManager.instance.loadedSetup != null)
  246. {
  247. return VRTK_SDKManager.instance.loadedSetup.headsetSDK;
  248. }
  249. if (headsetSDK == null)
  250. {
  251. headsetSDK = ScriptableObject.CreateInstance<SDK_FallbackHeadset>();
  252. }
  253. return headsetSDK;
  254. }
  255. public static SDK_BaseController GetControllerSDK()
  256. {
  257. if (VRTK_SDKManager.instance != null && VRTK_SDKManager.instance.loadedSetup != null)
  258. {
  259. return VRTK_SDKManager.instance.loadedSetup.controllerSDK;
  260. }
  261. if (controllerSDK == null)
  262. {
  263. controllerSDK = ScriptableObject.CreateInstance<SDK_FallbackController>();
  264. }
  265. return controllerSDK;
  266. }
  267. public static SDK_BaseBoundaries GetBoundariesSDK()
  268. {
  269. if (VRTK_SDKManager.instance != null && VRTK_SDKManager.instance.loadedSetup != null)
  270. {
  271. return VRTK_SDKManager.instance.loadedSetup.boundariesSDK;
  272. }
  273. if (boundariesSDK == null)
  274. {
  275. boundariesSDK = ScriptableObject.CreateInstance<SDK_FallbackBoundaries>();
  276. }
  277. return boundariesSDK;
  278. }
  279. public static void InvalidateCaches()
  280. {
  281. #if UNITY_EDITOR
  282. Object.DestroyImmediate(systemSDK);
  283. Object.DestroyImmediate(headsetSDK);
  284. Object.DestroyImmediate(controllerSDK);
  285. Object.DestroyImmediate(boundariesSDK);
  286. #else
  287. Object.Destroy(systemSDK);
  288. Object.Destroy(headsetSDK);
  289. Object.Destroy(controllerSDK);
  290. Object.Destroy(boundariesSDK);
  291. #endif
  292. systemSDK = null;
  293. headsetSDK = null;
  294. controllerSDK = null;
  295. boundariesSDK = null;
  296. }
  297. }
  298. }