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