AnimancerState.ExpectFade.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2024 Kybernetik //
  2. namespace Animancer
  3. {
  4. /// https://kybernetik.com.au/animancer/api/Animancer/AnimancerState
  5. public abstract partial class AnimancerState
  6. {
  7. /************************************************************************************************************************/
  8. #if UNITY_ASSERTIONS
  9. private static bool _SkipNextExpectFade;
  10. private bool _ExpectFade;
  11. #endif
  12. /************************************************************************************************************************/
  13. /// <summary>[Internal] Sets a flag for <see cref="OptionalWarning.ExpectFade"/>.</summary>
  14. [System.Diagnostics.Conditional(Strings.Assertions)]
  15. public static void SetExpectFade(AnimancerState state, float fadeDuration)
  16. {
  17. #if UNITY_ASSERTIONS
  18. state._ExpectFade = fadeDuration > 0;
  19. #endif
  20. }
  21. /************************************************************************************************************************/
  22. /// <summary>[Internal] Sets the next <see cref="AssertNotExpectingFade"/> call to be skipped.</summary>
  23. [System.Diagnostics.Conditional(Strings.Assertions)]
  24. internal static void SkipNextExpectFade()
  25. {
  26. #if UNITY_ASSERTIONS
  27. _SkipNextExpectFade = true;
  28. #endif
  29. }
  30. /************************************************************************************************************************/
  31. /// <summary>[Internal] Call when playing a `state` without a fade to check <see cref="OptionalWarning.ExpectFade"/>.</summary>
  32. [System.Diagnostics.Conditional(Strings.Assertions)]
  33. internal static void AssertNotExpectingFade(AnimancerState state)
  34. {
  35. #if UNITY_ASSERTIONS
  36. if (_SkipNextExpectFade)
  37. {
  38. _SkipNextExpectFade = false;
  39. return;
  40. }
  41. if (state._ExpectFade)
  42. {
  43. state._ExpectFade = false;// Don't log again for the same state.
  44. OptionalWarning.ExpectFade.Log(
  45. "A state was created by a transition with a non-zero Fade Duration" +
  46. " but is now being played without a fade, which may be unintentional." +
  47. " In most cases, the transition should be played so that it can properly" +
  48. " apply its settings, unlike if the state is played directly.",
  49. state.Graph?.Component);
  50. }
  51. #endif
  52. }
  53. /************************************************************************************************************************/
  54. }
  55. }