Float1ControllerState.cs 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // Animancer // https://kybernetik.com.au/animancer // Copyright 2022 Kybernetik //
  2. using System;
  3. using UnityEngine;
  4. namespace Animancer
  5. {
  6. /// <summary>[Pro-Only] A <see cref="ControllerState"/> which manages one float parameter.</summary>
  7. /// <remarks>
  8. /// Documentation: <see href="https://kybernetik.com.au/animancer/docs/manual/animator-controllers">Animator Controllers</see>
  9. /// </remarks>
  10. /// <seealso cref="Float2ControllerState"/>
  11. /// <seealso cref="Float3ControllerState"/>
  12. /// https://kybernetik.com.au/animancer/api/Animancer/Float1ControllerState
  13. ///
  14. public class Float1ControllerState : ControllerState
  15. {
  16. /************************************************************************************************************************/
  17. /// <summary>An <see cref="ITransition{TState}"/> that creates a <see cref="Float1ControllerState"/>.</summary>
  18. public new interface ITransition : ITransition<Float1ControllerState> { }
  19. /************************************************************************************************************************/
  20. private ParameterID _ParameterID;
  21. /// <summary>The identifier of the parameter which <see cref="Parameter"/> will get and set.</summary>
  22. public new ParameterID ParameterID
  23. {
  24. get => _ParameterID;
  25. set
  26. {
  27. _ParameterID = value;
  28. _ParameterID.ValidateHasParameter(Controller, AnimatorControllerParameterType.Float);
  29. }
  30. }
  31. /// <summary>
  32. /// Gets and sets a float parameter in the <see cref="ControllerState.Controller"/> using the
  33. /// <see cref="ParameterID"/>.
  34. /// </summary>
  35. /// <exception cref="ArgumentOutOfRangeException">The value is NaN or Infinity.</exception>
  36. public float Parameter
  37. {
  38. get => Playable.GetFloat(_ParameterID.Hash);
  39. set
  40. {
  41. AssertParameterValue(value);
  42. Playable.SetFloat(_ParameterID.Hash, value);
  43. }
  44. }
  45. /************************************************************************************************************************/
  46. /// <summary>Creates a new <see cref="Float1ControllerState"/> to play the `controller`.</summary>
  47. public Float1ControllerState(RuntimeAnimatorController controller, ParameterID parameter,
  48. params ActionOnStop[] actionsOnStop)
  49. : base(controller, actionsOnStop)
  50. {
  51. _ParameterID = parameter;
  52. _ParameterID.ValidateHasParameter(controller, AnimatorControllerParameterType.Float);
  53. }
  54. /// <summary>Creates a new <see cref="Float1ControllerState"/> to play the `controller`.</summary>
  55. public Float1ControllerState(RuntimeAnimatorController controller, ParameterID parameter)
  56. : this(controller, parameter, null)
  57. { }
  58. /************************************************************************************************************************/
  59. /// <inheritdoc/>
  60. public override int ParameterCount => 1;
  61. /// <inheritdoc/>
  62. public override int GetParameterHash(int index) => _ParameterID;
  63. /************************************************************************************************************************/
  64. }
  65. }