private int f_RegEventForTeam(float fDelayTime, float fRunTime, object oData, ccCallbackV2 tccCallbackV2, ccCallbackV2 tccCallbackV2Complete, bool bUsePause) { if ((tccCallbackV2 != null) && (fDelayTime >= 0f)) { //額外條件 //如果complete為空,則指定給tccCallback if (tccCallbackV2Complete == null) { tccCallbackV2Complete = tccCallbackV2; } sTimeEvent tClass1 = new sTimeEvent { iId = ++iKeyId, m_fDelayTime = fDelayTime, m_fSurplusTime = fRunTime, m_oData = oData, m_ccCallbackV2 = tccCallbackV2, m_ccCallbackV2Complete = tccCallbackV2Complete, m_bUsePause = bUsePause, }; _aTimeEventList.Add(tClass1); if (this.enabled == false) { this.enabled = true; } return(( int )tClass1.iId); } return(-99); }
/// <summary> /// 至少要給予m_fSurplusTime、m_ccCallback 否則將不會執行, /// </summary> /// <param name="tsTimeEvent">給予一個sTimeEvent類別的物件 /// 可使用ccUpdateEvent中的m_sTimeEvent去new出來</param> /// <returns></returns> public int f_RegEvent(sTimeEvent tsTimeEvent) { return(this.f_RegEventForTeam(tsTimeEvent.m_fDelayTime, tsTimeEvent.m_fSurplusTime, tsTimeEvent.m_oData, tsTimeEvent.m_ccCallbackV2, tsTimeEvent.m_ccCallbackV2Complete, tsTimeEvent.m_bUsePause)); }
private void Update() { if (this._aTimeEventList.Count > 0) { for (int i = 0; i < this._aTimeEventList.Count; i++) { this._sTimeEvent = this._aTimeEventList[i]; if (!this._sTimeEvent.m_bUsePause || !this.paused) { if (this._sTimeEvent.m_bInit == false) { this._sTimeEvent.m_bInit = true; return; } if (this._sTimeEvent.m_fDelayTime > 0) { this._sTimeEvent.m_fDelayTime -= Time.deltaTime; } else { this._sTimeEvent.m_fSurplusTime -= Time.deltaTime; if (this._sTimeEvent.m_fSurplusTime > 0f) { if (this._sTimeEvent.m_ccCallbackV2 == null) { this._aWaitDelEvent.Add(this._sTimeEvent); } else { this._sTimeEvent.m_ccCallbackV2(this._sTimeEvent.m_oData, this._sTimeEvent.m_fSurplusTime); } } else { this._aWaitDelEvent.Add(this._sTimeEvent); if (this._sTimeEvent.m_ccCallbackV2Complete != null) { this._sTimeEvent.m_ccCallbackV2Complete(this._sTimeEvent.m_oData, 0f); } } } } } if (this._aWaitDelEvent.Count > 0) { for (int i = 0; i < _aWaitDelEvent.Count; i++) { this._aTimeEventList.Remove(_aWaitDelEvent[i]); } this._aWaitDelEvent.Clear(); } } else { this.enabled = false; } }
/// <summary> /// 增加指定ID的事件目前秒數,可為負數,如果相加後小於等於0,則事件結束 /// </summary> /// <param name="iEventID">該時間事件的ID</param> /// <param name="fSecond">增加的秒數(float),可為負的(會相減),如果相減後低於0則直接完成計時</param> /// <returns></returns> public void f_AddTimeEventExcuteCount(int iEventID, float fSecond) { sTimeEvent _sTimeEvent = _aTimeEventList.Find(e => e.iId == iEventID); if (_sTimeEvent != null) { _sTimeEvent.m_fSurplusTime += fSecond; } else { Debug.Log("ccUpdateEvent : f_AddTimeEventExcuteCount 找不到此 " + iEventID + " 事件"); } }
/// <summary> /// 設定指定ID的事件目前秒數,可為負數,如果設定後秒數小於等於0,則事件結束 /// </summary> /// <param name="iEventID">該時間事件的ID</param> /// <param name="fSecond">設定的秒數(float),可為負的,如果設定後低於0則直接完成計時</param> /// <returns></returns> public void f_SetTimeEventExcuteTime(int iEventID, float fSecond) { sTimeEvent _sTimeEvent = _aTimeEventList.Find(e => e.iId == iEventID); if (_sTimeEvent != null) { _sTimeEvent.m_fSurplusTime = fSecond; } else { Debug.Log("ccTimeEvent : f_GetTimeEventExcuteTime 找不到此 " + iEventID + " 事件"); } }
/// <summary> /// 取得指定ID的事件目前剩餘的秒數 /// 找不到時,回傳float類型 數值0f /// </summary> /// <param name="iEventID"></param> /// <returns></returns> public float f_GetTimeEventExcuteCount(int iEventID) { sTimeEvent _sTimeEvent = _aTimeEventList.Find(e => e.iId == iEventID); if (_aTimeEventList != null) { return(_sTimeEvent.m_fSurplusTime); } else { Debug.Log("f_GetTimeEventExcuteCount 找不到此 iEventID 事件"); return(0f); } }
/// <summary> /// 取得指定ID的事件目前剩餘的執行時間 /// 找不到時,回傳float類型 數值 -99 /// </summary> /// <param name="iEventID"></param> /// <returns></returns> public float f_GetTimeEventExcuteTime(int iEventID) { sTimeEvent _sTimeEvent = _aTimeEventList.Find(e => e.iId == iEventID); if (_sTimeEvent != null) { return(_sTimeEvent.iExcuteCount * this._fDelayTime); } else { Debug.Log("ccTimeEvent : f_GetTimeEventExcuteTime 找不到此 " + iEventID + " 事件"); return(-99); } }
/// <summary> /// 設定指定ID的事件執行時間 /// fSecond可為負數,如果fSecond小於等於0,則直接完成計時 /// </summary> /// <param name="iEventID">該時間事件的ID</param> /// <param name="fSecond">設定的秒數(float),可為負的(會相減),如果相減後低於0則直接完成計時, /// 4捨5入 3.05f = 31次, 3.049f = 30次 ,4捨5入取到小數點第二位</param> /// <returns></returns> public void f_SetTimeEventExcuteTime(int iEventID, float fSecond) { float fTemp = fSecond / this._fDelayTime; int _ExcCount = ccCommonClass.Round(fTemp, 0); sTimeEvent _sTimeEvent = _aTimeEventList.Find(e => e.iId == iEventID); if (_sTimeEvent != null) { _sTimeEvent.iExcuteCount = _ExcCount; } else { Debug.Log("ccTimeEvent : f_AddTimeEventExcuteCount 找不到此 " + iEventID + " 事件"); } }
private void CustomUpdate() { if (this._aTimeEventList.Count > 0) { for (int i = 0; i < this._aTimeEventList.Count; i++) { this._sTimeEvent = this._aTimeEventList[i]; if (!this._sTimeEvent.m_bUsePause || !this.paused) { this._sTimeEvent.iExcuteCount -= 1; if (this._sTimeEvent.iExcuteCount <= 0) { if (this._sTimeEvent.m_ccCallback == null) { this._aWaitDelEvent.Add(this._sTimeEvent); } else { this._sTimeEvent.m_ccCallback(this._sTimeEvent.m_oData); if (this._sTimeEvent.m_bRepeat) { float fTemp = this._sTimeEvent.m_fDelayTime / this._fDelayTime; this._sTimeEvent.iExcuteCount = ccCommonClass.Round(fTemp, 0); } else { this._aWaitDelEvent.Add(this._sTimeEvent); } } } } } if (this._aWaitDelEvent.Count > 0) { for (int i = 0; i < _aWaitDelEvent.Count; i++) { this._aTimeEventList.Remove(_aWaitDelEvent[i]); } this._aWaitDelEvent.Clear(); CheckInvokeAmount(); } } }
private int f_RegEventForTeam(float fDelayTime, bool bRePeat, object oData, ccCallback tccCallback, bool bUsePause) { if ((tccCallback != null) && (fDelayTime >= 0f)) { float fTemp = fDelayTime / _fDelayTime; sTimeEvent tClass1 = new sTimeEvent { iId = ++iKeyId, m_fDelayTime = fDelayTime, m_fSurplusTime = fDelayTime, //4捨5入 3.05f = 31次, 3.049f = 30次 ,4捨5入取到小數點第二位 iExcuteCount = ccCommonClass.Round(fTemp, 0), m_bRepeat = bRePeat, m_oData = oData, m_ccCallback = tccCallback, m_bUsePause = bUsePause }; _aTimeEventList.Add(tClass1); this.Init(); return(( int )tClass1.iId); } return(-99); }