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.

136 lines
5.5 KiB

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