using System.Collections; using System.Collections.Generic; using UnityEngine; using ChivaXR; using System; using Sirenix.OdinInspector; using DG.Tweening; public class AniDriver_MoveAndRotateByDistance : AnimationDriverBase { [Title("旋转模式(默认模式:WorldAxisAdd)")] [LabelText("旋转模式")] [SerializeField] private RotateMode m_RotateMode = RotateMode.WorldAxisAdd; [BoxGroup("Angle设定")] public Vector3 initRotateAngle; [BoxGroup("Angle设定")] public Vector3 targetRotateAngle; [BoxGroup("Position设定")] public Vector3 initLocalPosition; [BoxGroup("Position设定")] public Vector3 targetLocalPosition; public float duration; [LabelText("要操作的物体(物体在父节点的坐标应为0)")] public List moveObjs = new List(); Sequence sequence; public override void InitState() { sequence?.Kill(); SetObjState(initLocalPosition, initRotateAngle); } public override void FinishedState() { sequence?.Kill(); SetObjState(targetLocalPosition, targetRotateAngle); } public override void StartPlay(Action finishedCallBack = null) { sequence?.Kill(); sequence = DOTween.Sequence(); foreach (var item in moveObjs) { Tweener tw = item.transform.DOLocalMove(targetLocalPosition,duration).SetEase(Ease.Linear); Tweener tw1 = item.transform.DOLocalRotate(targetRotateAngle, duration,m_RotateMode).SetEase(Ease.Linear); sequence.Join(tw); sequence.Join(tw1); } sequence.OnComplete(() => { finishedCallBack?.Invoke(); }); sequence.Play(); } private void SetObjState(Vector3 _targetPosition, Vector3 _targetRotateAngle) { foreach (var item in moveObjs) { item.localPosition = _targetPosition; item.localEulerAngles = _targetRotateAngle; } } }