// Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2024 Kybernetik // using System.Collections; using System.Runtime.CompilerServices; using UnityEngine; namespace Animancer { /// https://kybernetik.com.au/animancer/api/Animancer/AnimancerEvent partial struct AnimancerEvent { /// Executes after animations in the Fixed Update cycle. /// https://kybernetik.com.au/animancer/api/Animancer/InvokerFixed [AnimancerHelpUrl(typeof(InvokerFixed))] [AddComponentMenu("")]// Singleton creates itself. public class InvokerFixed : Invoker { /************************************************************************************************************************/ private static InvokerFixed _Instance; /// Creates the singleton instance. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static InvokerFixed 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; } } } /************************************************************************************************************************/ /// A cached instance of . public static readonly WaitForFixedUpdate WaitForFixedUpdate = new(); /************************************************************************************************************************/ /// Starts the coroutine. protected virtual void OnEnable() => StartCoroutine(LateFixedUpdate()); /************************************************************************************************************************/ /// After animation update with fixed timestep. private IEnumerator LateFixedUpdate() { while (true) { yield return WaitForFixedUpdate; InvokeAllAndClear(); } } /************************************************************************************************************************/ } } }