This commit is contained in:
CortexCore
2023-12-16 23:30:08 +08:00
parent 78216a3d47
commit 961ae8feb4
33 changed files with 369 additions and 148 deletions

View File

@@ -15,6 +15,7 @@ namespace NodeCanvas.Tasks.Actions
public BBParameter<GameObject> target;
public BBParameter<float> speed = 4;
public BBParameter<float> keepDistance = 0.1f;
public BBParameter<bool> waitUntilFinish = false;
private Vector3? lastRequest;
@@ -29,16 +30,21 @@ namespace NodeCanvas.Tasks.Actions
EndAction(true);
return;
}
}
protected override void OnUpdate() {
if ( target.value == null ) { EndAction(false); return; }
var pos = target.value.transform.position;
if ( lastRequest != pos ) {
if ( !agent.SetDestination(pos) ) {
if (lastRequest != pos)
{
if (!agent.SetDestination(pos))
{
EndAction(false);
return;
}
if (waitUntilFinish.value == false)
EndAction(true);
}
lastRequest = pos;
@@ -46,11 +52,13 @@ namespace NodeCanvas.Tasks.Actions
if ( !agent.pathPending && agent.remainingDistance <= agent.stoppingDistance + keepDistance.value ) {
EndAction(true);
}
}
protected override void OnPause() { OnStop(); }
protected override void OnStop() {
if ( agent.gameObject.activeSelf ) {
if ( agent.gameObject.activeSelf && agent.isOnNavMesh && waitUntilFinish.value) {
agent.ResetPath();
}
lastRequest = null;