This commit is contained in:
PC-20230316NUNE\Administrator
2024-02-02 15:38:13 +08:00
parent 877dca3b43
commit 00f56e11c7
228 changed files with 36944 additions and 20084 deletions

View File

@@ -18,22 +18,38 @@ namespace Pathfinding {
public Transform target;
IAstarAI ai;
void OnEnable () {
public Vector3 pos;
void OnEnable ()
{
this.pos = this.transform.position;
ai = GetComponent<IAstarAI>();
// Update the destination right before searching for a path as well.
// This is enough in theory, but this script will also update the destination every
// frame as the destination is used for debugging and may be used for other things by other
// scripts as well. So it makes sense that it is up to date every frame.
if (ai != null) ai.onSearchPath += Update;
if (ai != null) ai.onSearchPath += OnUpdate;
}
void OnDisable () {
if (ai != null) ai.onSearchPath -= Update;
if (ai != null) ai.onSearchPath -= OnUpdate;
}
/// <summary>Updates the AI's destination every frame</summary>
void Update () {
if (target != null && ai != null) ai.destination = target.position;
public override void OnSyncUpdate(int dt, JNFrameInfo frame, Object input)
{
base.OnSyncUpdate(dt, frame, input);
this.OnUpdate();
}
public void SetTarget(Vector3 pos)
{
this.pos = pos;
}
public void OnUpdate()
{
if (ai != null) ai.destination = pos;
}
}
}