// UltEvents // Copyright 2020 Kybernetik // using System.Collections; using UnityEngine; namespace UltEvents { /// /// A component which encapsulates a single with a delay before its invocation. /// [AddComponentMenu(UltEventUtils.ComponentMenuPrefix + "Delayed Ult Event Holder")] [HelpURL(UltEventUtils.APIDocumentationURL + "/DelayedUltEventHolder")] public class DelayedUltEventHolder : UltEventHolder { /************************************************************************************************************************/ [SerializeField] private float _Delay; private WaitForSeconds _Wait; /// /// The number of seconds that will pass between calling and the event actually being invoked. /// public float Delay { get { return _Delay; } set { _Delay = value; _Wait = null; } } /************************************************************************************************************************/ /// Waits for seconds then calls Event.Invoke(). public override void Invoke() { if (_Delay < 0) base.Invoke(); else StartCoroutine(DelayedInvoke()); } /************************************************************************************************************************/ private IEnumerator DelayedInvoke() { if (_Wait == null) _Wait = new WaitForSeconds(_Delay); yield return _Wait; base.Invoke(); } /************************************************************************************************************************/ } }