// Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2023 Kybernetik // using UnityEngine; namespace Animancer { /// https://kybernetik.com.au/animancer/api/Animancer/CustomFade /// public partial class CustomFade { /************************************************************************************************************************/ /// Modify the current fade to use the specified `curve` to calculate the weight. /// See . /// The `curve` should follow the guideline. public static void Apply(AnimancerComponent animancer, AnimationCurve curve) => Apply(animancer.States.Current, curve); /// Modify the current fade to use the specified `curve` to calculate the weight. /// See . /// The `curve` should follow the guideline. public static void Apply(AnimancerPlayable animancer, AnimationCurve curve) => Apply(animancer.States.Current, curve); /// Modify the current fade to use the specified `curve` to calculate the weight. /// See . /// The `curve` should follow the guideline. public static void Apply(AnimancerState state, AnimationCurve curve) => Curve.Acquire(curve).Apply(state); /// Modify the current fade to use the specified `curve` to calculate the weight. /// See . /// The `curve` should follow the guideline. public static void Apply(AnimancerNode node, AnimationCurve curve) => Curve.Acquire(curve).Apply(node); /************************************************************************************************************************/ /// A which uses an to calculate the weight. /// See . private class Curve : CustomFade { /************************************************************************************************************************/ private AnimationCurve _Curve; /************************************************************************************************************************/ public static Curve Acquire(AnimationCurve curve) { if (curve == null) { OptionalWarning.CustomFadeNotNull.Log($"{nameof(curve)} is null."); return null; } var fade = ObjectPool.Acquire(); fade._Curve = curve; return fade; } /************************************************************************************************************************/ protected override float CalculateWeight(float progress) => _Curve.Evaluate(progress); /************************************************************************************************************************/ protected override void Release() => ObjectPool.Release(this); /************************************************************************************************************************/ } } }