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.

97 lines
3.8 KiB

  1. namespace VRTK
  2. {
  3. using UnityEngine;
  4. [ExecuteInEditMode]
  5. [System.Obsolete("`VRTK_RoomExtender_PlayAreaGizmo` will be removed in a future version of VRTK.")]
  6. public class VRTK_RoomExtender_PlayAreaGizmo : MonoBehaviour
  7. {
  8. public Color color = Color.red;
  9. public float wireframeHeight = 2.0f;
  10. public bool drawWireframeWhenSelectedOnly = false;
  11. protected Transform playArea;
  12. protected VRTK_RoomExtender roomExtender;
  13. protected virtual void Awake()
  14. {
  15. VRTK_SDKManager.AttemptAddBehaviourToToggleOnLoadedSetupChange(this);
  16. }
  17. protected virtual void OnEnable()
  18. {
  19. playArea = VRTK_DeviceFinder.PlayAreaTransform();
  20. roomExtender = FindObjectOfType<VRTK_RoomExtender>();
  21. if (playArea == null || roomExtender == null)
  22. {
  23. VRTK_Logger.Warn(VRTK_Logger.GetCommonMessage(VRTK_Logger.CommonMessageKeys.REQUIRED_COMPONENT_MISSING_FROM_GAMEOBJECT, "VRTK_RoomExtender_PlayAreaGizmo", "PlayArea or VRTK_RoomExtender", "an active"));
  24. return;
  25. }
  26. }
  27. protected virtual void OnDestroy()
  28. {
  29. VRTK_SDKManager.AttemptRemoveBehaviourToToggleOnLoadedSetupChange(this);
  30. }
  31. protected virtual void OnDrawGizmos()
  32. {
  33. if (!drawWireframeWhenSelectedOnly)
  34. {
  35. DrawWireframe();
  36. }
  37. }
  38. protected virtual void OnDrawGizmosSelected()
  39. {
  40. if (drawWireframeWhenSelectedOnly)
  41. {
  42. DrawWireframe();
  43. }
  44. }
  45. protected virtual void DrawWireframe()
  46. {
  47. if (playArea == null || roomExtender == null)
  48. {
  49. return;
  50. }
  51. Vector3[] vertices = VRTK_SDK_Bridge.GetPlayAreaVertices();
  52. if (vertices == null || vertices.Length == 0)
  53. {
  54. return;
  55. }
  56. int btmRight = 4;
  57. int btmLeft = 5;
  58. int topLeft = 6;
  59. int topRight = 7;
  60. Vector3 btmRightVertex = vertices[btmRight] * roomExtender.additionalMovementMultiplier;
  61. Vector3 btmLeftVertex = vertices[btmLeft] * roomExtender.additionalMovementMultiplier;
  62. Vector3 topLeftVertex = vertices[topLeft] * roomExtender.additionalMovementMultiplier;
  63. Vector3 topRightVertex = vertices[topRight] * roomExtender.additionalMovementMultiplier;
  64. Vector3 btmOffset = new Vector3(0f, roomExtender.transform.localPosition.y, 0f);
  65. Vector3 topOffset = btmOffset + playArea.TransformVector(Vector3.up * wireframeHeight);
  66. Gizmos.color = color;
  67. //bottom rectangle
  68. Gizmos.DrawLine(btmRightVertex + btmOffset, btmLeftVertex + btmOffset);
  69. Gizmos.DrawLine(topLeftVertex + btmOffset, topRightVertex + btmOffset);
  70. Gizmos.DrawLine(btmRightVertex + btmOffset, topRightVertex + btmOffset);
  71. Gizmos.DrawLine(btmLeftVertex + btmOffset, topLeftVertex + btmOffset);
  72. //top rectangle
  73. Gizmos.DrawLine(btmRightVertex + topOffset, btmLeftVertex + topOffset);
  74. Gizmos.DrawLine(topLeftVertex + topOffset, topRightVertex + topOffset);
  75. Gizmos.DrawLine(btmRightVertex + topOffset, topRightVertex + topOffset);
  76. Gizmos.DrawLine(btmLeftVertex + topOffset, topLeftVertex + topOffset);
  77. //sides
  78. Gizmos.DrawLine(btmRightVertex + btmOffset, btmRightVertex + topOffset);
  79. Gizmos.DrawLine(btmLeftVertex + btmOffset, btmLeftVertex + topOffset);
  80. Gizmos.DrawLine(topRightVertex + btmOffset, topRightVertex + topOffset);
  81. Gizmos.DrawLine(topLeftVertex + btmOffset, topLeftVertex + topOffset);
  82. }
  83. }
  84. }