1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- #if UNITY_2017_1_OR_NEWER
- using UnityEngine;
- using UnityEngine.Playables;
- namespace BehaviorDesigner.Runtime.Tasks.Unity.Timeline
- {
- [TaskCategory("Unity/Timeline")]
- [TaskDescription("Pauses playback of the currently running playable.")]
- public class Pause : Action
- {
- [Tooltip("The GameObject that the task operates on. If null the task GameObject is used.")]
- public SharedGameObject targetGameObject;
- private PlayableDirector playableDirector;
- private GameObject prevGameObject;
- public override void OnStart()
- {
- var currentGameObject = GetDefaultGameObject(targetGameObject.Value);
- if (currentGameObject != prevGameObject) {
- playableDirector = currentGameObject.GetComponent<PlayableDirector>();
- prevGameObject = currentGameObject;
- }
- }
- public override TaskStatus OnUpdate()
- {
- if (playableDirector == null) {
- Debug.LogWarning("PlayableDirector is null");
- return TaskStatus.Failure;
- }
- playableDirector.Pause();
- return TaskStatus.Success;
- }
- public override void OnReset()
- {
- targetGameObject = null;
- }
- }
- }
- #endif
|