using UnityEngine;
using System.Collections;
/// 时间控制器
public class TimerManager : MonoBehaviour
{
#region 单利
/// 单利静态引用
private static TimerManager _instance;
/// 单利 返回 常驻内存的 PrefabManger 对象,只会实例化一次
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();
}
}
return _instance;
}
}
#endregion
public delegate void DelegateWaitCallBack(object paramObj);
/// 延时执行某个函数
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));
}
/// 延迟函数
IEnumerator StartWait(int waitTiame, DelegateWaitCallBack waitCallBack, object paramObj)
{
yield return new WaitForSeconds((float)waitTiame / 1000f);
waitCallBack(paramObj);
waitCallBack = null;
}
}