GetAngularDrag.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using UnityEngine;
  2. namespace BehaviorDesigner.Runtime.Tasks.Unity.UnityRigidbody
  3. {
  4. [TaskCategory("Unity/Rigidbody")]
  5. [TaskDescription("Stores the angular drag of the Rigidbody. Returns Success.")]
  6. public class GetAngularDrag : 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 angular drag of the Rigidbody")]
  11. [RequiredField]
  12. public SharedFloat storeValue;
  13. // cache the rigidbody component
  14. private Rigidbody rigidbody;
  15. private GameObject prevGameObject;
  16. public override void OnStart()
  17. {
  18. var currentGameObject = GetDefaultGameObject(targetGameObject.Value);
  19. if (currentGameObject != prevGameObject) {
  20. rigidbody = currentGameObject.GetComponent<Rigidbody>();
  21. prevGameObject = currentGameObject;
  22. }
  23. }
  24. public override TaskStatus OnUpdate()
  25. {
  26. if (rigidbody == null) {
  27. Debug.LogWarning("Rigidbody is null");
  28. return TaskStatus.Failure;
  29. }
  30. storeValue.Value = rigidbody.angularDrag;
  31. return TaskStatus.Success;
  32. }
  33. public override void OnReset()
  34. {
  35. targetGameObject = null;
  36. storeValue = 0;
  37. }
  38. }
  39. }