1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- using ChivaXR;
- using Sirenix.OdinInspector;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Text;
- #if UNITY_EDITOR
- using UnityEditor;
- #endif
- using UnityEngine;
- public class AniDriver_SimpleMoveRot : AnimationDriverBase
- {
- [HorizontalGroup("AniGroup")]
- public SimpleMoveItem mSimpleMoveItem;
- #if UNITY_EDITOR
- [HorizontalGroup("AniGroup")]
- [Button("选中MovePathItem")]
- public void SelectMovePathItem()
- {
- if (mSimpleMoveItem != null)
- {
- Selection.activeObject = mSimpleMoveItem.gameObject;
- }
- }
- #endif
- [Header("反向播放")]
- public bool reverse = false;
- public override void FinishedState()
- {
- mSimpleMoveItem.SetFinishedState(reverse);
- }
- public override void InitState()
- {
- mSimpleMoveItem.SetInitState(reverse);
- }
- public override void StartPlay(Action finishedCallBack = null)
- {
- StartAniCoroutine(MovePathByItem(mSimpleMoveItem, reverse, finishedCallBack));
- }
- /// <summary>
- /// 根据路径点移动
- /// </summary>
- /// <param name="points"></param>
- /// <param name="moveObj"></param>
- /// <param name="moveSpeed"></param>
- /// <param name="rotateSpeed"></param>
- /// <returns></returns>
- IEnumerator MovePathByItem(SimpleMoveItem movePathItem, bool isReverse, Action finishedCallBack = null)
- {
- float timer = 0;
- float lerp = 0;
- while (timer < movePathItem.duration)
- {
- lerp = reverse ? (1 - timer / movePathItem.duration) : timer / movePathItem.duration;
- foreach (var item in movePathItem.moveObjs)
- {
- item.Key.transform.position = Vector3.Lerp(item.Value.position, item.Value.position + item.Value.TransformDirection(movePathItem.localMovePos), lerp);
- item.Key.transform.rotation = item.Value.rotation;
- item.Key.transform.RotateAround(item.Value.position, item.Value.TransformDirection(movePathItem.localMovePos), movePathItem.rotAngle * lerp);
- }
- timer += Time.deltaTime;
- yield return new WaitForEndOfFrame();
- }
- movePathItem.SetFinishedState(isReverse);
- Debug.Log("MoveEnd is true");
- finishedCallBack?.Invoke();
- }
- public override string AnimationDescription()
- {
- return animationSequence.ToString() + "--移动物体:" + mSimpleMoveItem.name;
- }
- }
|