GetBaseSpeed.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #if CHRONOS_PLAYMAKER
  2. using HutongGames.PlayMaker;
  3. namespace Chronos.PlayMaker
  4. {
  5. [ActionCategory("Chronos")]
  6. [Tooltip("Gets a base speed used by a timeline.")]
  7. [HelpUrl("http://ludiq.io/chronos/documentation#Timeline")]
  8. public class GetBaseSpeed : ChronosComponentAction<Timeline>
  9. {
  10. public enum Speed
  11. {
  12. Animator,
  13. Animation,
  14. Particle,
  15. Audio,
  16. Navigation,
  17. NavigationAngular
  18. }
  19. [RequiredField]
  20. [CheckForComponent(typeof(Timeline))]
  21. public FsmOwnerDefault gameObject;
  22. public Speed getSpeed;
  23. [RequiredField]
  24. [UIHint(UIHint.Variable)]
  25. public FsmFloat storeValue;
  26. public bool everyFrame;
  27. public override void Reset()
  28. {
  29. gameObject = null;
  30. getSpeed = Speed.Animator;
  31. storeValue = null;
  32. everyFrame = false;
  33. }
  34. public override void OnEnter()
  35. {
  36. DoAction();
  37. if (!everyFrame)
  38. {
  39. Finish();
  40. }
  41. }
  42. public override void OnUpdate()
  43. {
  44. DoAction();
  45. }
  46. private void DoAction()
  47. {
  48. if (!UpdateCache(Fsm.GetOwnerDefaultTarget(gameObject))) return;
  49. switch (getSpeed)
  50. {
  51. case Speed.Animator:
  52. storeValue.Value = timeline.animator.speed;
  53. break;
  54. case Speed.Animation:
  55. storeValue.Value = timeline.animation.speed;
  56. break;
  57. case Speed.Particle:
  58. storeValue.Value = timeline.particleSystem.playbackSpeed;
  59. break;
  60. case Speed.Audio:
  61. storeValue.Value = timeline.audioSource.pitch;
  62. break;
  63. case Speed.Navigation:
  64. storeValue.Value = timeline.navMeshAgent.speed;
  65. break;
  66. case Speed.NavigationAngular:
  67. storeValue.Value = timeline.navMeshAgent.angularSpeed;
  68. break;
  69. default:
  70. storeValue.Value = 0f;
  71. break;
  72. }
  73. }
  74. }
  75. }
  76. #endif