using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.XR.Interaction.Toolkit; using DG.Tweening; //DOTween 네임스페이스 using UnityEngine.Assertions; public class FadeTeleportationProvider : TeleportationProvider { public Image fadeScreen; public Color fadeColor = Color.black; public float fadeDuration = 0.5f; // Start is called before the first frame update void Start() { startLocomotion += FadeTeleportationProvider_startLocomotion; endLocomotion += FadeTeleportationProvider_endLocomotion; fadeScreen.color = fadeColor; } private void FadeTeleportationProvider_startLocomotion(LocomotionSystem obj) { print("Start Locomotion"); //페이드아웃이 끝나면 Teleport 함수를 실행해라 fadeScreen.DOFade(1f, fadeDuration).OnComplete(Teleport); } private void FadeTeleportationProvider_endLocomotion(LocomotionSystem obj) { print("End Locomotion"); fadeScreen.DOFade(0f, fadeDuration); } protected override void Update() { //텔레포트 요청 if (!validRequest || !BeginLocomotion()) return; } void Teleport() { print("Begin TeleporT!!!"); //실제 텔레포트 하는 부분 var xrRig = system.xrRig; if (xrRig != null) { switch (currentRequest.matchOrientation) { case MatchOrientation.WorldSpaceUp: xrRig.MatchRigUp(Vector3.up); break; case MatchOrientation.TargetUp: xrRig.MatchRigUp(currentRequest.destinationRotation * Vector3.up); break; case MatchOrientation.TargetUpAndForward: xrRig.MatchRigUpCameraForward(currentRequest.destinationRotation * Vector3.up, currentRequest.destinationRotation * Vector3.forward); break; case MatchOrientation.None: // Change nothing. Maintain current rig rotation. break; default: Assert.IsTrue(false, $"Unhandled {nameof(MatchOrientation)}={currentRequest.matchOrientation}."); break; } var heightAdjustment = xrRig.rig.transform.up * xrRig.cameraInRigSpaceHeight; var cameraDestination = currentRequest.destinationPosition + heightAdjustment; xrRig.MoveCameraToWorldLocation(cameraDestination); } EndLocomotion(); validRequest = false; } }