123456789101112131415161718192021222324252627282930313233343536373839404142 |
- using DG.Tweening;
- using System.Collections;
- using UnityEngine;
- namespace SC.XR.Unity {
- [RequireComponent(typeof(SCKeyboardMono))]
- public class SCKeyboardFollower : FollowerBase {
- Vector3 viewPoint = Vector3.zero;
- bool isFollowing = false;
- Vector2 initViewPoint;
- protected override void OnEnable() {
- base.OnEnable();
- initViewPoint = Camera.main.WorldToViewportPoint(CalculateWindowPosition(Camera.main.transform));
- isFollowing = true;
- StopFollower = false;
- }
- protected override void Follow() {
- if (Camera.main == null || Camera.main.transform == null)
- return;
- viewPoint = Camera.main.WorldToViewportPoint(transform.position);
- if (viewPoint.x < (initViewPoint.x - 1f) || viewPoint.y < (initViewPoint.y - 0.5f) || viewPoint.x > (initViewPoint.x + 1f) || viewPoint.y > (initViewPoint.y + 1f) || Vector3.Magnitude(Camera.main.transform.position - transform.position) > (WindowDistance+0.1f)) {
- isFollowing = true;
- } else if (Mathf.Abs(viewPoint.x - initViewPoint.x) < 0.03f && Mathf.Abs(viewPoint.y - initViewPoint.y) < 0.03f) {
- isFollowing = false;
- StopFollower = true;
- }
- if (isFollowing) {
- transform.position = Vector3.Lerp(transform.position, CalculateWindowPosition(Camera.main.transform), WindowFollowSpeed * Time.deltaTime);
- transform.rotation = Quaternion.Slerp(transform.rotation, CalculateWindowRotation(Camera.main.transform), WindowFollowSpeed * Time.deltaTime);
- }
- }
- }
- }
|