AnimancerEvent.Parameter.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2024 Kybernetik //
  2. using UnityEngine;
  3. namespace Animancer
  4. {
  5. /// https://kybernetik.com.au/animancer/api/Animancer/AnimancerEvent
  6. partial struct AnimancerEvent
  7. {
  8. /// <summary>A non-generic interface for <see cref="Parameter{T}"/>.</summary>
  9. /// https://kybernetik.com.au/animancer/api/Animancer/IParameter
  10. public interface IParameter
  11. {
  12. /************************************************************************************************************************/
  13. /// <summary>The parameter value.</summary>
  14. object Value { get; set; }
  15. /************************************************************************************************************************/
  16. }
  17. /// <summary>
  18. /// Base class for <see cref="IInvokable"/>s which assign the <see cref="CurrentParameter"/>.
  19. /// </summary>
  20. /// <remarks>
  21. /// Inherit from <see cref="ParameterBoxed{T}"/>
  22. /// instead of this if <typeparamref name="T"/> is a value type to avoid repeated boxing costs.
  23. /// </remarks>
  24. /// https://kybernetik.com.au/animancer/api/Animancer/Parameter_1
  25. public abstract class Parameter<T> :
  26. IParameter,
  27. IInvokable
  28. {
  29. /************************************************************************************************************************/
  30. [SerializeField]
  31. private T _Value;
  32. /// <summary>[<see cref="SerializeField"/>] The serialized <typeparamref name="T"/>.</summary>
  33. public virtual T Value
  34. {
  35. get => _Value;
  36. set => _Value = value;
  37. }
  38. /// <inheritdoc/>
  39. object IParameter.Value
  40. {
  41. get => _Value;
  42. set => _Value = (T)value;
  43. }
  44. /// <inheritdoc/>
  45. public virtual void Invoke()
  46. {
  47. CurrentParameter = _Value;
  48. Current.InvokeBoundCallback();
  49. }
  50. /************************************************************************************************************************/
  51. }
  52. }
  53. }