You've already forked taptap2024_GJ_chidouren
49 lines
1.4 KiB
C#
49 lines
1.4 KiB
C#
using Game.Component.Map;
|
|
using UnityEngine;
|
|
|
|
namespace Game.Component.FsmMonoData
|
|
{
|
|
public class WalkPathGroup : MonoBehaviour
|
|
{
|
|
[SerializeField] private MovePathGroup PathGroup;
|
|
|
|
private int _curIndex;
|
|
|
|
public Vector2 CurTarget { get; private set; }
|
|
|
|
public void InitTarget (Vector2 actorPos)
|
|
{
|
|
//根据角色当前位置,寻找最近的节点
|
|
_curIndex = 0;
|
|
CurTarget = this.PathGroup.PathList[0].position;
|
|
for (int i = 1; i < this.PathGroup.PathList.Count; i++)
|
|
{
|
|
if (Vector2.Distance (actorPos , this.PathGroup.PathList[i].position) < Vector2.Distance (actorPos , CurTarget))
|
|
{
|
|
_curIndex = i;
|
|
CurTarget = this.PathGroup.PathList[i].position;
|
|
}
|
|
}
|
|
}
|
|
|
|
public bool CheckNextNode (Vector2 actorPos)
|
|
{
|
|
if (Vector2.Distance (actorPos , CurTarget) < 0.1f)
|
|
{
|
|
NextNode ();
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
private void NextNode ()
|
|
{
|
|
_curIndex++;
|
|
if (this._curIndex >= this.PathGroup.PathList.Count)
|
|
{
|
|
_curIndex = 0;
|
|
}
|
|
CurTarget = this.PathGroup.PathList[_curIndex].position;
|
|
}
|
|
}
|
|
} |