123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- using UnityEngine;
- using System.Collections;
- /// <summary>时间控制器</summary>
- public class TimerManager : MonoBehaviour
- {
- #region 单利
- /// <summary>单利静态引用</summary>
- private static TimerManager _instance;
- /// <summary>单利 返回 常驻内存的 PrefabManger 对象,只会实例化一次</summary>
- public static TimerManager Instance
- {
- get
- {
- if (_instance == null)
- {
- _instance = GameObject.FindObjectOfType(typeof(TimerManager)) as TimerManager;
- if (_instance == null)
- {
- GameObject go = new GameObject("TimerManager");
- go.transform.localPosition = Vector3.zero;
- go.transform.localScale = Vector3.one;
- DontDestroyOnLoad(go);
- _instance = go.AddComponent<TimerManager>();
- }
- }
- return _instance;
- }
- }
- #endregion
- public delegate void DelegateWaitCallBack(object paramObj);
- /// <summary>延时执行某个函数</summary>
- public void WaitCallBack(int waitTime, DelegateWaitCallBack waitCallBack)
- {
- this.StartCoroutine(StartWait(waitTime, waitCallBack, null));
- }
- public void WaitCallBack(int waitTime, DelegateWaitCallBack waitCallBack, object paramObj)
- {
- this.StartCoroutine(StartWait(waitTime, waitCallBack, paramObj));
- }
- /// <summary>延迟函数</summary>
- IEnumerator StartWait(int waitTiame, DelegateWaitCallBack waitCallBack, object paramObj)
- {
- yield return new WaitForSeconds((float)waitTiame / 1000f);
- waitCallBack(paramObj);
- waitCallBack = null;
- }
- }
|