GetTimelineInfo.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #if CHRONOS_PLAYMAKER
  2. using HutongGames.PlayMaker;
  3. namespace Chronos.PlayMaker
  4. {
  5. [ActionCategory("Chronos")]
  6. [Tooltip("Gets various useful time measurements from a timeline.")]
  7. [HelpUrl("http://ludiq.io/chronos/documentation#Timeline")]
  8. public class GetTimelineInfo : ChronosComponentAction<Timeline>
  9. {
  10. public enum TimeInfo
  11. {
  12. DeltaTime,
  13. FixedDeltaTime,
  14. SmoothDeltaTime,
  15. TimeScale,
  16. Time,
  17. UnscaledTime,
  18. TimeInCurrentState,
  19. }
  20. [RequiredField]
  21. [CheckForComponent(typeof(Timeline))]
  22. public FsmOwnerDefault gameObject;
  23. public TimeInfo getInfo;
  24. [RequiredField]
  25. [UIHint(UIHint.Variable)]
  26. public FsmFloat storeValue;
  27. public bool everyFrame;
  28. public override void Reset()
  29. {
  30. gameObject = null;
  31. getInfo = TimeInfo.DeltaTime;
  32. storeValue = null;
  33. everyFrame = false;
  34. }
  35. public override void OnEnter()
  36. {
  37. DoAction();
  38. if (!everyFrame)
  39. {
  40. Finish();
  41. }
  42. }
  43. public override void OnUpdate()
  44. {
  45. DoAction();
  46. }
  47. private void DoAction()
  48. {
  49. if (!UpdateCache(Fsm.GetOwnerDefaultTarget(gameObject))) return;
  50. switch (getInfo)
  51. {
  52. case TimeInfo.DeltaTime:
  53. storeValue.Value = timeline.deltaTime;
  54. break;
  55. case TimeInfo.FixedDeltaTime:
  56. storeValue.Value = timeline.fixedDeltaTime;
  57. break;
  58. case TimeInfo.SmoothDeltaTime:
  59. storeValue.Value = timeline.smoothDeltaTime;
  60. break;
  61. case TimeInfo.TimeScale:
  62. storeValue.Value = timeline.timeScale;
  63. break;
  64. case TimeInfo.Time:
  65. storeValue.Value = timeline.time;
  66. break;
  67. case TimeInfo.UnscaledTime:
  68. storeValue.Value = timeline.unscaledTime;
  69. break;
  70. case TimeInfo.TimeInCurrentState:
  71. storeValue.Value = timeline.time - State.RealStartTime;
  72. break;
  73. default:
  74. storeValue.Value = 0f;
  75. break;
  76. }
  77. }
  78. }
  79. }
  80. #endif