IMotion.cs 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2024 Kybernetik //
  2. using UnityEngine;
  3. namespace Animancer
  4. {
  5. /// <summary>An object with an <see cref="AverageAngularSpeed"/> and <see cref="AverageVelocity"/>.</summary>
  6. /// https://kybernetik.com.au/animancer/api/Animancer/IMotion
  7. ///
  8. public interface IMotion
  9. {
  10. /************************************************************************************************************************/
  11. /// <summary>The initial <see cref="Motion.averageAngularSpeed"/> that the created state will have.</summary>
  12. /// <remarks>The actual average can vary in states like <see cref="ManualMixerState"/>.</remarks>
  13. float AverageAngularSpeed { get; }
  14. /// <summary>The initial <see cref="Motion.averageSpeed"/> that the created state will have.</summary>
  15. /// <remarks>The actual average can vary in states like <see cref="ManualMixerState"/>.</remarks>
  16. Vector3 AverageVelocity { get; }
  17. /************************************************************************************************************************/
  18. }
  19. /// https://kybernetik.com.au/animancer/api/Animancer/AnimancerUtilities
  20. public static partial class AnimancerUtilities
  21. {
  22. /************************************************************************************************************************/
  23. /// <summary>Outputs the <see cref="Motion.averageAngularSpeed"/> or <see cref="IMotion.AverageAngularSpeed"/>.</summary>
  24. /// <remarks>Returns false if the `motion` is null or an unsupported type.</remarks>
  25. public static bool TryGetAverageAngularSpeed(object motion, out float averageAngularSpeed)
  26. {
  27. if (motion is Motion unityMotion)
  28. {
  29. averageAngularSpeed = unityMotion.averageAngularSpeed;
  30. return true;
  31. }
  32. else if (AnimancerUtilities.TryGetWrappedObject(motion, out IMotion iMotion))
  33. {
  34. averageAngularSpeed = iMotion.AverageAngularSpeed;
  35. return true;
  36. }
  37. else
  38. {
  39. averageAngularSpeed = default;
  40. return false;
  41. }
  42. }
  43. /************************************************************************************************************************/
  44. /// <summary>Outputs the <see cref="Motion.averageSpeed"/> or <see cref="IMotion.AverageVelocity"/>.</summary>
  45. /// <remarks>Returns false if the `motion` is null or an unsupported type.</remarks>
  46. public static bool TryGetAverageVelocity(object motion, out Vector3 averageVelocity)
  47. {
  48. if (motion is Motion unityMotion)
  49. {
  50. averageVelocity = unityMotion.averageSpeed;
  51. return true;
  52. }
  53. else if (AnimancerUtilities.TryGetWrappedObject(motion, out IMotion iMotion))
  54. {
  55. averageVelocity = iMotion.AverageVelocity;
  56. return true;
  57. }
  58. else
  59. {
  60. averageVelocity = default;
  61. return false;
  62. }
  63. }
  64. /************************************************************************************************************************/
  65. }
  66. }