// Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2023 Kybernetik // using UnityEngine.Playables; namespace Animancer { /// https://kybernetik.com.au/animancer/api/Animancer/AnimancerState partial class AnimancerState { /// /// Uses to pause a . /// public class DelayedPause : Key, IUpdatable { /************************************************************************************************************************/ /// The . public AnimancerPlayable Root { get; set; } /// The state that will be paused. public AnimancerState State { get; set; } /************************************************************************************************************************/ /// /// Gets a from the and initializes it for the `state`. /// public static void Register(AnimancerState state) { var root = state.Root; if (root == null) return; var pause = ObjectPool.Acquire(); pause.Root = root; pause.State = state; root.RequirePostUpdate(pause); } /************************************************************************************************************************/ /// /// Pauses the if hasn't been set to true and returns this /// object to the . /// public void Update() { if (!State.IsPlaying) State._Playable.Pause(); Root.CancelPostUpdate(this); Root = null; State = null; ObjectPool.Release(this); } /************************************************************************************************************************/ } } }