WakeUp.cs 1.2 KB

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