IsStopped.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using UnityEngine;
  2. using UnityEngine.AI;
  3. namespace BehaviorDesigner.Runtime.Tasks.Unity.UnityNavMeshAgent
  4. {
  5. [TaskCategory("Unity/NavMeshAgent")]
  6. [TaskDescription("Is the agent stopped?")]
  7. public class IsStopped : Conditional
  8. {
  9. [Tooltip("The GameObject that the task operates on. If null the task GameObject is used.")]
  10. public SharedGameObject targetGameObject;
  11. // cache the navmeshagent component
  12. private NavMeshAgent navMeshAgent;
  13. private GameObject prevGameObject;
  14. public override void OnStart()
  15. {
  16. var currentGameObject = GetDefaultGameObject(targetGameObject.Value);
  17. if (currentGameObject != prevGameObject) {
  18. navMeshAgent = currentGameObject.GetComponent<NavMeshAgent>();
  19. prevGameObject = currentGameObject;
  20. }
  21. }
  22. public override TaskStatus OnUpdate()
  23. {
  24. if (navMeshAgent == null) {
  25. Debug.LogWarning("NavMeshAgent is null");
  26. return TaskStatus.Failure;
  27. }
  28. return navMeshAgent.isStopped ? TaskStatus.Success : TaskStatus.Failure;
  29. }
  30. public override void OnReset()
  31. {
  32. targetGameObject = null;
  33. }
  34. }
  35. }