GetIsStopped.cs 1.4 KB

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