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.

58 lines
1.6 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using VRTK;
  5. public class RingTeleportation : VRTK_HeightAdjustTeleport
  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(playArea.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 GetNewPosition(Vector3 tipPosition, Transform target, bool returnOriginalPosition)
  25. {
  26. Vector3 basePosition = base.GetNewPosition(tipPosition, target, true);
  27. return basePosition;
  28. }
  29. protected override Quaternion SetNewRotation(Quaternion? rotation)
  30. {
  31. Debug.Log("Setting new rotation");
  32. return Quaternion.FromToRotation(Vector3.down, DownDirection);
  33. }
  34. protected override void ProcessOrientation(object sender, DestinationMarkerEventArgs e, Vector3 targetPosition, Quaternion targetRotation)
  35. {
  36. base.ProcessOrientation(sender, e, targetPosition, targetRotation);
  37. Quaternion newRotation = Quaternion.FromToRotation(Vector3.down, m_ring.getDownDirection(targetPosition));
  38. playArea.rotation = newRotation;
  39. }
  40. }