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.2 KiB

  1. // Oculus Boundaries|SDK_Oculus|005
  2. namespace VRTK
  3. {
  4. #if VRTK_DEFINE_SDK_OCULUS
  5. using UnityEngine;
  6. #endif
  7. /// <summary>
  8. /// The Oculus Boundaries SDK script provides a bridge to the Oculus SDK play area.
  9. /// </summary>
  10. [SDK_Description(typeof(SDK_OculusSystem))]
  11. [SDK_Description(typeof(SDK_OculusSystem), 1)]
  12. public class SDK_OculusBoundaries
  13. #if VRTK_DEFINE_SDK_OCULUS
  14. : SDK_BaseBoundaries
  15. #else
  16. : SDK_FallbackBoundaries
  17. #endif
  18. {
  19. #if VRTK_DEFINE_SDK_OCULUS
  20. /// <summary>
  21. /// The InitBoundaries method is run on start of scene and can be used to initialse anything on game start.
  22. /// </summary>
  23. public override void InitBoundaries()
  24. {
  25. #if VRTK_DEFINE_SDK_OCULUS_AVATAR
  26. GetAvatar();
  27. #endif
  28. }
  29. /// <summary>
  30. /// The GetPlayArea method returns the Transform of the object that is used to represent the play area in the scene.
  31. /// </summary>
  32. /// <returns>A transform of the object representing the play area in the scene.</returns>
  33. public override Transform GetPlayArea()
  34. {
  35. cachedPlayArea = GetSDKManagerPlayArea();
  36. if (cachedPlayArea == null)
  37. {
  38. OVRManager ovrManager = VRTK_SharedMethods.FindEvenInactiveComponent<OVRManager>(true);
  39. if (ovrManager != null)
  40. {
  41. cachedPlayArea = ovrManager.transform;
  42. }
  43. }
  44. return cachedPlayArea;
  45. }
  46. /// <summary>
  47. /// The GetPlayAreaVertices method returns the points of the play area boundaries.
  48. /// </summary>
  49. /// <returns>A Vector3 array of the points in the scene that represent the play area boundaries.</returns>
  50. public override Vector3[] GetPlayAreaVertices()
  51. {
  52. OVRBoundary area = new OVRBoundary();
  53. if (area.GetConfigured())
  54. {
  55. Vector3 outerBoundary = area.GetDimensions(OVRBoundary.BoundaryType.OuterBoundary);
  56. float thickness = 0.1f;
  57. Vector3[] vertices = new Vector3[8];
  58. vertices[0] = new Vector3(outerBoundary.x - thickness, 0f, outerBoundary.z - thickness);
  59. vertices[1] = new Vector3(0f + thickness, 0f, outerBoundary.z - thickness);
  60. vertices[2] = new Vector3(0f + thickness, 0f, 0f + thickness);
  61. vertices[3] = new Vector3(outerBoundary.x - thickness, 0f, 0f + thickness);
  62. vertices[4] = new Vector3(outerBoundary.x, 0f, outerBoundary.z);
  63. vertices[5] = new Vector3(0f, 0f, outerBoundary.z);
  64. vertices[6] = new Vector3(0f, 0f, 0f);
  65. vertices[7] = new Vector3(outerBoundary.x, 0f, 0f);
  66. return vertices;
  67. }
  68. return null;
  69. }
  70. /// <summary>
  71. /// The GetPlayAreaBorderThickness returns the thickness of the drawn border for the given play area.
  72. /// </summary>
  73. /// <returns>The thickness of the drawn border.</returns>
  74. public override float GetPlayAreaBorderThickness()
  75. {
  76. return 0.1f;
  77. }
  78. /// <summary>
  79. /// The IsPlayAreaSizeCalibrated method returns whether the given play area size has been auto calibrated by external sensors.
  80. /// </summary>
  81. /// <returns>Returns true if the play area size has been auto calibrated and set by external sensors.</returns>
  82. public override bool IsPlayAreaSizeCalibrated()
  83. {
  84. return true;
  85. }
  86. /// <summary>
  87. /// The GetDrawAtRuntime method returns whether the given play area drawn border is being displayed.
  88. /// </summary>
  89. /// <returns>Returns true if the drawn border is being displayed.</returns>
  90. public override bool GetDrawAtRuntime()
  91. {
  92. return false;
  93. }
  94. /// <summary>
  95. /// The SetDrawAtRuntime method sets whether the given play area drawn border should be displayed at runtime.
  96. /// </summary>
  97. /// <param name="value">The state of whether the drawn border should be displayed or not.</param>
  98. public override void SetDrawAtRuntime(bool value)
  99. {
  100. }
  101. #if VRTK_DEFINE_SDK_OCULUS_AVATAR
  102. private OvrAvatar avatarContainer;
  103. /// <summary>
  104. /// The GetAvatar method is used to retrieve the Oculus Avatar object if it exists in the scene. This method is only available if the Oculus Avatar package is installed.
  105. /// </summary>
  106. /// <returns>The OvrAvatar script for managing the Oculus Avatar.</returns>
  107. public virtual OvrAvatar GetAvatar()
  108. {
  109. if (avatarContainer == null)
  110. {
  111. avatarContainer = VRTK_SharedMethods.FindEvenInactiveComponent<OvrAvatar>(true);
  112. if (avatarContainer != null && avatarContainer.GetComponent<VRTK_TransformFollow>() == null)
  113. {
  114. VRTK_TransformFollow objectFollow = avatarContainer.gameObject.AddComponent<VRTK_TransformFollow>();
  115. objectFollow.gameObjectToFollow = GetPlayArea().gameObject;
  116. }
  117. }
  118. return avatarContainer;
  119. }
  120. #endif
  121. #endif
  122. }
  123. }