// Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2026 Kybernetik // using System; using System.Collections.Generic; using UnityEngine; namespace Animancer { /// A [] wrapper around an . /// /// This allows Transition Assets to be referenced inside [] /// fields which can't directly reference s. /// /// Documentation: /// /// Transition Assets /// /// https://kybernetik.com.au/animancer/api/Animancer/TransitionAssetReference [Serializable] public class TransitionAssetReference : IAnimationClipSource, ICloneable, ICopyable, IPolymorphic, ITransition, IWrapper { /************************************************************************************************************************/ [SerializeField] private TransitionAssetBase _Asset; /// [] The wrapped Transition Asset. public ref TransitionAssetBase Asset => ref _Asset; /************************************************************************************************************************/ /// Creates a new . public TransitionAssetReference() { } /// Creates a new . public TransitionAssetReference(TransitionAssetBase asset) { _Asset = asset; } /************************************************************************************************************************/ /// object IWrapper.WrappedObject => _Asset; /************************************************************************************************************************/ /// Can this transition create a valid ? public virtual bool IsValid => _Asset.IsValid(); /// public virtual float FadeDuration => _Asset != null ? _Asset.FadeDuration : 0; /// public virtual object Key => _Asset != null ? _Asset.Key : null; /// public virtual FadeMode FadeMode => _Asset != null ? _Asset.FadeMode : default; /// public bool IsLooping => _Asset != null && _Asset.IsLooping; /// public float NormalizedStartTime { get => _Asset != null ? _Asset.NormalizedStartTime : float.NaN; set => _Asset.NormalizedStartTime = value;// No null check. Don't silently ignore commands. } /// public float MaximumLength => _Asset != null ? _Asset.MaximumLength : 0; /// public float Speed { get => _Asset != null ? _Asset.Speed : 1; set => _Asset.Speed = value;// No null check. Don't silently ignore commands. } /************************************************************************************************************************/ /// [Obsolete(TransitionAssetBase.ObsoleteEventsMessage)] public AnimancerEvent.Sequence Events => _Asset != null ? _Asset.Events : null; /// [Obsolete(TransitionAssetBase.ObsoleteEventsMessage)] public AnimancerEvent.Sequence.Serializable SerializedEvents { get => _Asset.SerializedEvents; set => _Asset.SerializedEvents = value; } /************************************************************************************************************************/ /// public virtual AnimancerState CreateState() => _Asset.CreateState(); /// public virtual void Apply(AnimancerState state) => _Asset.Apply(state); /************************************************************************************************************************/ /// [] /// Calls . /// public virtual void GetAnimationClips(List clips) => clips.GatherFromSource(_Asset); /************************************************************************************************************************/ /// public virtual TransitionAssetReference Clone(CloneContext context) { var clone = new TransitionAssetReference(); clone.CopyFrom(this, context); return clone; } /// public void CopyFrom(TransitionAssetReference copyFrom, CloneContext context) { _Asset = context.GetCloneOrOriginal(copyFrom._Asset); } /************************************************************************************************************************/ /// Describes the . public override string ToString() => $"{nameof(TransitionAssetReference)}({_Asset})"; /************************************************************************************************************************/ } }