using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using ChivaXR;
using System;
public class AniDriver_MoveByPathItem : AnimationDriverBase
{
public MovePathItem mMovePathItem;
[Header("反向播放")]
public bool reverse = false;
public override void FinishedState()
{
mMovePathItem.SetFinishedState(reverse);
}
public override void InitState()
{
mMovePathItem.SetInitState(reverse);
}
public override void StartPlay(Action finishedCallBack = null)
{
StartAniCoroutine(MovePathByItem(mMovePathItem, reverse, finishedCallBack));
}
///
/// 根据路径点移动
///
///
///
///
///
///
IEnumerator MovePathByItem(MovePathItem movePathItem, bool isReverse, Action finishedCallBack = null)
{
List points = movePathItem.GetMovePathPoints(isReverse);
yield return new WaitForSeconds(movePathItem.waitTime);
for (int i = 0; i < points.Count; i++)
{
bool moveToTarget = false;
while (!moveToTarget)
{
movePathItem.moveTarget.transform.position = Vector3.MoveTowards(movePathItem.moveTarget.transform.position, points[i].position, movePathItem.moveSpeed * Time.deltaTime);
movePathItem.moveTarget.transform.rotation = Quaternion.Lerp(movePathItem.moveTarget.transform.rotation, points[i].rotation, movePathItem.rotateSpeed * Time.deltaTime);
if (Vector3.Distance(movePathItem.moveTarget.transform.position, points[i].position) < 0.02f && Quaternion.Angle(movePathItem.moveTarget.transform.rotation, points[i].rotation) < 5)
{
movePathItem.moveTarget.transform.position = points[i].position;
movePathItem.moveTarget.transform.rotation = points[i].rotation;
moveToTarget = true;
}
yield return new WaitForEndOfFrame();
}
}
Debug.Log("MoveEnd is true");
finishedCallBack?.Invoke();
}
}