FadeMode.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // Animancer // https://kybernetik.com.au/animancer // Copyright 2022 Kybernetik //
  2. using System;
  3. namespace Animancer
  4. {
  5. /// <summary>Determines how <see cref="AnimancerLayer.Play(AnimancerState, float, FadeMode)"/> works.</summary>
  6. /// <remarks>
  7. /// Documentation: <see href="https://kybernetik.com.au/animancer/docs/manual/blending/fading/modes">Fade Modes</see>
  8. /// <para></para>
  9. /// Example: <see href="https://kybernetik.com.au/animancer/docs/examples/basics/transitions">Transitions</see>
  10. /// </remarks>
  11. /// https://kybernetik.com.au/animancer/api/Animancer/FadeMode
  12. ///
  13. public enum FadeMode
  14. {
  15. /************************************************************************************************************************/
  16. /// <summary>
  17. /// Calculate the fade speed to bring the <see cref="AnimancerNode.Weight"/> from 0 to 1 over the specified
  18. /// fade duration (in seconds), regardless of the actual starting weight.
  19. /// </summary>
  20. ///
  21. /// <example>
  22. /// A fade duration of 0.5 would make the fade last for 0.5 seconds, regardless of how long the animation is.
  23. /// <para></para>
  24. /// This is generally the same as <see cref="FixedDuration"/> but differs when starting the fade from a
  25. /// non-zero <see cref="AnimancerNode.Weight"/>, for example:
  26. /// <list type="bullet">
  27. /// <item>Fade Duration: 0.25</item>
  28. /// <item>To fade from 0 to 1 with either mode would get a speed of 4 and take 0.25 seconds</item>
  29. /// <item>To fade from 0.5 to 1 with <see cref="FixedDuration"/> would get a speed of 2 and take 0.25 seconds.
  30. /// It has half the distance to cover so it goes half as fast to maintain the expected duration.</item>
  31. /// <item>To fade from 0.5 to 1 with <see cref="FixedSpeed"/> would get a speed of 4 and take 0.125 seconds.
  32. /// It gets the same speed regardless of the distance to cover, so with less distance it completes faster.</item>
  33. /// </list>
  34. /// </example>
  35. ///
  36. /// <exception cref="InvalidOperationException">The <see cref="AnimancerState.Clip"/> is null.</exception>
  37. ///
  38. /// <exception cref="ArgumentOutOfRangeException">
  39. /// More states have been created for the <see cref="AnimancerState.Clip"/> than the
  40. /// <see cref="AnimancerLayer.MaxStateDepth"/> allows.
  41. /// </exception>
  42. FixedSpeed,
  43. /// <summary>
  44. /// Calculate the fade speed to bring the <see cref="AnimancerNode.Weight"/> to the target value over the
  45. /// specified fade duration (in seconds).
  46. /// </summary>
  47. ///
  48. /// <example>
  49. /// A fade duration of 0.5 would make the fade last for 0.5 seconds, regardless of how long the animation is.
  50. /// <para></para>
  51. /// This is generally the same as <see cref="FixedSpeed"/>, but differs when starting the fade from a
  52. /// non-zero <see cref="AnimancerNode.Weight"/>:
  53. /// <list type="bullet">
  54. /// <item>Fade Duration: 0.25</item>
  55. /// <item>To fade from 0 to 1 with either mode would get a speed of 4 and take 0.25 seconds</item>
  56. /// <item>To fade from 0.5 to 1 with <see cref="FixedDuration"/> would get a speed of 2 and take 0.25 seconds.
  57. /// It has half the distance to cover so it goes half as fast to maintain the expected duration.</item>
  58. /// <item>To fade from 0.5 to 1 with <see cref="FixedSpeed"/> would get a speed of 4 and take 0.125 seconds.
  59. /// It gets the same speed regardless of the distance to cover, so with less distance it completes faster.</item>
  60. /// </list>
  61. /// </example>
  62. ///
  63. /// <remarks>
  64. /// This was how fading worked prior to the introduction of <see cref="FadeMode"/>s in Animancer v4.0.
  65. /// </remarks>
  66. FixedDuration,
  67. /// <summary>
  68. /// If the <see cref="AnimancerNode.Weight"/> is above the <see cref="AnimancerLayer.WeightlessThreshold"/>,
  69. /// this mode will use <see cref="AnimancerLayer.GetOrCreateWeightlessState"/> to get a copy of it that is at 0
  70. /// weight so it can fade the copy in while the original fades out with all other states. This allows an
  71. /// animation to fade into itself.
  72. /// </summary>
  73. ///
  74. /// <example>
  75. /// This mode can be useful when you want to repeat an action while the previous animation is still fading out.
  76. /// For example, if you play an 'Attack' animation, it ends and starts fading back to 'Idle', and while it is
  77. /// doing so you want to start another 'Attack' with the same animation. The previous 'Attack' can't simply
  78. /// snap back to the start, so you can use this mode to create a second 'Attack' state to fade in while the old
  79. /// one fades out.
  80. /// </example>
  81. ///
  82. /// <remarks>
  83. /// Using this mode repeatedly on subsequent frames will probably have undesirable effects because it will
  84. /// create a new state each time. In such a situation you most likely want <see cref="FixedSpeed"/> instead.
  85. /// <para></para>
  86. /// This mode only works for <see cref="ClipState"/>s.
  87. /// <para></para>
  88. /// The <see href="https://kybernetik.com.au/animancer/docs/manual/blending/fading/modes">Fade Modes</see> page
  89. /// explains this mode in more detail.
  90. /// </remarks>
  91. FromStart,
  92. /// <summary>
  93. /// Like <see cref="FixedSpeed"/>, except that the fade duration is multiplied by the animation length.
  94. /// </summary>
  95. NormalizedSpeed,
  96. /// <summary>
  97. /// Like <see cref="FixedDuration"/>, except that the fade duration is multiplied by the animation length.
  98. /// </summary>
  99. NormalizedDuration,
  100. /// <summary>
  101. /// Like <see cref="FromStart"/>, except that the fade duration is multiplied by the animation length.
  102. /// </summary>
  103. NormalizedFromStart,
  104. /************************************************************************************************************************/
  105. }
  106. }