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.

63 lines
1.8 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using VRTK;
  5. public class RingBezierPointer : VRTK_BezierPointerRenderer
  6. {
  7. #region Read-Only Fields
  8. /// <summary>
  9. /// Direction from Centre of ship to CameraRig
  10. /// </summary>
  11. public Vector3 DownDirection => m_ring.getDownDirection(transform.position);
  12. #endregion Read-Only Fields
  13. #region Inspector Fields
  14. [Header("Ring Settings")]
  15. [SerializeField, Tooltip("Reference to the Ship which is being teleported on. If left empty will try and find one in scene")]
  16. private RotationController m_ring;
  17. #endregion Inspector Fields
  18. protected override void OnEnable()
  19. {
  20. base.OnEnable();
  21. if (m_ring == null)
  22. m_ring = FindObjectOfType<RotationController>();
  23. }
  24. protected override Vector3 ProjectDownBeam(Vector3 jointPosition)
  25. {
  26. Vector3 downPosition = Vector3.zero;
  27. Ray projectedBeamDownRaycast = new Ray(jointPosition, DownDirection);
  28. RaycastHit collidedWith;
  29. bool downRayHit = VRTK_CustomRaycast.Raycast(customRaycast, projectedBeamDownRaycast, out collidedWith, defaultIgnoreLayer, maximumLength.y);
  30. if (!downRayHit || (destinationHit.collider && destinationHit.collider != collidedWith.collider))
  31. {
  32. if (destinationHit.collider != null)
  33. {
  34. PointerExit(destinationHit);
  35. }
  36. destinationHit = new RaycastHit();
  37. downPosition = projectedBeamDownRaycast.GetPoint(0f);
  38. }
  39. if (downRayHit)
  40. {
  41. downPosition = projectedBeamDownRaycast.GetPoint(collidedWith.distance);
  42. PointerEnter(collidedWith);
  43. destinationHit = collidedWith;
  44. }
  45. return downPosition;
  46. }
  47. }