You've already forked taptap2024_GJ_chidouren
完成4种基础ai
This commit is contained in:
49
Assets/Scripts/Game/Component/FsmMonoData/WalkPathGroup.cs
Normal file
49
Assets/Scripts/Game/Component/FsmMonoData/WalkPathGroup.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user