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));
}
///
/// 根据路径点移动
///
///
///
///
///
///
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;
}
}