SW 중심대학 OSS GIT 서버 새로운 리포
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.

80 lines
2.6 KiB

5 years ago
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEngine.XR.Interaction.Toolkit;
  6. using DG.Tweening; //DOTween 네임스페이스
  7. using UnityEngine.Assertions;
  8. public class FadeTeleportationProvider : TeleportationProvider
  9. {
  10. public Image fadeScreen;
  11. public Color fadeColor = Color.black;
  12. public float fadeDuration = 0.5f;
  13. // Start is called before the first frame update
  14. void Start()
  15. {
  16. startLocomotion += FadeTeleportationProvider_startLocomotion;
  17. endLocomotion += FadeTeleportationProvider_endLocomotion;
  18. fadeScreen.color = fadeColor;
  19. }
  20. private void FadeTeleportationProvider_startLocomotion(LocomotionSystem obj)
  21. {
  22. print("Start Locomotion");
  23. //페이드아웃이 끝나면 Teleport 함수를 실행해라
  24. fadeScreen.DOFade(1f, fadeDuration).OnComplete(Teleport);
  25. }
  26. private void FadeTeleportationProvider_endLocomotion(LocomotionSystem obj)
  27. {
  28. print("End Locomotion");
  29. fadeScreen.DOFade(0f, fadeDuration);
  30. }
  31. protected override void Update()
  32. {
  33. //텔레포트 요청
  34. if (!validRequest || !BeginLocomotion())
  35. return;
  36. }
  37. void Teleport()
  38. {
  39. print("Begin TeleporT!!!");
  40. //실제 텔레포트 하는 부분
  41. var xrRig = system.xrRig;
  42. if (xrRig != null)
  43. {
  44. switch (currentRequest.matchOrientation)
  45. {
  46. case MatchOrientation.WorldSpaceUp:
  47. xrRig.MatchRigUp(Vector3.up);
  48. break;
  49. case MatchOrientation.TargetUp:
  50. xrRig.MatchRigUp(currentRequest.destinationRotation * Vector3.up);
  51. break;
  52. case MatchOrientation.TargetUpAndForward:
  53. xrRig.MatchRigUpCameraForward(currentRequest.destinationRotation * Vector3.up, currentRequest.destinationRotation * Vector3.forward);
  54. break;
  55. case MatchOrientation.None:
  56. // Change nothing. Maintain current rig rotation.
  57. break;
  58. default:
  59. Assert.IsTrue(false, $"Unhandled {nameof(MatchOrientation)}={currentRequest.matchOrientation}.");
  60. break;
  61. }
  62. var heightAdjustment = xrRig.rig.transform.up * xrRig.cameraInRigSpaceHeight;
  63. var cameraDestination = currentRequest.destinationPosition + heightAdjustment;
  64. xrRig.MoveCameraToWorldLocation(cameraDestination);
  65. }
  66. EndLocomotion();
  67. validRequest = false;
  68. }
  69. }