// Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2024 Kybernetik // using UnityEngine.Playables; namespace Animancer { /// A utility for re-assigning Animancer's . /// /// /// This should be totally useless, but for some reason it seems to fix an issue with Unity's /// Animation Rigging package. Normally, all of the Rig's parameters get reset to their /// starting values any time a playable is connected or disconnected (which Animancer does frequently), /// but using this utility effectively re-captures the starting values /// so any subsequent resets retain the values you set. /// /// Example: /// /// public class PlayableOutputRefresherExample : MonoBehaviour /// { /// [SerializeField] private AnimancerComponent _Animancer; /// [SerializeField] private Rig _Rig; /// /// // A field to store it in. /// private PlayableOutputRefresher _OutputRefresher; /// /// protected virtual void OnEnable() /// { /// // Initialize on startup. /// _OutputRefresher = new(_Animancer); /// } /// /// public void SetWeight(float weight) /// { /// // Change something that would be reset. /// _Rig.weight = weight; /// /// // Then call this afterwards. /// _OutputRefresher.Refresh(); /// } /// } /// /// /// https://kybernetik.com.au/animancer/api/Animancer/PlayableOutputRefresher /// public struct PlayableOutputRefresher { /************************************************************************************************************************/ /// The of Animancer's . public PlayableOutput Output { get; set; } /// The root of Animancer's . public Playable Root { get; set; } /************************************************************************************************************************/ /// Creates a new . public PlayableOutputRefresher(PlayableOutput output) { Output = output; Root = Output.GetSourcePlayable(); } /************************************************************************************************************************/ /// Creates a new . public PlayableOutputRefresher(AnimancerGraph animancer) : this(animancer.Output) { } /************************************************************************************************************************/ /// Re-assigns the as the source playable of the . public readonly void Refresh() => Output.SetSourcePlayable(Root); /************************************************************************************************************************/ /// Re-acquires the from the . /// Call this after . public void OnSourcePlayableChanged() => Root = Output.GetSourcePlayable(); /************************************************************************************************************************/ } }