Files
2026-02-21 16:45:37 +08:00

63 lines
1.2 KiB
C#

using UnityEngine;
using UnityEngine.AI;
namespace BehaviorDesigner.Runtime.Tasks.Movement
{
public abstract class NavMeshMovement : Movement
{
[Tooltip("The speed of the agent")]
public SharedFloat speed = 10f;
[Tooltip("The angular speed of the agent")]
public SharedFloat angularSpeed = 120f;
private NavMeshAgent navMeshAgent;
public override void OnAwake()
{
navMeshAgent = gameObject.GetComponent<NavMeshAgent>();
}
public override void OnStart()
{
navMeshAgent.speed = speed.Value;
navMeshAgent.angularSpeed = angularSpeed.Value;
navMeshAgent.Resume();
}
protected override bool SetDestination(Vector3 target)
{
if (navMeshAgent.destination == target)
{
return true;
}
if (navMeshAgent.SetDestination(target))
{
return true;
}
return false;
}
protected override bool HasArrived()
{
return !navMeshAgent.pathPending && navMeshAgent.remainingDistance <= navMeshAgent.stoppingDistance + 0.001f;
}
protected override Vector3 Velocity()
{
return navMeshAgent.velocity;
}
public override void OnEnd()
{
navMeshAgent.Stop();
}
public override void OnReset()
{
speed = 10f;
angularSpeed = 120f;
}
}
}