GetIsKinematic.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using UnityEngine;
  2. namespace BehaviorDesigner.Runtime.Tasks.Unity.UnityRigidbody2D
  3. {
  4. [TaskCategory("Unity/Rigidbody2D")]
  5. [TaskDescription("Stores the is kinematic value of the Rigidbody2D. Returns Success.")]
  6. public class GetIsKinematic : Action
  7. {
  8. [Tooltip("The GameObject that the task operates on. If null the task GameObject is used.")]
  9. public SharedGameObject targetGameObject;
  10. [Tooltip("The is kinematic value of the Rigidbody2D")]
  11. [RequiredField]
  12. public SharedBool storeValue;
  13. private Rigidbody2D rigidbody2D;
  14. private GameObject prevGameObject;
  15. public override void OnStart()
  16. {
  17. var currentGameObject = GetDefaultGameObject(targetGameObject.Value);
  18. if (currentGameObject != prevGameObject) {
  19. rigidbody2D = currentGameObject.GetComponent<Rigidbody2D>();
  20. prevGameObject = currentGameObject;
  21. }
  22. }
  23. public override TaskStatus OnUpdate()
  24. {
  25. if (rigidbody2D == null) {
  26. Debug.LogWarning("Rigidbody2D is null");
  27. return TaskStatus.Failure;
  28. }
  29. storeValue.Value = rigidbody2D.isKinematic;
  30. return TaskStatus.Success;
  31. }
  32. public override void OnReset()
  33. {
  34. targetGameObject = null;
  35. storeValue = false;
  36. }
  37. }
  38. }