/// <summary> /// 获取游戏时间 /// </summary> /// <param name="tTimeType"></param> /// <returns></returns> public static float GetGameTimeNow(TUnityTimeType tTimeType) { float fTimeNow = 0; if (tTimeType == TUnityTimeType.enGameTime) { fTimeNow = UnityEngine.Time.time; } if (tTimeType == TUnityTimeType.enPhysicalTime) { fTimeNow = UnityEngine.Time.realtimeSinceStartup; } return(fTimeNow); }
/// <summary> /// 清理 /// </summary> public void Clear() { m_uTimerId = 0; m_fStartTime = 0; m_fLifeTimeRemain = 0; m_fKeepDecimal = 0; m_fIntervalTime = 0; m_handleTriggerAction = null; m_handleIntervalAction = null; m_objTriggerParam = null; m_objIntervalParam = null; m_fLastUpdateTime = 0; m_TimeType = TUnityTimeType.enGameTime; }
/// <summary> /// 注册 /// </summary> /// <param name="fTrigger"></param> /// <param name="handleAction"></param> /// <param name="objTrigger"></param> public void Register(UInt32 uId, float fCountDownTime, HandleObjectAction handleOnTimeUp, System.Object objTimeUpParam, TUnityTimeType tTimeType, float fStartDelay) { float fTimeNow = CTimeAlgorithm.GetGameTimeNow(tTimeType); m_uTimerId = uId; m_fLifeTimeRemain = fCountDownTime; m_handleTriggerAction = handleOnTimeUp; m_objTriggerParam = objTimeUpParam; m_fStartTime = fTimeNow + fStartDelay; }
/// <summary> /// 注册倒计时,带间隔时间触发 /// </summary> /// <param name="fCountDownTime"></param> /// <param name="handleOnTimeUp"></param> /// <param name="fInterval"></param> /// <param name="handleOnIntervalTrigger"></param> /// <param name="objTimeUpParam"></param> /// <param name="objInvtervalTriggerParam"></param> /// <param name="tTimeType"></param> /// <param name="fStartDelay"></param> /// <returns></returns> public UInt32 RegisterCountDownTimer(float fCountDownTime, HandleObjectAction handleOnTimeUp, float fInterval, HandleObjectAction handleOnIntervalTrigger, System.Object objTimeUpParam = null, System.Object objInvtervalTriggerParam = null, TUnityTimeType tTimeType = TUnityTimeType.enGameTime, float fStartDelay = 0) { CTimer timer = m_TimerPool.RentObject() as CTimer; if (timer == null) { return(0); } UInt32 uId = m_uNextTimerID; m_uNextTimerID += 1; timer.Register(uId, fCountDownTime, handleOnTimeUp, fInterval, handleOnIntervalTrigger, objTimeUpParam, objInvtervalTriggerParam, tTimeType, fStartDelay); m_TimerList.Add(timer); return(uId); }