Pause.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #if UNITY_2017_1_OR_NEWER
  2. using UnityEngine;
  3. using UnityEngine.Playables;
  4. namespace BehaviorDesigner.Runtime.Tasks.Unity.Timeline
  5. {
  6. [TaskCategory("Unity/Timeline")]
  7. [TaskDescription("Pauses playback of the currently running playable.")]
  8. public class Pause : Action
  9. {
  10. [Tooltip("The GameObject that the task operates on. If null the task GameObject is used.")]
  11. public SharedGameObject targetGameObject;
  12. private PlayableDirector playableDirector;
  13. private GameObject prevGameObject;
  14. public override void OnStart()
  15. {
  16. var currentGameObject = GetDefaultGameObject(targetGameObject.Value);
  17. if (currentGameObject != prevGameObject) {
  18. playableDirector = currentGameObject.GetComponent<PlayableDirector>();
  19. prevGameObject = currentGameObject;
  20. }
  21. }
  22. public override TaskStatus OnUpdate()
  23. {
  24. if (playableDirector == null) {
  25. Debug.LogWarning("PlayableDirector is null");
  26. return TaskStatus.Failure;
  27. }
  28. playableDirector.Pause();
  29. return TaskStatus.Success;
  30. }
  31. public override void OnReset()
  32. {
  33. targetGameObject = null;
  34. }
  35. }
  36. }
  37. #endif