namespace Zinnia.Utility { using UnityEngine; using Zinnia.Extension; /// /// Scrubs through an animation timeline to a specific normalized point along the timeline. /// public class AnimatorScrubber : MonoBehaviour { [Tooltip("The Animator to scrub.")] [SerializeField] private Animator timeline; /// /// The to scrub. /// public Animator Timeline { get { return timeline; } set { timeline = value; timeline.speed = 0; } } [Tooltip("The name of the Animation to scrub.")] [SerializeField] private string animationName; /// /// The name of the to scrub. /// public string AnimationName { get { return animationName; } set { animationName = value; } } /// /// Scrubs through the to the given value. /// /// The normalized position to scrub to. public virtual void Scrub(float value) { if (!CanScrub()) { return; } Timeline.speed = 0; Timeline.Play(AnimationName, -1, value); } protected virtual void OnEnable() { if (Timeline != null) { Timeline.speed = 0; } } /// /// Determines whether the timeline can be scrubbed. /// /// Whether the timeline can be scrubbed. protected virtual bool CanScrub() { return this.IsValidState() && Timeline != null && !string.IsNullOrEmpty(AnimationName); } } }