internal bool Trigger() { if (TriggerLeftInMS <= 0) { if (m_Category == TimerTaskCategory.End) { m_OnEndEvent?.Invoke(m_UserData); return(true); } else if (m_Category == TimerTaskCategory.Interval) { m_OnIntervalEvent?.Invoke(m_UserData); TriggerLeftInMS = m_IntervalInMS; return(false); } else if (m_Category == TimerTaskCategory.IntervalAndEnd) { m_OnIntervalEvent?.Invoke(m_UserData); m_TotalInMS -= m_IntervalInMS; if (m_TotalInMS <= 0) { m_OnEndEvent?.Invoke(m_UserData); return(true); } else { if (m_TotalInMS >= m_IntervalInMS) { TriggerLeftInMS = m_IntervalInMS; return(false); } else { m_Category = TimerTaskCategory.End; TriggerLeftInMS = m_TotalInMS; return(false); } } } else { DebugLog.Error("Timer error"); return(true); } } else { return(false); } }
/// <summary> /// Start the timer with a specific duration. /// </summary> /// <param name="newDuration">The new timer duration.</param> public virtual void StartTimer(float newDuration) { nextDuration = newDuration; startTime = Time.time; running = true; onTimerStarted.Invoke(); }
// Called every frame protected virtual void Update() { if (delayRunning) { if (Time.time - delayStartTime >= nextDelay) { delayRunning = false; StartTimer(); } } // If it's running, check if the timer has finished. if (running) { if (Time.time - startTime >= nextDuration) { running = false; onTimerFinished.Invoke(); } else { DisplayUpdate(); } } }
private void TimerElapsed(object sender, ElapsedEventArgs e) { lock (_lockObject) { _timer.Stop(); _timer.Dispose(); int id = First.Id; TimerEventHandler.Invoke(id); } }
/// <summary> /// Update the specified castTime. /// </summary> /// <param name="time">游戏运行到现在的时间</param> public void Update(float time) { if (IsActive) { //Debug.Log("time:"+time+" nextActive:"+nextActive); if (time > nextActive) { nextActive = time + Duration; //IsActive must set false before tick() , cause if u want to restart in the tick() , IsActive would be reset to fasle . //IsActive = false; Tick.Invoke(); } } }
/// <summary> /// Passing subscribers the flight that need to enter the base station. /// </summary> /// <param name="flight"></param> private void OnTimerElapsed(FlightModel flight) { TimerEventHandler?.Invoke(flight); }