// Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2026 Kybernetik //
using System;
using System.Collections.Generic;
using UnityEngine;
namespace Animancer
{
/// A based .
///
/// Documentation:
///
/// Transition Assets
///
/// When adding a to any derived classes, you can use
/// and .
///
/// https://kybernetik.com.au/animancer/api/Animancer/TransitionAssetBase
[AnimancerHelpUrl(typeof(TransitionAssetBase))]
public abstract partial class TransitionAssetBase : ScriptableObject,
IAnimationClipSource,
ITransition,
IWrapper
{
/************************************************************************************************************************/
/// The name of the serialized backing field of .
public const string TransitionField = "_Transition";
/************************************************************************************************************************/
/// Returns the wrapped by this .
public abstract ITransition GetTransition();
///
object IWrapper.WrappedObject
=> this != null
? GetTransition()
: null;
/************************************************************************************************************************/
///
public virtual float FadeDuration
=> GetTransition().FadeDuration;
///
public virtual object Key
=> GetTransition().Key;
///
public virtual FadeMode FadeMode
=> GetTransition().FadeMode;
///
public virtual AnimancerState CreateState()
=> GetTransition().CreateState();
///
public virtual void Apply(AnimancerState state)
{
GetTransition().Apply(state);
state.SetDebugName(this);
}
/************************************************************************************************************************/
/// Can this transition create a valid ?
///
/// Use
/// to also null check this reference, i.e: transition.IsValid().
///
public virtual bool IsValid
=> this != null
&& GetTransition().IsValid();
///
public bool IsLooping
=> GetTransition().IsLooping;
///
public float NormalizedStartTime
{
get => GetTransition().NormalizedStartTime;
set => GetTransition().NormalizedStartTime = value;
}
///
public float MaximumLength
=> GetTransition().MaximumLength;
///
public float Speed
{
get => GetTransition().Speed;
set => GetTransition().Speed = value;
}
/************************************************************************************************************************/
/// Explains why Transition Assets warn about accessing their events.
public const string ObsoleteEventsMessage =
"Directly accessing the Events of a Transition Asset is generally not recommended" +
" because any modifications will affect all characters who share the same asset" +
" and will persist until the asset is destroyed (usually when the application exits)." +
"\n\n" +
"In most cases, the recommended approach is to initialize events on the " + nameof(AnimancerState) +
" returned when you Play the Transition rather than modifying the Asset itself." +
"\n\n" +
"If you really need to access these events, you can use the asset.Transition.Events.";
///
[Obsolete(ObsoleteEventsMessage)]
public AnimancerEvent.Sequence Events
=> GetTransition().Events;
///
[Obsolete(ObsoleteEventsMessage)]
public AnimancerEvent.Sequence.Serializable SerializedEvents
{
get => GetTransition().SerializedEvents;
set => GetTransition().SerializedEvents = value;
}
/************************************************************************************************************************/
/// []
/// Calls .
///
public virtual void GetAnimationClips(List clips)
=> clips.GatherFromSource(GetTransition());
/************************************************************************************************************************/
#if UNITY_EDITOR
/************************************************************************************************************************/
/// [Editor-Only] Creates an instance of the main non-abstract inheritor of this class.
/// TransitionAsset sets this to use itself by default.
public static new Func CreateInstance { get; set; }
/************************************************************************************************************************/
private const string CreateFromSelectionMenu = Strings.CreateMenuPrefix + "Transition Assets From Selection";
[UnityEditor.MenuItem(
itemName: CreateFromSelectionMenu,
validate = true)]
private static bool ValidateCreateFromSelection()
{
var selection = UnityEditor.Selection.objects;
foreach (var item in selection)
if (TryCreateTransitionAttribute.CanCreateAndSave(item))
return true;
return false;
}
[UnityEditor.MenuItem(
itemName: CreateFromSelectionMenu,
priority = Strings.AssetMenuOrder + 2)]
private static void CreateFromSelection()
{
var selection = UnityEditor.Selection.objects;
foreach (var item in selection)
TryCreateTransitionAttribute.TryCreateTransitionAsset(item, true);
}
/************************************************************************************************************************/
#endif
/************************************************************************************************************************/
}
}