ITransitionDetailed.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // Animancer // https://kybernetik.com.au/animancer // Copyright 2022 Kybernetik //
  2. using UnityEngine;
  3. namespace Animancer
  4. {
  5. /// <summary>An <see cref="ITransition"/> with some additional details (mainly for the Unity Editor GUI).</summary>
  6. /// <remarks>
  7. /// Documentation: <see href="https://kybernetik.com.au/animancer/docs/manual/transitions">Transitions</see>
  8. /// </remarks>
  9. /// https://kybernetik.com.au/animancer/api/Animancer/ITransitionDetailed
  10. ///
  11. public interface ITransitionDetailed : ITransition
  12. {
  13. /************************************************************************************************************************/
  14. /// <summary>Can this transition create a valid <see cref="AnimancerState"/>?</summary>
  15. bool IsValid { get; }
  16. /// <summary>What will the value of <see cref="AnimancerState.IsLooping"/> be for the created state?</summary>
  17. bool IsLooping { get; }
  18. /// <summary>The <see cref="AnimancerState.NormalizedTime"/> to start the animation at.</summary>
  19. /// <remarks><see cref="float.NaN"/> allows the animation to continue from its current time.</remarks>
  20. float NormalizedStartTime { get; set; }
  21. /// <summary>The maximum amount of time the animation is expected to take (in seconds).</summary>
  22. /// <remarks>The actual duration can vary in states like <see cref="MixerState"/>.</remarks>
  23. float MaximumDuration { get; }
  24. /// <summary>The <see cref="AnimancerNode.Speed"/> to play the animation at.</summary>
  25. float Speed { get; set; }
  26. /************************************************************************************************************************/
  27. }
  28. /// https://kybernetik.com.au/animancer/api/Animancer/AnimancerUtilities
  29. public static partial class AnimancerUtilities
  30. {
  31. /************************************************************************************************************************/
  32. /// <summary>Returns the <see cref="ITransitionDetailed.IsValid"/> with support for <see cref="IWrapper"/>.</summary>
  33. public static bool IsValid(this ITransition transition)
  34. {
  35. if (transition == null)
  36. return false;
  37. if (TryGetWrappedObject(transition, out ITransitionDetailed detailed))
  38. return detailed.IsValid;
  39. return true;
  40. }
  41. /************************************************************************************************************************/
  42. /// <summary>Outputs the <see cref="Motion.isLooping"/> or <see cref="ITransitionDetailed.IsLooping"/>.</summary>
  43. /// <remarks>Returns false if the `motionOrTransition` is null or an unsupported type.</remarks>
  44. public static bool TryGetIsLooping(object motionOrTransition, out bool isLooping)
  45. {
  46. if (motionOrTransition is Motion motion)
  47. {
  48. isLooping = motion.isLooping;
  49. return true;
  50. }
  51. else if (TryGetWrappedObject(motionOrTransition, out ITransitionDetailed transition))
  52. {
  53. isLooping = transition.IsLooping;
  54. return true;
  55. }
  56. else
  57. {
  58. isLooping = false;
  59. return false;
  60. }
  61. }
  62. /************************************************************************************************************************/
  63. /// <summary>Outputs the <see cref="AnimationClip.length"/> or <see cref="ITransitionDetailed.MaximumDuration"/>.</summary>
  64. /// <remarks>Returns false if the `motionOrTransition` is null or an unsupported type.</remarks>
  65. public static bool TryGetLength(object motionOrTransition, out float length)
  66. {
  67. if (motionOrTransition is AnimationClip clip)
  68. {
  69. length = clip.length;
  70. return true;
  71. }
  72. else if (TryGetWrappedObject(motionOrTransition, out ITransitionDetailed transition))
  73. {
  74. length = transition.MaximumDuration;
  75. return true;
  76. }
  77. else
  78. {
  79. length = 0;
  80. return false;
  81. }
  82. }
  83. /************************************************************************************************************************/
  84. }
  85. }