using DG.Tweening; using System.Collections; using UnityEngine; namespace SC.XR.Unity { [RequireComponent(typeof(SCKeyboardMono))] public class SCKeyboardFollower : FollowerBase { Vector3 viewPoint = Vector3.zero; Vector3 worldPoint = Vector3.zero; Vector3 cachedKeyboardViewportPosition = Vector3.zero; Vector3 keyboardEuler = Vector3.zero; public override void SetTransform(Transform transform) { cachedKeyboardViewportPosition = SvrManager.Instance.leftCamera.WorldToViewportPoint(transform.position); keyboardEuler = transform.rotation.eulerAngles; } protected override void Follow() { viewPoint = SvrManager.Instance.leftCamera.WorldToViewportPoint(transform.position); worldPoint = SvrManager.Instance.leftCamera.ViewportToWorldPoint(cachedKeyboardViewportPosition); if (viewPoint.x < -0.2 || viewPoint.y < -0.2 || viewPoint.x > 1.2 || viewPoint.y > 1.2) { //Debug.Log("Start Following"); Vector3 angle = SvrManager.Instance.leftCamera.transform.eulerAngles; //transform.DORotate(new Vector3(0, angle.y, 0), 0.5f).SetEase(Ease.InQuart).SetAutoKill(true); transform.DORotate(new Vector3(keyboardEuler.x, angle.y, keyboardEuler.z), 0.2f).SetEase(Ease.InQuart).SetAutoKill(true); transform.DOMove(worldPoint, 0.5f).SetEase(Ease.OutCubic).SetAutoKill(true); } } } }