AnimancerEvent.InvokerDynamic.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2024 Kybernetik //
  2. using System.Runtime.CompilerServices;
  3. using UnityEngine;
  4. namespace Animancer
  5. {
  6. /// https://kybernetik.com.au/animancer/api/Animancer/AnimancerEvent
  7. partial struct AnimancerEvent
  8. {
  9. /// <summary>Executes <see cref="Invoker.InvokeAllAndClear"/> after animations in the Dynamic Update cycle.</summary>
  10. /// https://kybernetik.com.au/animancer/api/Animancer/InvokerDynamic
  11. [AnimancerHelpUrl(typeof(InvokerDynamic))]
  12. [AddComponentMenu("")]// Singleton creates itself.
  13. public class InvokerDynamic : Invoker
  14. {
  15. /************************************************************************************************************************/
  16. private static InvokerDynamic _Instance;
  17. /// <summary>Creates the singleton instance.</summary>
  18. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  19. public static InvokerDynamic Initialize()
  20. => AnimancerUtilities.InitializeSingleton(ref _Instance);
  21. /************************************************************************************************************************/
  22. /// <summary>Should this system execute events?</summary>
  23. /// <remarks>If disabled, this system will not be re-enabled automatically.</remarks>
  24. public static bool Enabled
  25. {
  26. get => _Instance != null && _Instance.enabled;
  27. set
  28. {
  29. if (value)
  30. {
  31. Initialize();
  32. _Instance.enabled = true;
  33. }
  34. else if (_Instance != null)
  35. {
  36. _Instance.enabled = false;
  37. }
  38. }
  39. }
  40. /************************************************************************************************************************/
  41. /// <summary>After animation update with dynamic timestep.</summary>
  42. protected virtual void LateUpdate()
  43. {
  44. InvokeAllAndClear();
  45. }
  46. /************************************************************************************************************************/
  47. }
  48. }
  49. }