Schedule.cs 980 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #if CHRONOS_PLAYMAKER
  2. using HutongGames.PlayMaker;
  3. namespace Chronos.PlayMaker
  4. {
  5. [ActionCategory("Chronos")]
  6. [Tooltip("Schedules an event at a specific delay on a timeline. If no event is specified, FINISHED will be used.")]
  7. [HelpUrl("http://ludiq.io/chronos/documentation#Timeline.Schedule")]
  8. public class Schedule : ChronosComponentAction<Timeline>
  9. {
  10. [RequiredField]
  11. [CheckForComponent(typeof(Timeline))]
  12. public FsmOwnerDefault gameObject;
  13. [RequiredField]
  14. public FsmFloat delay;
  15. [Title("Event")]
  16. public FsmEvent scheduledEvent;
  17. public override void Reset()
  18. {
  19. gameObject = null;
  20. delay = 1f;
  21. scheduledEvent = null;
  22. }
  23. public override void OnEnter()
  24. {
  25. if (!UpdateCache(Fsm.GetOwnerDefaultTarget(gameObject))) return;
  26. timeline.Schedule(timeline.time + delay.Value, delegate
  27. {
  28. if (!FsmEvent.IsNullOrEmpty(scheduledEvent))
  29. {
  30. Fsm.Event(scheduledEvent);
  31. }
  32. else
  33. {
  34. Finish();
  35. }
  36. });
  37. }
  38. }
  39. }
  40. #endif