FadeGroupExtensions.cs 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2024 Kybernetik //
  2. using System;
  3. namespace Animancer
  4. {
  5. /// <summary>Extension methods for <see cref="FadeGroup"/>.</summary>
  6. /// https://kybernetik.com.au/animancer/api/Animancer/FadeGroupExtensions
  7. public static class FadeGroupExtensions
  8. {
  9. /************************************************************************************************************************/
  10. /// <summary>[Pro-Only]
  11. /// Assigns the `function` as the <see cref="FadeGroup.Easing"/> if the `fade` isn't <c>null</c>.
  12. /// </summary>
  13. /// <remarks>
  14. /// <em>Animancer Lite ignores this feature in runtime builds.</em>
  15. /// <para></para>
  16. /// <strong>Example:</strong><code>
  17. /// void EasingExample(AnimancerComponent animancer, AnimationClip clip)
  18. /// {
  19. /// // Start fading the animation normally.
  20. /// AnimancerState state = animancer.Play(clip, 0.25f);
  21. ///
  22. /// // Then a custom Easing delegate to modify it.
  23. /// state.FadeGroup.SetEasing(t => t * t);// Square the 0-1 value to start slow and end fast.
  24. ///
  25. /// // The Easing class has lots of standard mathematical curve functions.
  26. /// state.FadeGroup.SetEasing(Easing.Sine.InOut);
  27. ///
  28. /// // Or you can use the Easing.Function enum.
  29. /// state.FadeGroup.SetEasing(Easing.Function.SineInOut);
  30. /// }
  31. /// </code>
  32. /// </remarks>
  33. public static void SetEasing(this FadeGroup fade, Func<float, float> function)
  34. {
  35. if (fade != null)
  36. fade.Easing = function;
  37. }
  38. /************************************************************************************************************************/
  39. /// <summary>[Pro-Only]
  40. /// Assigns the <see cref="Easing.GetDelegate(Easing.Function)"/> as the
  41. /// <see cref="FadeGroup.Easing"/> if the `fade` isn't <c>null</c>.
  42. /// </summary>
  43. /// <remarks>
  44. /// <em>Animancer Lite ignores this feature in runtime builds.</em>
  45. /// <para></para>
  46. /// <strong>Example:</strong><code>
  47. /// void EasingExample(AnimancerComponent animancer, AnimationClip clip)
  48. /// {
  49. /// // Start fading the animation normally.
  50. /// AnimancerState state = animancer.Play(clip, 0.25f);
  51. ///
  52. /// // Then a custom Easing delegate to modify it.
  53. /// state.FadeGroup.SetEasing(t => t * t);// Square the 0-1 value to start slow and end fast.
  54. ///
  55. /// // The Easing class has lots of standard mathematical curve functions.
  56. /// state.FadeGroup.SetEasing(Easing.Sine.InOut);
  57. ///
  58. /// // Or you can use the Easing.Function enum.
  59. /// state.FadeGroup.SetEasing(Easing.Function.SineInOut);
  60. /// }
  61. /// </code>
  62. /// </remarks>
  63. public static void SetEasing(this FadeGroup fade, Easing.Function function)
  64. {
  65. if (fade != null)
  66. fade.Easing = function.GetDelegate();
  67. }
  68. /************************************************************************************************************************/
  69. }
  70. }