SetDrag.cs 996 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #if CHRONOS_PLAYMAKER
  2. using HutongGames.PlayMaker;
  3. namespace Chronos.PlayMaker
  4. {
  5. [ActionCategory("Physics (Chronos)")]
  6. [HelpUrl("http://hutonggames.com/playmakerforum/index.php?topic=4734.0")]
  7. [Tooltip("Sets the Drag of a Game Object's Rigid Body.")]
  8. public class SetDrag : ChronosComponentAction<Timeline>
  9. {
  10. [RequiredField]
  11. [CheckForComponent(typeof(Timeline))]
  12. public FsmOwnerDefault gameObject;
  13. [RequiredField]
  14. [HasFloatSlider(0.0f, 10f)]
  15. public FsmFloat drag;
  16. [Tooltip("Repeat every frame. Typically this would be set to True.")]
  17. public bool everyFrame;
  18. public override void Reset()
  19. {
  20. gameObject = null;
  21. drag = 1;
  22. }
  23. public override void OnEnter()
  24. {
  25. DoSetDrag();
  26. if (!everyFrame)
  27. {
  28. Finish();
  29. }
  30. }
  31. public override void OnUpdate()
  32. {
  33. DoSetDrag();
  34. }
  35. private void DoSetDrag()
  36. {
  37. var go = Fsm.GetOwnerDefaultTarget(gameObject);
  38. if (UpdateCache(go))
  39. {
  40. timeline.rigidbody.drag = drag.Value;
  41. }
  42. }
  43. }
  44. }
  45. #endif