chore: initial commit
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
// Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2026 Kybernetik //
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace Animancer
|
||||
{
|
||||
/// <summary>An <see cref="IUpdatable"/> that cancels any fades and logs warnings when they occur.</summary>
|
||||
///
|
||||
/// <remarks>
|
||||
/// This is useful for <see cref="Sprite"/> based characters since fading does nothing for them.
|
||||
/// <para></para>
|
||||
/// You can also set the <see cref="AnimancerGraph.DefaultFadeDuration"/> to 0 so that you don't need to set it
|
||||
/// manually on all your transitions.
|
||||
/// <para></para>
|
||||
/// <strong>Example:</strong>
|
||||
/// <code>
|
||||
/// [SerializeField] private AnimancerComponent _Animancer;
|
||||
///
|
||||
/// protected virtual void Awake()
|
||||
/// {
|
||||
/// // To only apply it only in the Unity Editor and Development Builds:
|
||||
/// DontAllowFade.Assert(_Animancer);
|
||||
///
|
||||
/// // Or to apply it at all times:
|
||||
/// _Animancer.Graph.RequireUpdate(new DontAllowFade());
|
||||
/// }
|
||||
/// </code></remarks>
|
||||
///
|
||||
/// https://kybernetik.com.au/animancer/api/Animancer/DontAllowFade
|
||||
///
|
||||
public class DontAllowFade : Updatable
|
||||
{
|
||||
/************************************************************************************************************************/
|
||||
|
||||
/// <summary>[Assert-Conditional] Applies a <see cref="DontAllowFade"/> to `animancer`.</summary>
|
||||
[System.Diagnostics.Conditional(Strings.Assertions)]
|
||||
public static void Assert(AnimancerGraph animancer)
|
||||
{
|
||||
#if UNITY_ASSERTIONS
|
||||
animancer.RequirePreUpdate(new DontAllowFade());
|
||||
#endif
|
||||
}
|
||||
|
||||
/************************************************************************************************************************/
|
||||
|
||||
/// <summary>If the `node` is fading, this methods logs a warning (Assert-Only) and cancels the fade.</summary>
|
||||
private static void Validate(AnimancerNode node)
|
||||
{
|
||||
if (node != null && node.FadeSpeed != 0)
|
||||
{
|
||||
#if UNITY_ASSERTIONS
|
||||
Debug.LogWarning($"The following {node.GetType().Name} is fading even though " +
|
||||
$"{nameof(DontAllowFade)} is active: {node.GetDescription()}",
|
||||
node.Graph.Component as Object);
|
||||
#endif
|
||||
|
||||
node.Weight = node.TargetWeight;
|
||||
}
|
||||
}
|
||||
|
||||
/************************************************************************************************************************/
|
||||
|
||||
/// <summary>Calls <see cref="Validate"/> on all layers and their <see cref="AnimancerLayer.CurrentState"/>.</summary>
|
||||
public override void Update()
|
||||
{
|
||||
var layers = AnimancerGraph.Current.Layers;
|
||||
for (int i = layers.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var layer = layers[i];
|
||||
Validate(layer);
|
||||
Validate(layer.CurrentState);
|
||||
}
|
||||
}
|
||||
|
||||
/************************************************************************************************************************/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8847753c6eace0b4c84c323e465a428f
|
||||
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,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cb0b29d765f534f4dbda52acb782341d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,77 @@
|
||||
// Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2026 Kybernetik //
|
||||
|
||||
using System;
|
||||
|
||||
namespace Animancer
|
||||
{
|
||||
/// <summary>Extension methods for <see cref="FadeGroup"/>.</summary>
|
||||
/// https://kybernetik.com.au/animancer/api/Animancer/FadeGroupExtensions
|
||||
public static class FadeGroupExtensions
|
||||
{
|
||||
/************************************************************************************************************************/
|
||||
|
||||
/// <summary>[Pro-Only]
|
||||
/// Assigns the `function` as the <see cref="FadeGroup.Easing"/> if the `fade` isn't <c>null</c>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <em>Animancer Lite ignores this feature in runtime builds.</em>
|
||||
/// <para></para>
|
||||
/// <strong>Example:</strong><code>
|
||||
/// void EasingExample(AnimancerComponent animancer, AnimationClip clip)
|
||||
/// {
|
||||
/// // Start fading the animation normally.
|
||||
/// AnimancerState state = animancer.Play(clip, 0.25f);
|
||||
///
|
||||
/// // Then a custom Easing delegate to modify it.
|
||||
/// state.FadeGroup.SetEasing(t => t * t);// Square the 0-1 value to start slow and end fast.
|
||||
///
|
||||
/// // The Easing class has lots of standard mathematical curve functions.
|
||||
/// state.FadeGroup.SetEasing(Easing.Sine.InOut);
|
||||
///
|
||||
/// // Or you can use the Easing.Function enum.
|
||||
/// state.FadeGroup.SetEasing(Easing.Function.SineInOut);
|
||||
/// }
|
||||
/// </code>
|
||||
/// </remarks>
|
||||
public static void SetEasing(this FadeGroup fade, Func<float, float> function)
|
||||
{
|
||||
if (fade != null)
|
||||
fade.Easing = function;
|
||||
}
|
||||
|
||||
/************************************************************************************************************************/
|
||||
|
||||
/// <summary>[Pro-Only]
|
||||
/// Assigns the <see cref="Easing.GetDelegate(Easing.Function)"/> as the
|
||||
/// <see cref="FadeGroup.Easing"/> if the `fade` isn't <c>null</c>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <em>Animancer Lite ignores this feature in runtime builds.</em>
|
||||
/// <para></para>
|
||||
/// <strong>Example:</strong><code>
|
||||
/// void EasingExample(AnimancerComponent animancer, AnimationClip clip)
|
||||
/// {
|
||||
/// // Start fading the animation normally.
|
||||
/// AnimancerState state = animancer.Play(clip, 0.25f);
|
||||
///
|
||||
/// // Then a custom Easing delegate to modify it.
|
||||
/// state.FadeGroup.SetEasing(t => t * t);// Square the 0-1 value to start slow and end fast.
|
||||
///
|
||||
/// // The Easing class has lots of standard mathematical curve functions.
|
||||
/// state.FadeGroup.SetEasing(Easing.Sine.InOut);
|
||||
///
|
||||
/// // Or you can use the Easing.Function enum.
|
||||
/// state.FadeGroup.SetEasing(Easing.Function.SineInOut);
|
||||
/// }
|
||||
/// </code>
|
||||
/// </remarks>
|
||||
public static void SetEasing(this FadeGroup fade, Easing.Function function)
|
||||
{
|
||||
if (fade != null)
|
||||
fade.Easing = function.GetDelegate();
|
||||
}
|
||||
|
||||
/************************************************************************************************************************/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0141a1bdad0bc044dbef84c772ab5188
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,78 @@
|
||||
// Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2026 Kybernetik //
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Animancer
|
||||
{
|
||||
/// <summary>
|
||||
/// Fades the child weights of a <see cref="MixerState{TParameter}"/>
|
||||
/// to a new parameter value instead of fading the actual parameter.
|
||||
/// </summary>
|
||||
///
|
||||
/// <remarks>
|
||||
/// <para></para>
|
||||
/// <strong>Documentation:</strong>
|
||||
/// <see href="https://kybernetik.com.au/animancer/docs/manual/parameters#smoothing">
|
||||
/// Smoothing</see>
|
||||
/// <para></para>
|
||||
/// <strong>Example:</strong>
|
||||
/// Imagine a Linear Mixer with thresholds 0, 1, 2 and child states A, B, C.
|
||||
/// If you fade its Parameter from 0 to 2 the states would go from A to B to C.
|
||||
/// But if you use this system instead, the states would go directly from A to C.
|
||||
/// <h2>Usage</h2>
|
||||
/// <code>
|
||||
/// [SerializeField] private AnimancerComponent _Animancer;
|
||||
/// [SerializeField] private LinearMixerTransition _Mixer;
|
||||
///
|
||||
/// public void FadeMixerTo(float parameter, float fadeDuration)
|
||||
/// {
|
||||
/// _Mixer.State.FadeChildWeights(parameter, fadeDuration);
|
||||
/// }
|
||||
/// </code></remarks>
|
||||
///
|
||||
/// https://kybernetik.com.au/animancer/api/Animancer/MixerChildFade
|
||||
///
|
||||
public static class MixerChildFade
|
||||
{
|
||||
/************************************************************************************************************************/
|
||||
|
||||
private static readonly List<float>
|
||||
ChildWeights = new();
|
||||
|
||||
/************************************************************************************************************************/
|
||||
|
||||
/// <summary>
|
||||
/// Fades the child weights of a <see cref="MixerState{TParameter}"/>
|
||||
/// to a new parameter value instead of fading the actual parameter.
|
||||
/// </summary>
|
||||
/// <remarks>See <see cref="MixerChildFade"/> for a usage example.</remarks>
|
||||
public static void FadeChildWeights<TParameter>(
|
||||
this MixerState<TParameter> mixer,
|
||||
TParameter parameter,
|
||||
float fadeDuration)
|
||||
{
|
||||
ChildWeights.Clear();
|
||||
|
||||
var childCount = mixer.ChildCount;
|
||||
for (int i = 0; i < childCount; i++)
|
||||
ChildWeights.Add(mixer.GetChild(i).Weight);
|
||||
|
||||
mixer.Parameter = parameter;
|
||||
if (!mixer.RecalculateWeights())
|
||||
return;
|
||||
|
||||
var mixerPlayable = mixer.Playable;
|
||||
|
||||
for (int i = 0; i < childCount; i++)
|
||||
{
|
||||
var child = mixer.GetChild(i);
|
||||
mixerPlayable.SetChildWeight(child, ChildWeights[i]);
|
||||
child.StartFade(Math.Max(child.TargetWeight, float.Epsilon), fadeDuration);
|
||||
}
|
||||
}
|
||||
|
||||
/************************************************************************************************************************/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9ce7cd50d8d836f4ba0a3481884aa46b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user