using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices.WindowsRuntime;
using DG.Tweening;
using DG.Tweening.Plugins.Core.PathCore;
using UnityEngine;
public class DomoveSimpleScript : MonoBehaviour
{
//public Ease m_MoveType = Ease.Linear;
public float m_Speed = 5f;
public float m_CheckTime = 1f;
private List<Vector3> m_PointList;
private Action mf_Complete;
void Awake()
{
if (m_PointList==null)
{
m_PointList=new List<Vector3>();
}
}
//将所需的路径点信息添加
public void AddWayPoint(Vector3 V)
{
if (m_PointList==null)
{
m_PointList=new List<Vector3>();
}
m_PointList.Add(V);
}
//
public void DoMove(float Spd=1.0f,Action F=null,Action stepFunc=null,Ease moveType = Ease.Linear)
{
m_Speed = Spd;
//路径完成后的回调
mf_Complete = F;
if (m_PointList!=null)
{
var doAni= transform.DOPath(m_PointList.ToArray(), m_Speed);
doAni.SetEase(moveType);
//默认朝向
doAni.SetLookAt(0);
doAni.OnWaypointChange(
(s) =>
{
//Debug.LogError(s);
//单步完成后的回调
stepFunc();
});
doAni.OnComplete(OnComplete);
m_isStop = false;
}
}
public bool IsMoving()
{
return (!m_isStop);
}
private float Dtime = 0f;
private bool m_isStop = true;
private void Update()
{
if (m_isStop)
return;
Dtime += Time.deltaTime;
if (Dtime > m_CheckTime)
{
Dtime = 0;
}
}
void OnComplete()
{
m_isStop = true;
m_PointList.Clear();
if (mf_Complete!=null)
{
mf_Complete();
}
}
}
DoTweenPath的具体使用实例
猜你喜欢
转载自blog.csdn.net/osuckseed/article/details/108551936
今日推荐
周排行