using System.Collections; using System.Collections.Generic; using UnityEngine; using ChivaXR; using DG.Tweening; using System; public class AniDriver_RotateBySelf : AnimationDriverBase { public Transform target; public Axis axis; public Vector3 initAngle; public Vector3 targetAngle; public float duration; public override void FinishedState() { target.DOKill(); target.transform.localEulerAngles = targetAngle; } public override void InitState() { target.DOKill(); target.transform.localEulerAngles = initAngle; } public override void StartPlay(Action finishedCallBack = null) { target.DOLocalRotateQuaternion(Quaternion.Euler(targetAngle.x, targetAngle.y, targetAngle.z), duration).OnComplete(() => finishedCallBack?.Invoke()); //StartAniCoroutine(RotateBySelf(finishedCallBack)); } /// /// 根据路径点移动 /// /// /// /// /// /// IEnumerator RotateBySelf(Action finishedCallBack = null) { bool moveToTarget = false; float timer = 0; float lerp = 0; //初始角度 Quaternion tmpInitQuaternion = target.rotation; Quaternion tmpTargetQuaternion = new Quaternion(targetAngle.x, targetAngle.y, targetAngle.z, 0); while (!moveToTarget) { target.transform.rotation = Quaternion.Lerp(tmpInitQuaternion, tmpTargetQuaternion, lerp); if (Quaternion.Angle(target.transform.rotation, tmpTargetQuaternion) < 5) { target.transform.rotation = tmpTargetQuaternion; moveToTarget = true; } timer += Time.deltaTime; lerp = timer / duration; yield return new WaitForEndOfFrame(); } Debug.Log("MoveEnd is true"); finishedCallBack?.Invoke(); } }