1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- 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));
- }
- 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();
- }
- }
|