GetSpeed2d.cs 966 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #if CHRONOS_PLAYMAKER
  2. using HutongGames.PlayMaker;
  3. namespace Chronos.PlayMaker
  4. {
  5. [ActionCategory("Physics 2d (Chronos)")]
  6. [Tooltip("Gets the 2d Speed of a Game Object and stores it in a Float Variable. NOTE: The Game Object must have a rigid body 2D.")]
  7. public class GetSpeed2d : ChronosComponentAction<Timeline>
  8. {
  9. [RequiredField]
  10. [CheckForComponent(typeof(Timeline))]
  11. public FsmOwnerDefault gameObject;
  12. [RequiredField]
  13. [UIHint(UIHint.Variable)]
  14. public FsmFloat storeResult;
  15. public bool everyFrame;
  16. public override void Reset()
  17. {
  18. gameObject = null;
  19. storeResult = null;
  20. everyFrame = false;
  21. }
  22. public override void OnEnter()
  23. {
  24. DoGetSpeed();
  25. if (!everyFrame)
  26. Finish();
  27. }
  28. public override void OnUpdate()
  29. {
  30. DoGetSpeed();
  31. }
  32. private void DoGetSpeed()
  33. {
  34. if (!UpdateCache(Fsm.GetOwnerDefaultTarget(gameObject))) return;
  35. storeResult.Value = timeline.rigidbody2D.velocity.magnitude;
  36. }
  37. }
  38. }
  39. #endif