SCKeyboardFollower.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using DG.Tweening;
  2. using System.Collections;
  3. using UnityEngine;
  4. namespace SC.XR.Unity
  5. {
  6. [RequireComponent(typeof(SCKeyboardMono))]
  7. public class SCKeyboardFollower : FollowerBase
  8. {
  9. Vector3 viewPoint = Vector3.zero;
  10. Vector3 worldPoint = Vector3.zero;
  11. Vector3 cachedKeyboardViewportPosition = Vector3.zero;
  12. Vector3 keyboardEuler = Vector3.zero;
  13. public override void SetTransform(Transform transform)
  14. {
  15. cachedKeyboardViewportPosition = SvrManager.Instance.leftCamera.WorldToViewportPoint(transform.position);
  16. keyboardEuler = transform.rotation.eulerAngles;
  17. }
  18. protected override void Follow()
  19. {
  20. viewPoint = SvrManager.Instance.leftCamera.WorldToViewportPoint(transform.position);
  21. worldPoint = SvrManager.Instance.leftCamera.ViewportToWorldPoint(cachedKeyboardViewportPosition);
  22. if (viewPoint.x < -0.2 || viewPoint.y < -0.2 || viewPoint.x > 1.2 || viewPoint.y > 1.2)
  23. {
  24. //Debug.Log("Start Following");
  25. Vector3 angle = SvrManager.Instance.leftCamera.transform.eulerAngles;
  26. //transform.DORotate(new Vector3(0, angle.y, 0), 0.5f).SetEase(Ease.InQuart).SetAutoKill(true);
  27. transform.DORotate(new Vector3(keyboardEuler.x, angle.y, keyboardEuler.z), 0.2f).SetEase(Ease.InQuart).SetAutoKill(true);
  28. transform.DOMove(worldPoint, 0.5f).SetEase(Ease.OutCubic).SetAutoKill(true);
  29. }
  30. }
  31. }
  32. }