// Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2024 Kybernetik //
using System.Runtime.CompilerServices;
using UnityEngine;
namespace Animancer
{
    /// https://kybernetik.com.au/animancer/api/Animancer/AnimancerEvent
    partial struct AnimancerEvent
    {
        /// Executes  after animations in the Dynamic Update cycle.
        /// https://kybernetik.com.au/animancer/api/Animancer/InvokerDynamic
        [AnimancerHelpUrl(typeof(InvokerDynamic))]
        [AddComponentMenu("")]// Singleton creates itself.
        public class InvokerDynamic : Invoker
        {
            /************************************************************************************************************************/
            private static InvokerDynamic _Instance;
            /// Creates the singleton instance.
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            public static InvokerDynamic Initialize()
                => AnimancerUtilities.InitializeSingleton(ref _Instance);
            /************************************************************************************************************************/
            /// Should this system execute events?
            /// If disabled, this system will not be re-enabled automatically.
            public static bool Enabled
            {
                get => _Instance != null && _Instance.enabled;
                set
                {
                    if (value)
                    {
                        Initialize();
                        _Instance.enabled = true;
                    }
                    else if (_Instance != null)
                    {
                        _Instance.enabled = false;
                    }
                }
            }
            /************************************************************************************************************************/
            /// After animation update with dynamic timestep.
            protected virtual void LateUpdate()
            {
                InvokeAllAndClear();
            }
            /************************************************************************************************************************/
        }
    }
}