This commit is contained in:
2025-08-18 09:22:24 +08:00
commit cef5623ab0
1333 changed files with 305844 additions and 0 deletions
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: cae3088bc435d2942827b0a25e688903
timeCreated: 1515048758
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,822 @@
// Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2024 Kybernetik //
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;
using UnityEngine;
using UnityEngine.Playables;
using Object = UnityEngine.Object;
namespace Animancer
{
/// <summary>Base class for <see cref="Playable"/> wrapper objects in an <see cref="AnimancerGraph"/>.</summary>
/// <remarks>This is the base class of <see cref="AnimancerLayer"/> and <see cref="AnimancerState"/>.</remarks>
/// https://kybernetik.com.au/animancer/api/Animancer/AnimancerNode
public abstract class AnimancerNode : AnimancerNodeBase,
ICopyable<AnimancerNode>,
IEnumerable<AnimancerState>,
IEnumerator,
IHasDescription
{
/************************************************************************************************************************/
#region Playable
/************************************************************************************************************************/
#if UNITY_EDITOR
/// <summary>[Editor-Only] [Internal] Indicates whether the Inspector details for this node are expanded.</summary>
internal bool _IsInspectorExpanded;
#endif
/************************************************************************************************************************/
/// <summary>Creates and assigns the <see cref="Playable"/> managed by this node.</summary>
/// <remarks>This method also applies the <see cref="AnimancerNodeBase.Speed"/> if it was set beforehand.</remarks>
protected virtual void CreatePlayable()
{
#if UNITY_ASSERTIONS
if (Graph == null)
{
MarkAsUsed(this);
throw new InvalidOperationException($"{nameof(AnimancerNode)}.{nameof(Graph)}" +
$" is null when attempting to create its {nameof(Playable)}: {this}" +
$"\nThe {nameof(Graph)} is generally set when you first play a state," +
$" so you probably just need to play it before trying to access it.");
}
if (_Playable.IsValid())
Debug.LogWarning($"{nameof(AnimancerNode)}.{nameof(CreatePlayable)}" +
$" was called before destroying the previous {nameof(Playable)}: {this}", Graph?.Component as Object);
#endif
CreatePlayable(out _Playable);
#if UNITY_ASSERTIONS
if (!_Playable.IsValid())
throw new InvalidOperationException(
$"{nameof(AnimancerNode)}.{nameof(CreatePlayable)}" +
$" did not create a valid {nameof(Playable)} for {this}");
#endif
if (Speed != 1)
_Playable.SetSpeed(Speed);
}
/// <summary>Creates and assigns the <see cref="Playable"/> managed by this node.</summary>
protected abstract void CreatePlayable(out Playable playable);
/************************************************************************************************************************/
/// <summary>Destroys the <see cref="Playable"/>.</summary>
public void DestroyPlayable()
{
if (_Playable.IsValid())
Graph._PlayableGraph.DestroyPlayable(_Playable);
}
/************************************************************************************************************************/
/// <summary>Calls <see cref="DestroyPlayable"/> and <see cref="CreatePlayable()"/>.</summary>
public virtual void RecreatePlayable()
{
DestroyPlayable();
CreatePlayable();
}
/// <summary>Calls <see cref="RecreatePlayable"/> on this node and all its children recursively.</summary>
public void RecreatePlayableRecursive()
{
RecreatePlayable();
for (int i = ChildCount - 1; i >= 0; i--)
GetChild(i)?.RecreatePlayableRecursive();
}
/************************************************************************************************************************/
/// <summary>Copies the details of `copyFrom` into this node, replacing its previous contents.</summary>
public virtual void CopyFrom(AnimancerNode copyFrom, CloneContext context)
{
SetWeight(copyFrom._Weight);
FadeGroup = context.WillCloneUpdatables
? null
: copyFrom.FadeGroup?.CloneForSingleTarget(copyFrom, this);
Speed = copyFrom.Speed;
CopyIKFlags(copyFrom);
#if UNITY_ASSERTIONS
DebugName = context.GetCloneOrOriginal(copyFrom.DebugName);
#endif
}
/************************************************************************************************************************/
#endregion
/************************************************************************************************************************/
#region Graph
/************************************************************************************************************************/
/// <summary>The index of the port this node is connected to on the parent's <see cref="Playable"/>.</summary>
/// <remarks>
/// A negative value indicates that it is not assigned to a port.
/// <para></para>
/// Indices are generally assigned starting from 0, ascending in the order they are connected to their layer.
/// They will not usually change unless the <see cref="AnimancerNodeBase.Parent"/> changes or another state on
/// the same layer is destroyed so the last state is swapped into its place to avoid shuffling everything down
/// to cover the gap.
/// <para></para>
/// The setter is internal so user defined states cannot set it incorrectly. Ideally,
/// <see cref="AnimancerLayer"/> should be able to set the port in its constructor and
/// <see cref="AnimancerState.SetParent"/> should also be able to set it, but classes that further inherit from
/// there should not be able to change it without properly calling that method.
/// </remarks>
public int Index { get; internal set; } = int.MinValue;
/************************************************************************************************************************/
/// <summary>Creates a new <see cref="AnimancerNode"/>.</summary>
protected AnimancerNode()
{
#if UNITY_ASSERTIONS
if (TraceConstructor)
_ConstructorStackTrace = new(true);
#endif
}
/************************************************************************************************************************/
#if UNITY_ASSERTIONS
/************************************************************************************************************************/
/// <summary>[Assert-Only]
/// Should a <see cref="System.Diagnostics.StackTrace"/> be captured in the constructor of all new nodes so
/// <see cref="OptionalWarning.UnusedNode"/> can include it in the warning if that node ends up being unused?
/// </summary>
/// <remarks>This has a notable performance cost so it should only be used when trying to identify a problem.</remarks>
public static bool TraceConstructor { get; set; }
/************************************************************************************************************************/
/// <summary>[Assert-Only]
/// The stack trace of the constructor (or null if <see cref="TraceConstructor"/> was false).
/// </summary>
private System.Diagnostics.StackTrace _ConstructorStackTrace;
/// <summary>[Assert-Only]
/// Returns the stack trace of the constructor (or null if <see cref="TraceConstructor"/> was false).
/// </summary>
public static System.Diagnostics.StackTrace GetConstructorStackTrace(AnimancerNode node)
=> node._ConstructorStackTrace;
/************************************************************************************************************************/
/// <summary>[Assert-Only] Checks <see cref="OptionalWarning.UnusedNode"/>.</summary>
~AnimancerNode()
{
if (Graph != null ||
Parent != null ||
OptionalWarning.UnusedNode.IsDisabled())
return;
// ToString might throw an exception since finalizers arn't run on the main thread.
string name = null;
try { name = ToString(); }
catch { name = GetType().FullName; }
var message = $"The {nameof(Graph)} of '{name}'" +
$" is null during finalization (garbage collection)." +
$" This may have been caused by earlier exceptions, but otherwise it probably means" +
$" that this node was never used for anything and should not have been created.";
if (_ConstructorStackTrace != null)
message += "\n\nThis node was created at:\n" + _ConstructorStackTrace;
else
message += $"\n\nEnable {nameof(AnimancerNode)}.{nameof(TraceConstructor)} on startup" +
$" to allow this warning to include the {nameof(System.Diagnostics.StackTrace)}" +
$" of when the node was constructed.";
OptionalWarning.UnusedNode.Log(message);
}
/************************************************************************************************************************/
#endif
/************************************************************************************************************************/
/// <summary>Connects the `child`'s <see cref="Playable"/> to this node.</summary>
/// <remarks>This method is NOT safe to call if the child was already connected.</remarks>
protected internal void ConnectChildUnsafe(int index, AnimancerNode child)
{
#if UNITY_ASSERTIONS
if (index < 0)
{
MarkAsUsed(this);
throw new InvalidOperationException(
$"Invalid {nameof(index)} when attempting to connect to its parent:" +
"\n• Child: " + child +
"\n• Parent: " + this);
}
Validate.AssertPlayable(child);
#endif
Graph._PlayableGraph.Connect(_Playable, child._Playable, index, child._Weight);
}
/// <summary>Disconnects the <see cref="Playable"/> of the child at the specified `index` from this node.</summary>
/// <remarks>This method is safe to call if the child was already disconnected.</remarks>
protected void DisconnectChildSafe(int index)
{
if (_Playable.GetInput(index).IsValid())
Graph._PlayableGraph.Disconnect(_Playable, index);
}
/************************************************************************************************************************/
// IEnumerator for yielding in a coroutine to wait until animations have stopped.
/************************************************************************************************************************/
/// <summary>Is this node playing and not yet at its end?</summary>
/// <remarks>
/// This method is called by <see cref="IEnumerator.MoveNext"/> so this object can be used as a custom yield
/// instruction to wait until it finishes.
/// </remarks>
public abstract bool IsPlayingAndNotEnding();
bool IEnumerator.MoveNext()
=> IsPlayingAndNotEnding();
object IEnumerator.Current
=> null;
void IEnumerator.Reset() { }
/************************************************************************************************************************/
#endregion
/************************************************************************************************************************/
#region Children
/************************************************************************************************************************/
/// <inheritdoc/>
protected internal override AnimancerNode GetChildNode(int index)
=> GetChild(index);
/// <summary>Returns the state connected to the specified `index` as a child of this node.</summary>
/// <remarks>When overriding, don't call this base method because it throws an exception.</remarks>
/// <exception cref="NotSupportedException">This node can't have children.</exception>
public virtual AnimancerState GetChild(int index)
{
MarkAsUsed(this);
throw new NotSupportedException(this + " can't have children.");
}
/// <summary>Called when a child is connected with this node as its <see cref="AnimancerNodeBase.Parent"/>.</summary>
/// <remarks>When overriding, don't call this base method because it throws an exception.</remarks>
/// <exception cref="NotSupportedException">This node can't have children.</exception>
protected internal virtual void OnAddChild(AnimancerState state)
{
MarkAsUsed(this);
state.SetParentInternal(null);
throw new NotSupportedException(this + " can't have children.");
}
/************************************************************************************************************************/
// IEnumerable for 'foreach' statements.
/************************************************************************************************************************/
/// <summary>Gets an enumerator for all of this node's child states.</summary>
public virtual FastEnumerator<AnimancerState> GetEnumerator()
=> default;
IEnumerator<AnimancerState> IEnumerable<AnimancerState>.GetEnumerator()
=> GetEnumerator();
IEnumerator IEnumerable.GetEnumerator()
=> GetEnumerator();
/************************************************************************************************************************/
#endregion
/************************************************************************************************************************/
#region Weight
/************************************************************************************************************************/
/// <summary>[Internal] The current blend weight of this node. Accessed via <see cref="Weight"/>.</summary>
internal float _Weight;
/************************************************************************************************************************/
/// <summary>The current blend weight of this node which determines how much it affects the final output.</summary>
///
/// <remarks>
/// 0 has no effect while 1 applies the full effect and values inbetween apply a proportional effect.
/// <para></para>
/// Setting this property cancels any fade currently in progress. If you don't wish to do that, you can use
/// <see cref="SetWeight"/> instead.
/// <para></para>
/// <em>Animancer Lite only allows this value to be set to 0 or 1 in runtime builds.</em>
/// </remarks>
///
/// <example>
/// Calling <see cref="AnimancerLayer.Play(AnimationClip)"/> immediately sets the weight of all states to 0
/// and the new state to 1. Note that this is separate from other values like
/// <see cref="AnimancerState.IsPlaying"/> so a state can be paused at any point and still show its pose on the
/// character or it could be still playing at 0 weight if you want it to still trigger events (though states
/// are normally stopped when they reach 0 weight so you would need to explicitly set it to playing again).
/// <para></para>
/// Calling <see cref="AnimancerLayer.Play(AnimationClip, float, FadeMode)"/> doesn't immediately change
/// the weights, but instead calls <see cref="StartFade(float, float)"/> on every state to set their
/// <see cref="TargetWeight"/> and <see cref="FadeSpeed"/>. Then every update each state's weight will move
/// towards that target value at that speed.
/// </example>
public float Weight
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => _Weight;
set
{
FadeGroup = null;
SetWeight(value);
}
}
/// <summary>
/// Sets the current blend weight of this node which determines how much it affects the final output.
/// 0 has no effect while 1 applies the full effect of this node.
/// </summary>
/// <remarks>
/// This method allows any fade currently in progress to continue. If you don't wish to do that, you can set
/// the <see cref="Weight"/> property instead.
/// <para></para>
/// <em>Animancer Lite only allows this value to be set to 0 or 1 in runtime builds.</em>
/// </remarks>
public virtual void SetWeight(float value)
=> SetWeightInternal(value);
/// <summary>The internal non-<c>virtual</c> implementation of <see cref="SetWeight"/>.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void SetWeightInternal(float value)
{
if (_Weight == value)
return;
Validate.AssertSetWeight(this, value);
_Weight = value;
if (Graph != null)
Parent?.Playable.ApplyChildWeight(this);
}
/************************************************************************************************************************/
/// <inheritdoc/>
protected internal override float BaseWeight
=> Weight;
/// <summary>
/// The <see cref="Weight"/> of this state multiplied by the <see cref="Weight"/> of each of its parents down
/// the hierarchy to determine how much this state affects the final output.
/// </summary>
public float EffectiveWeight
{
get
{
var weight = Weight;
var parent = Parent;
while (parent != null)
{
weight *= parent.BaseWeight;
parent = parent.Parent;
}
return weight;
}
}
/************************************************************************************************************************/
#endregion
/************************************************************************************************************************/
#region Fading
/************************************************************************************************************************/
internal FadeGroup _FadeGroup;
/// <summary>The current fade being applied to this node (if any).</summary>
public FadeGroup FadeGroup
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => _FadeGroup;
internal set
{
_FadeGroup?.Remove(this);
_FadeGroup = value;
}
}
/// <summary>
/// The desired <see cref="Weight"/> which this node is fading towards according to the
/// <see cref="FadeSpeed"/>.
/// </summary>
public float TargetWeight
=> FadeGroup != null
? FadeGroup.GetTargetWeight(this)
: Weight;
/// <summary>The speed at which this node is fading towards the <see cref="TargetWeight"/>.</summary>
/// <remarks>
/// This value isn't affected by this node's <see cref="AnimancerNodeBase.Speed"/>,
/// but is affected by its parents.
/// </remarks>
public float FadeSpeed
=> FadeGroup != null
? FadeGroup.FadeSpeed
: 0;
/************************************************************************************************************************/
/// <summary>
/// Calls <see cref="OnStartFade"/> and starts fading the <see cref="Weight"/> over the course
/// of the <see cref="AnimancerGraph.DefaultFadeDuration"/> (in seconds).
/// </summary>
/// <remarks>
/// If the `targetWeight` is 0 then <see cref="Stop"/> will be called when the fade is complete.
/// <para></para>
/// If the <see cref="Weight"/> is already equal to the `targetWeight` then the fade will end
/// immediately.
/// </remarks>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void StartFade(float targetWeight)
=> StartFade(targetWeight, AnimancerGraph.DefaultFadeDuration);
/// <summary>
/// Calls <see cref="OnStartFade"/> and starts fading the <see cref="Weight"/>
/// over the course of the `fadeDuration` (in seconds).
/// </summary>
/// <remarks>
/// If the `targetWeight` is 0 then <see cref="Stop"/> will be called when the fade is complete.
/// <para></para>
/// If the <see cref="Weight"/> is already equal to the `targetWeight`
/// then the fade will end immediately.
/// <para></para>
/// <em>Animancer Lite only allows a `targetWeight` of 0 or 1
/// and the default `fadeDuration` (0.25 seconds) in runtime builds.</em>
/// </remarks>
public void StartFade(float targetWeight, float fadeDuration)
{
if (Weight == targetWeight && FadeGroup == null)
{
OnStartFade();
}
else if (fadeDuration > 0)
{
var fadeSpeed = Math.Abs(targetWeight - Weight) / fadeDuration;
var fade = FadeGroup.Pool.Instance.Acquire();
fade.SetFadeIn(this);
fade.StartFade(targetWeight, fadeSpeed);
}
else
{
Weight = targetWeight;
}
}
/************************************************************************************************************************/
/// <summary>Called by <see cref="StartFade(float, float)"/>.</summary>
protected internal abstract void OnStartFade();
/************************************************************************************************************************/
/// <summary>Removes this node from the <see cref="FadeGroup"/>.</summary>
public void CancelFade()
=> _FadeGroup?.Remove(this);
/// <summary>[Internal] Called by <see cref="FadeGroup.Remove"/>.</summary>
/// <remarks>Not called when a fade fully completes.</remarks>
protected internal virtual void InternalClearFade()
{
_FadeGroup = null;
}
/************************************************************************************************************************/
/// <summary>Stops the animation and makes it inactive immediately so it no longer affects the output.</summary>
/// <remarks>
/// Sets <see cref="Weight"/> = 0 by default unless overridden.
/// <para></para>
/// Note that playing something new will automatically stop the old animation.
/// </remarks>
public void Stop()
{
FadeGroup = null;
SetWeightInternal(0);
StopWithoutWeight();
}
/// <summary>[Internal] Stops this node without setting its <see cref="Weight"/>.</summary>
protected internal virtual void StopWithoutWeight() { }
/************************************************************************************************************************/
#endregion
/************************************************************************************************************************/
#region Inverse Kinematics
/************************************************************************************************************************/
/// <summary>
/// Should setting the <see cref="AnimancerNodeBase.Parent"/>
/// also set this node's <see cref="ApplyAnimatorIK"/> to match it?
/// Default is true.
/// </summary>
public static bool ApplyParentAnimatorIK { get; set; } = true;
/// <summary>
/// Should setting the <see cref="AnimancerNodeBase.Parent"/>
/// also set this node's <see cref="ApplyFootIK"/> to match it?
/// Default is true.
/// </summary>
public static bool ApplyParentFootIK { get; set; } = true;
/************************************************************************************************************************/
/// <summary>
/// Copies the IK settings from `copyFrom` into this node:
/// <list type="bullet">
/// <item>If <see cref="ApplyParentAnimatorIK"/> is true, copy <see cref="ApplyAnimatorIK"/>.</item>
/// <item>If <see cref="ApplyParentFootIK"/> is true, copy <see cref="ApplyFootIK"/>.</item>
/// </list>
/// </summary>
public virtual void CopyIKFlags(AnimancerNodeBase copyFrom)
{
if (Graph == null)
return;
if (ApplyParentAnimatorIK)
ApplyAnimatorIK = copyFrom.ApplyAnimatorIK;
if (ApplyParentFootIK)
ApplyFootIK = copyFrom.ApplyFootIK;
}
/************************************************************************************************************************/
/// <inheritdoc/>
public override bool ApplyAnimatorIK
{
get
{
for (int i = ChildCount - 1; i >= 0; i--)
{
var state = GetChild(i);
if (state.ApplyAnimatorIK)
return true;
}
return false;
}
set
{
for (int i = ChildCount - 1; i >= 0; i--)
{
var state = GetChild(i);
state.ApplyAnimatorIK = value;
}
}
}
/************************************************************************************************************************/
/// <inheritdoc/>
public override bool ApplyFootIK
{
get
{
for (int i = ChildCount - 1; i >= 0; i--)
{
var state = GetChild(i);
if (state.ApplyFootIK)
return true;
}
return false;
}
set
{
for (int i = ChildCount - 1; i >= 0; i--)
{
var state = GetChild(i);
state.ApplyFootIK = value;
}
}
}
/************************************************************************************************************************/
#endregion
/************************************************************************************************************************/
#region Descriptions
/************************************************************************************************************************/
#if UNITY_ASSERTIONS
/// <summary>[Assert-Only] The Inspector display name of this node.</summary>
/// <remarks>Set using <see cref="SetDebugName"/>.</remarks>
public object DebugName { get; private set; }
#endif
/// <summary>[Assert-Conditional] Sets the <see cref="DebugName"/> to display in the Inspector.</summary>
[System.Diagnostics.Conditional(Strings.Assertions)]
public void SetDebugName(object name)
{
#if UNITY_ASSERTIONS
DebugName = name;
#endif
}
/// <summary>The Inspector display name of this node.</summary>
public override string ToString()
{
#if UNITY_ASSERTIONS
if (NameCache.TryToString(DebugName, out var name))
return name;
#endif
return base.ToString();
}
/************************************************************************************************************************/
/// <inheritdoc/>
public void AppendDescription(StringBuilder text, string separator = "\n")
{
text.Append(ToString());
AppendDetails(text, separator);
if (ChildCount > 0)
{
text.AppendField(separator, nameof(ChildCount), ChildCount);
var indentedSeparator = separator + Strings.Indent;
var i = 0;
foreach (var child in this)
{
text.Append(separator)
.Append('[')
.Append(i++)
.Append("] ")
.AppendDescription(child, indentedSeparator, true);
}
}
}
/************************************************************************************************************************/
/// <summary>Called by <see cref="AppendDescription"/> to append the details of this node.</summary>
protected virtual void AppendDetails(StringBuilder text, string separator)
{
text.AppendField(separator, "Playable", _Playable.IsValid()
? _Playable.GetPlayableType().ToString()
: "Invalid");
var parent = Parent;
var isConnected =
parent != null &&
parent.Playable.GetInput(Index).IsValid();
text.AppendField(separator, "Connected", isConnected);
text.AppendField(separator, nameof(Index), Index);
if (Index < 0)
text.Append(" (No Parent)");
text.AppendField(separator, nameof(Speed), Speed);
var realSpeed = _Playable.IsValid()
? _Playable.GetSpeed()
: Speed;
if (realSpeed != Speed)
text.Append(" (Real ").Append(realSpeed).Append(')');
text.AppendField(separator, nameof(Weight), Weight);
if (Weight != TargetWeight)
{
text.AppendField(separator, nameof(TargetWeight), TargetWeight);
text.AppendField(separator, nameof(FadeSpeed), FadeSpeed);
}
AppendIKDetails(text, separator, this);
#if UNITY_ASSERTIONS
if (_ConstructorStackTrace != null)
text.AppendField(separator, "ConstructorStackTrace", _ConstructorStackTrace);
#endif
}
/************************************************************************************************************************/
/// <summary>
/// Appends the details of <see cref="AnimancerNodeBase.ApplyAnimatorIK"/> and
/// <see cref="AnimancerNodeBase.ApplyFootIK"/>.
/// </summary>
public static void AppendIKDetails(StringBuilder text, string separator, AnimancerNodeBase node)
{
if (!node.Playable.IsValid())
return;
text.Append(separator)
.Append("InverseKinematics: ");
if (node.ApplyAnimatorIK)
{
text.Append("OnAnimatorIK");
if (node.ApplyFootIK)
text.Append(", FootIK");
}
else if (node.ApplyFootIK)
{
text.Append("FootIK");
}
else
{
text.Append("None");
}
}
/************************************************************************************************************************/
/// <summary>Returns the hierarchy path of this node through its <see cref="AnimancerNodeBase.Parent"/>s.</summary>
public string GetPath()
{
var path = StringBuilderPool.Instance.Acquire();
if (Parent is AnimancerNode parent)
{
AppendPath(path, parent);
AppendPortAndType(path);
}
else
{
AppendPortAndType(path);
}
return path.ReleaseToString();
}
/// <summary>Appends the hierarchy path of this state through its <see cref="AnimancerNodeBase.Parent"/>s.</summary>
private static void AppendPath(StringBuilder path, AnimancerNode parent)
{
if (parent != null)
{
if (parent.Parent is AnimancerNode grandParent)
{
AppendPath(path, grandParent);
}
else
{
var layer = parent.Layer;
if (layer != null)
{
path.Append("Layers[")
.Append(parent.Layer.Index)
.Append("].States");
}
else
{
path.Append("NoLayer -> ")
.Append(parent.ToString());
}
return;
}
}
if (parent is AnimancerState state)
{
state.AppendPortAndType(path);
}
else
{
path.Append(" -> ")
.Append(parent.GetType());
}
}
/// <summary>Appends "[Index] -> ToString()".</summary>
private void AppendPortAndType(StringBuilder path)
{
path.Append('[')
.Append(Index)
.Append("] -> ")
.Append(ToString());
}
/************************************************************************************************************************/
#endregion
/************************************************************************************************************************/
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 54f55b421ce0c584ab6bcb47947126e4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,279 @@
// Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2024 Kybernetik //
using System;
using UnityEngine.Playables;
namespace Animancer
{
/// <summary>Base class for objects that manage a <see cref="UnityEngine.Playables.Playable"/>.</summary>
/// <remarks>This is the base class of <see cref="AnimancerGraph"/> and <see cref="AnimancerNode"/>.</remarks>
/// https://kybernetik.com.au/animancer/api/Animancer/AnimancerNodeBase
public abstract class AnimancerNodeBase
{
/************************************************************************************************************************/
/// <summary>The <see cref="AnimancerGraph"/> containing this node.</summary>
public AnimancerGraph Graph { get; internal set; }
/************************************************************************************************************************/
/// <summary>The object which receives the output of the <see cref="Playable"/>.</summary>
/// <remarks>
/// This leads from <see cref="AnimancerState"/> to <see cref="AnimancerLayer"/> to
/// <see cref="AnimancerGraph"/> to <c>null</c>.
/// </remarks>
public AnimancerNodeBase Parent { get; protected set; }
/************************************************************************************************************************/
/// <summary>The root <see cref="AnimancerLayer"/> which this node is connected to (if any).</summary>
public virtual AnimancerLayer Layer
=> Parent?.Layer;
/************************************************************************************************************************/
/// <summary>The number of nodes using this as their <see cref="Parent"/>.</summary>
public virtual int ChildCount
=> 0;
/// <summary>Returns the node connected to the specified `index` as a child of this node.</summary>
/// <remarks>When overriding, don't call this base method because it throws an exception.</remarks>
/// <exception cref="NotSupportedException">This node can't have children.</exception>
protected internal virtual AnimancerNode GetChildNode(int index)
{
MarkAsUsed(this);
throw new NotSupportedException(this + " can't have children.");
}
/// <summary>Should child playables stay connected to the graph at all times?</summary>
/// <remarks>
/// If false, playables will be disconnected from the graph while they are inactive to stop it from
/// evaluating them every frame which usually improves performance.
/// </remarks>
/// <seealso cref="AnimancerGraph.KeepChildrenConnected"/>
public virtual bool KeepChildrenConnected
=> true;
/************************************************************************************************************************/
/// <summary>Called when a child's <see cref="AnimancerState.IsLooping"/> value changes.</summary>
protected virtual void OnChildIsLoopingChanged(bool value) { }
/// <summary>[Internal] Calls <see cref="OnChildIsLoopingChanged"/> for each <see cref="Parent"/> recursively.</summary>
protected internal void OnIsLoopingChangedRecursive(bool value)
{
var parent = Parent;
while (parent != null)
{
parent.OnChildIsLoopingChanged(value);
parent = parent.Parent;
}
}
/************************************************************************************************************************/
/// <summary>[Internal] Called when a child's <see cref="Parent"/> is changed from this node.</summary>
/// <remarks>When overriding, don't call this base method because it throws an exception.</remarks>
/// <exception cref="NotSupportedException">This node can't have children.</exception>
protected internal virtual void OnRemoveChild(AnimancerState state)
{
MarkAsUsed(this);
state.SetParentInternal(null);
throw new NotSupportedException(this + " can't have children.");
}
/************************************************************************************************************************/
/// <summary>[Internal] The <see cref="Playable"/>.</summary>
protected internal Playable _Playable;
/// <summary>The internal object this node manages in the <see cref="PlayableGraph"/>.</summary>
/// <remarks>
/// Must be set by <see cref="AnimancerNode.CreatePlayable()"/>. Failure to do so will throw the following
/// exception throughout the system when using this node: "<see cref="ArgumentException"/>: The playable passed
/// as an argument is invalid. To create a valid playable, please use the appropriate Create method".
/// </remarks>
public Playable Playable => _Playable;
/************************************************************************************************************************/
/// <summary>The current blend weight of this node which determines how much it affects the final output.</summary>
protected internal virtual float BaseWeight => 1;
/************************************************************************************************************************/
#region Speed
/************************************************************************************************************************/
private float _Speed = 1;
/// <summary>[Pro-Only] How fast the <see cref="AnimancerState.Time"/> is advancing every frame (default 1).</summary>
///
/// <remarks>
/// A negative value will play the animation backwards.
/// <para></para>
/// To pause an animation, consider setting <see cref="AnimancerState.IsPlaying"/> to false instead of setting
/// this value to 0.
/// <para></para>
/// <em>Animancer Lite doesn't allow this value to be changed in runtime builds.</em>
/// <para></para>
/// <strong>Example:</strong><code>
/// void SpeedExample(AnimancerComponent animancer, AnimationClip clip)
/// {
/// var state = animancer.Play(clip);
///
/// state.Speed = 1;// Normal speed.
/// state.Speed = 2;// Double speed.
/// state.Speed = 0.5f;// Half speed.
/// state.Speed = -1;// Normal speed playing backwards.
/// state.NormalizedTime = 1;// Start at the end to play backwards from there.
/// }
/// </code></remarks>
///
/// <exception cref="ArgumentOutOfRangeException">The value is not finite.</exception>
public float Speed
{
get => _Speed;
set
{
if (_Speed == value)
return;
#if UNITY_ASSERTIONS
if (!value.IsFinite())
{
MarkAsUsed(this);
throw new ArgumentOutOfRangeException(nameof(value), value, $"{nameof(Speed)} {Strings.MustBeFinite}");
}
#endif
_Speed = value;
if (_Playable.IsValid())
_Playable.SetSpeed(value);
}
}
/************************************************************************************************************************/
/// <summary>
/// The <see cref="Speed"/> of this node multiplied by the <see cref="Speed"/> of each of its parents to
/// determine the actual speed it's playing at.
/// </summary>
public float EffectiveSpeed
{
get => Speed * ParentEffectiveSpeed;
set => Speed = value / ParentEffectiveSpeed;
}
/************************************************************************************************************************/
/// <summary>
/// The multiplied <see cref="Speed"/> of each of the <see cref="Parent"/> down the hierarchy,
/// excluding the root <see cref="Speed"/>.
/// </summary>
private float ParentEffectiveSpeed
{
get
{
var parent = Parent;
if (parent == null)
return 1;
var speed = parent.Speed;
while ((parent = parent.Parent) != null)
{
speed *= parent.Speed;
}
return speed;
}
}
/************************************************************************************************************************/
#endregion
/************************************************************************************************************************/
/// <summary>
/// Should Unity call <c>OnAnimatorIK</c> on the animated object while this object and its children have any
/// <see cref="AnimancerNode.Weight"/>?
/// </summary>
/// <remarks>
/// This is equivalent to the "IK Pass" toggle in Animator Controller layers, except that due to limitations in
/// the Playables API the <c>layerIndex</c> will always be zero.
/// <para></para>
/// This value starts false by default, but can be automatically changed by
/// <see cref="AnimancerNode.CopyIKFlags"/> when the <see cref="Parent"/> is set.
/// <para></para>
/// IK only takes effect while at least one <see cref="ClipState"/> has a <see cref="AnimancerNode.Weight"/>
/// above zero. Other node types either store the value to apply to their children or don't support IK.
/// <para></para>
/// <strong>Documentation:</strong>
/// <see href="https://kybernetik.com.au/animancer/docs/manual/ik#ik-pass">
/// IK Pass</see>
/// </remarks>
public abstract bool ApplyAnimatorIK { get; set; }
/************************************************************************************************************************/
/// <summary>Should this object and its children apply IK to the character's feet?</summary>
/// <remarks>
/// This is equivalent to the "Foot IK" toggle in Animator Controller states.
/// <para></para>
/// This value starts true by default for <see cref="ClipState"/>s (false for others), but can be automatically
/// changed by <see cref="AnimancerNode.CopyIKFlags"/> when the <see cref="Parent"/> is set.
/// <para></para>
/// IK only takes effect while at least one <see cref="ClipState"/> has a <see cref="AnimancerNode.Weight"/>
/// above zero. Other node types either store the value to apply to their children or don't support IK.
/// <para></para>
/// <strong>Documentation:</strong>
/// <see href="https://kybernetik.com.au/animancer/docs/manual/ik#foot-ik">
/// Foot IK</see>
/// </remarks>
public abstract bool ApplyFootIK { get; set; }
/************************************************************************************************************************/
/// <summary>[Internal] Applies a change to a child's <see cref="AnimancerState.IsActive"/>.</summary>
protected internal virtual void ApplyChildActive(AnimancerState child, bool setActive)
=> child.ShouldBeActive = setActive;
/************************************************************************************************************************/
/// <summary>[Assert-Conditional] Prevents the `node` from causing <see cref="OptionalWarning.UnusedNode"/>.</summary>
[System.Diagnostics.Conditional(Strings.Assertions)]
public static void MarkAsUsed(AnimancerNodeBase node)
{
#if UNITY_ASSERTIONS
if (node.Graph == null)
GC.SuppressFinalize(node);
#endif
}
/************************************************************************************************************************/
#if UNITY_EDITOR
/************************************************************************************************************************/
/// <summary>[Editor-Only]
/// Adds functions to show and set <see cref="ApplyAnimatorIK"/> and
/// <see cref="ApplyFootIK"/>.
/// </summary>
public static void AddContextMenuIK(UnityEditor.GenericMenu menu, AnimancerNodeBase ik)
{
#if UNITY_IMGUI
menu.AddItem(new("Inverse Kinematics/Apply Animator IK ?"),
ik.ApplyAnimatorIK,
() => ik.ApplyAnimatorIK = !ik.ApplyAnimatorIK);
menu.AddItem(new("Inverse Kinematics/Apply Foot IK ?"),
ik.ApplyFootIK,
() => ik.ApplyFootIK = !ik.ApplyFootIK);
#endif
}
/************************************************************************************************************************/
#endif
/************************************************************************************************************************/
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 8abfd735619067c40b7e6e10bcc0b559
labels:
- Interface
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,67 @@
// Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2024 Kybernetik //
namespace Animancer
{
/// https://kybernetik.com.au/animancer/api/Animancer/AnimancerState
public abstract partial class AnimancerState
{
/************************************************************************************************************************/
#if UNITY_ASSERTIONS
private static bool _SkipNextExpectFade;
private bool _ExpectFade;
#endif
/************************************************************************************************************************/
/// <summary>[Internal] Sets a flag for <see cref="OptionalWarning.ExpectFade"/>.</summary>
[System.Diagnostics.Conditional(Strings.Assertions)]
public static void SetExpectFade(AnimancerState state, float fadeDuration)
{
#if UNITY_ASSERTIONS
state._ExpectFade = fadeDuration > 0;
#endif
}
/************************************************************************************************************************/
/// <summary>[Internal] Sets the next <see cref="AssertNotExpectingFade"/> call to be skipped.</summary>
[System.Diagnostics.Conditional(Strings.Assertions)]
internal static void SkipNextExpectFade()
{
#if UNITY_ASSERTIONS
_SkipNextExpectFade = true;
#endif
}
/************************************************************************************************************************/
/// <summary>[Internal] Call when playing a `state` without a fade to check <see cref="OptionalWarning.ExpectFade"/>.</summary>
[System.Diagnostics.Conditional(Strings.Assertions)]
internal static void AssertNotExpectingFade(AnimancerState state)
{
#if UNITY_ASSERTIONS
if (_SkipNextExpectFade)
{
_SkipNextExpectFade = false;
return;
}
if (state._ExpectFade)
{
state._ExpectFade = false;// Don't log again for the same state.
OptionalWarning.ExpectFade.Log(
"A state was created by a transition with a non-zero Fade Duration" +
" but is now being played without a fade, which may be unintentional." +
" In most cases, the transition should be played so that it can properly" +
" apply its settings, unlike if the state is played directly.",
state.Graph?.Component);
}
#endif
}
/************************************************************************************************************************/
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 04e4439666601f0439582e16fc1572eb
timeCreated: 1515060256
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 887b4c2f23914df4085099d24992df1c
timeCreated: 1515060256
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,195 @@
// Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2024 Kybernetik //
using System;
using UnityEngine;
using UnityEngine.Animations;
using UnityEngine.Playables;
using Object = UnityEngine.Object;
namespace Animancer
{
/// <summary>An <see cref="AnimancerState"/> which plays an <see cref="AnimationClip"/>.</summary>
/// <remarks>
/// <strong>Documentation:</strong>
/// <see href="https://kybernetik.com.au/animancer/docs/manual/playing/states">
/// States</see>
/// </remarks>
/// https://kybernetik.com.au/animancer/api/Animancer/ClipState
///
public class ClipState : AnimancerState
{
/************************************************************************************************************************/
#region Fields and Properties
/************************************************************************************************************************/
private AnimationClip _Clip;
/// <summary>The <see cref="AnimationClip"/> which this state plays.</summary>
public override AnimationClip Clip
{
get => _Clip;
set
{
Validate.AssertAnimationClip(value, true, $"set {nameof(ClipState)}.{nameof(Clip)}");
if (ChangeMainObject(ref _Clip, value))
{
_Length = value.length;
var isLooping = value.isLooping;
if (_IsLooping != isLooping)
{
_IsLooping = isLooping;
OnIsLoopingChangedRecursive(isLooping);
}
}
}
}
/// <summary>The <see cref="AnimationClip"/> which this state plays.</summary>
public override Object MainObject
{
get => _Clip;
set => Clip = (AnimationClip)value;
}
#if UNITY_EDITOR
/// <inheritdoc/>
public override Type MainObjectType
=> typeof(AnimationClip);
#endif
/************************************************************************************************************************/
private float _Length;
/// <summary>The <see cref="AnimationClip.length"/>.</summary>
public override float Length
=> _Length;
/************************************************************************************************************************/
private bool _IsLooping;
/// <summary>The <see cref="Motion.isLooping"/>.</summary>
public override bool IsLooping
=> _IsLooping;
/************************************************************************************************************************/
/// <inheritdoc/>
public override void GetEventDispatchInfo(
out float length,
out float normalizedTime,
out bool isLooping)
{
length = _Length;
normalizedTime = length != 0
? Time / length
: 0;
isLooping = _IsLooping;
}
/************************************************************************************************************************/
/// <inheritdoc/>
public override Vector3 AverageVelocity
=> _Clip.averageSpeed;
/************************************************************************************************************************/
#region Inverse Kinematics
/************************************************************************************************************************/
/// <inheritdoc/>
public override bool ApplyAnimatorIK
{
get => _Playable.IsValid() && ((AnimationClipPlayable)_Playable).GetApplyPlayableIK();
set
{
Validate.AssertPlayable(this);
((AnimationClipPlayable)_Playable).SetApplyPlayableIK(value);
}
}
/************************************************************************************************************************/
/// <inheritdoc/>
public override bool ApplyFootIK
{
get => _Playable.IsValid() && ((AnimationClipPlayable)_Playable).GetApplyFootIK();
set
{
Validate.AssertPlayable(this);
((AnimationClipPlayable)_Playable).SetApplyFootIK(value);
}
}
/************************************************************************************************************************/
#endregion
/************************************************************************************************************************/
#endregion
/************************************************************************************************************************/
#region Methods
/************************************************************************************************************************/
/// <summary>Creates a new <see cref="ClipState"/> and sets its <see cref="Clip"/>.</summary>
/// <exception cref="ArgumentNullException">The `clip` is null.</exception>
public ClipState(AnimationClip clip)
{
Validate.AssertAnimationClip(clip, true, $"create {nameof(ClipState)}");
_Clip = clip;
_Length = clip.length;
_IsLooping = clip.isLooping;
}
/************************************************************************************************************************/
/// <summary>Creates and assigns the <see cref="AnimationClipPlayable"/> managed by this node.</summary>
protected override void CreatePlayable(out Playable playable)
{
playable = AnimationClipPlayable.Create(Graph._PlayableGraph, _Clip);
}
/************************************************************************************************************************/
/// <inheritdoc/>
public override void RecreatePlayable()
{
var playable = (AnimationClipPlayable)_Playable;
var footIK = playable.GetApplyFootIK();
var playableIK = playable.GetApplyPlayableIK();
base.RecreatePlayable();
playable = (AnimationClipPlayable)_Playable;
playable.SetApplyFootIK(footIK);
playable.SetApplyPlayableIK(playableIK);
}
/************************************************************************************************************************/
/// <inheritdoc/>
public override void Destroy()
{
_Clip = null;
base.Destroy();
}
/************************************************************************************************************************/
/// <inheritdoc/>
public override AnimancerState Clone(CloneContext context)
{
var clip = context.GetCloneOrOriginal(_Clip);
var clone = new ClipState(clip);
clone.CopyFrom(this, context);
return clone;
}
/************************************************************************************************************************/
#endregion
/************************************************************************************************************************/
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 5cba070da561e2f4fa6d618d4701bce3
timeCreated: 1515060256
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,372 @@
// Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2024 Kybernetik //
using System;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using UnityEngine.Animations;
using UnityEngine.Audio;
using UnityEngine.Playables;
using Object = UnityEngine.Object;
namespace Animancer
{
/// <summary>[Pro-Only] An <see cref="AnimancerState"/> which plays a <see cref="PlayableAsset"/>.</summary>
/// <remarks>
/// <strong>Documentation:</strong>
/// <see href="https://kybernetik.com.au/animancer/docs/manual/timeline">
/// Timeline</see>
/// </remarks>
/// https://kybernetik.com.au/animancer/api/Animancer/PlayableAssetState
public class PlayableAssetState : AnimancerState
{
/************************************************************************************************************************/
#region Fields and Properties
/************************************************************************************************************************/
/// <summary>The <see cref="PlayableAsset"/> which this state plays.</summary>
private PlayableAsset _Asset;
/// <summary>The <see cref="PlayableAsset"/> which this state plays.</summary>
public PlayableAsset Asset
{
get => _Asset;
set => ChangeMainObject(ref _Asset, value);
}
/// <summary>The <see cref="PlayableAsset"/> which this state plays.</summary>
public override Object MainObject
{
get => _Asset;
set => _Asset = (PlayableAsset)value;
}
#if UNITY_EDITOR
/// <inheritdoc/>
public override Type MainObjectType
=> typeof(PlayableAsset);
#endif
/************************************************************************************************************************/
private float _Length;
/// <summary>The <see cref="PlayableAsset.duration"/>.</summary>
public override float Length => _Length;
/************************************************************************************************************************/
/// <inheritdoc/>
public override void GetEventDispatchInfo(
out float length,
out float normalizedTime,
out bool isLooping)
{
length = _Length;
normalizedTime = length != 0
? Time / length
: 0;
isLooping = false;
}
/************************************************************************************************************************/
/// <inheritdoc/>
protected override void OnSetIsPlaying()
{
if (!_Playable.IsValid())
return;
var inputCount = _Playable.GetInputCount();
for (int i = 0; i < inputCount; i++)
{
var playable = _Playable.GetInput(i);
if (!playable.IsValid())
continue;
if (IsPlaying)
playable.Play();
else
playable.Pause();
}
}
/************************************************************************************************************************/
/// <summary>IK cannot be dynamically enabled on a <see cref="PlayableAssetState"/>.</summary>
public override void CopyIKFlags(AnimancerNodeBase copyFrom) { }
/************************************************************************************************************************/
/// <summary>IK cannot be dynamically enabled on a <see cref="PlayableAssetState"/>.</summary>
public override bool ApplyAnimatorIK
{
get => false;
set
{
#if UNITY_ASSERTIONS
if (value)
OptionalWarning.UnsupportedIK.Log(
$"IK cannot be dynamically enabled on a {nameof(PlayableAssetState)}.", Graph?.Component);
#endif
}
}
/************************************************************************************************************************/
/// <summary>IK cannot be dynamically enabled on a <see cref="PlayableAssetState"/>.</summary>
public override bool ApplyFootIK
{
get => false;
set
{
#if UNITY_ASSERTIONS
if (value)
OptionalWarning.UnsupportedIK.Log(
$"IK cannot be dynamically enabled on a {nameof(PlayableAssetState)}.", Graph?.Component);
#endif
}
}
/************************************************************************************************************************/
#endregion
/************************************************************************************************************************/
#region Methods
/************************************************************************************************************************/
/// <summary>Creates a new <see cref="PlayableAssetState"/> to play the `asset`.</summary>
/// <exception cref="ArgumentNullException">The `asset` is null.</exception>
public PlayableAssetState(PlayableAsset asset)
{
if (asset == null)
throw new ArgumentNullException(nameof(asset));
_Asset = asset;
}
/************************************************************************************************************************/
/// <inheritdoc/>
protected override void CreatePlayable(out Playable playable)
{
playable = _Asset.CreatePlayable(Graph._PlayableGraph, Graph.Component.gameObject);
playable.SetDuration(9223372.03685477);// https://github.com/KybernetikGames/animancer/issues/111
_Length = (float)_Asset.duration;
if (!_HasInitializedBindings)
InitializeBindings();
}
/************************************************************************************************************************/
private IList<Object> _Bindings;
private bool _HasInitializedBindings;
/************************************************************************************************************************/
/// <summary>The objects controlled by each track in the asset.</summary>
public IList<Object> Bindings
{
get => _Bindings;
set
{
_Bindings = value;
InitializeBindings();
}
}
/************************************************************************************************************************/
/// <summary>Sets the <see cref="Bindings"/>.</summary>
public void SetBindings(params Object[] bindings)
{
Bindings = bindings;
}
/************************************************************************************************************************/
private void InitializeBindings()
{
if (Graph == null)
return;
_HasInitializedBindings = true;
Validate.AssertPlayable(this);
var graph = Graph._PlayableGraph;
var bindableIndex = 0;
var bindableCount = _Bindings != null
? _Bindings.Count
: 0;
foreach (var binding in _Asset.outputs)
{
GetBindingDetails(binding, out var trackName, out var trackType, out var isMarkers);
var bindable = bindableIndex < bindableCount
? _Bindings[bindableIndex]
: null;
#if UNITY_ASSERTIONS
if (!isMarkers &&
trackType != null &&
bindable != null &&
!trackType.IsAssignableFrom(bindable.GetType()))
{
Debug.LogError(
$"Binding Type Mismatch: bindings[{bindableIndex}] is '{bindable}'" +
$" but should be a {trackType.FullName} for {trackName}",
Graph.Component as Object);
bindableIndex++;
continue;
}
#endif
var playable = _Playable.GetInput(bindableIndex);
if (trackType == typeof(Animator))// AnimationTrack.
{
if (bindable != null)
{
#if UNITY_ASSERTIONS
if (bindable == Graph.Component?.Animator)
Debug.LogError(
$"{nameof(PlayableAsset)} tracks should not be bound to the same {nameof(Animator)} as" +
$" Animancer. Leaving the binding of the first Animation Track empty will automatically" +
$" apply its animation to the object being controlled by Animancer.",
Graph.Component as Object);
#endif
var playableOutput = AnimationPlayableOutput.Create(graph, trackName, (Animator)bindable);
playableOutput.SetReferenceObject(binding.sourceObject);
playableOutput.SetSourcePlayable(playable);
playableOutput.SetWeight(1);
}
}
#if UNITY_AUDIO
else if (trackType == typeof(AudioSource))// AudioTrack.
{
if (bindable != null)
{
var playableOutput = AudioPlayableOutput.Create(graph, trackName, (AudioSource)bindable);
playableOutput.SetReferenceObject(binding.sourceObject);
playableOutput.SetSourcePlayable(playable);
playableOutput.SetWeight(1);
}
}
#endif
else if (isMarkers)// Markers.
{
var animancer = Graph.Component as Component;
var playableOutput = ScriptPlayableOutput.Create(graph, trackName);
playableOutput.SetReferenceObject(binding.sourceObject);
playableOutput.SetSourcePlayable(playable);
playableOutput.SetWeight(1);
playableOutput.SetUserData(animancer);
var receivers = ListPool.Acquire<INotificationReceiver>();
animancer.GetComponents(receivers);
for (int i = 0; i < receivers.Count; i++)
playableOutput.AddNotificationReceiver(receivers[i]);
ListPool.Release(receivers);
continue;// Don't increment the bindingIndex.
}
else// ActivationTrack, ControlTrack, PlayableTrack, SignalTrack.
{
var playableOutput = ScriptPlayableOutput.Create(graph, trackName);
playableOutput.SetReferenceObject(binding.sourceObject);
playableOutput.SetSourcePlayable(playable);
playableOutput.SetWeight(1);
playableOutput.SetUserData(bindable);
if (bindable is INotificationReceiver receiver)
playableOutput.AddNotificationReceiver(receiver);
}
bindableIndex++;
}
}
/************************************************************************************************************************/
/// <summary>Gathers details about the `binding`.</summary>
public static void GetBindingDetails(
PlayableBinding binding,
out string name,
out Type type,
out bool isMarkers)
{
name = binding.streamName;
type = binding.outputTargetType;
isMarkers = type == typeof(GameObject) && name == "Markers";
}
/************************************************************************************************************************/
/// <inheritdoc/>
public override void Destroy()
{
_Asset = null;
base.Destroy();
}
/************************************************************************************************************************/
/// <inheritdoc/>
public override AnimancerState Clone(CloneContext context)
{
var asset = context.GetCloneOrOriginal(_Asset);
var clone = new PlayableAssetState(asset);
clone.CopyFrom(this, context);
return clone;
}
/************************************************************************************************************************/
/// <inheritdoc/>
protected override void AppendDetails(StringBuilder text, string separator)
{
base.AppendDetails(text, separator);
text.Append(separator)
.Append($"{nameof(Bindings)}: ");
int count;
if (_Bindings == null)
{
text.Append("Null");
count = 0;
}
else
{
count = _Bindings.Count;
text.Append('[')
.Append(count)
.Append(']');
}
text.Append(_HasInitializedBindings
? " (Initialized)"
: " (Not Initialized)");
for (int i = 0; i < count; i++)
{
text.Append(separator)
.Append($"{nameof(Bindings)}[")
.Append(i)
.Append("] = ")
.Append(AnimancerUtilities.ToStringOrNull(_Bindings[i]));
}
}
/************************************************************************************************************************/
#endregion
/************************************************************************************************************************/
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: c8771e9c8ab67844b8e5cf90e14bf90e
timeCreated: 1515060256
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: