12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- using System;
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- public class DelayCall : MonoBehaviour
- {
- #region Config
- public static DelayCall Instance
- {
- get
- {
- if (instance == null)
- {
- GameObject go = new GameObject("DelayCall");
- instance = go.AddComponent<DelayCall>();
- DontDestroyOnLoad(go);
- }
- return instance;
- }
- set { instance = value; }
- }
- private static DelayCall instance;
- #endregion
- public static Coroutine Call(int delayFrame, Action action)
- {
- return Instance.StartCoroutine(EDelayCall(delayFrame, action));
- }
- public static Coroutine Call(float delayTime, Action action)
- {
- return Instance.StartCoroutine(EDelayCall(delayTime, action));
- }
- public static void stopCoroutine(Coroutine coroutine)
- {
- Instance.StopCoroutine(coroutine);
- }
- private static IEnumerator EDelayCall(int delayFrame, Action action)
- {
- int count = 0;
- while (count++ < delayFrame)
- yield return null;
- action.SafeInvoke();
- }
- private static IEnumerator EDelayCall(float delayTime, Action action)
- {
- yield return new WaitForSeconds(delayTime);
-
- action.SafeInvoke();
- }
- }
|