private void OnTimerFinish() { if (TimerFinished != null) { TimerFinished.Invoke(_groupMember, new EventArgs()); } }
/* * Desc: Updates the timer * Keeps track of how many seconds have passed * Updates the LevelTimerUI display by calling its UpdateDisplay() method * Triggers the TimerFinished event if the timer has run out of time -- Stops the timer */ private void UpdateTimer() { _secondsSinceStart++; // Update the display every second _levelTimerUI.UpdateDisplay(_secondsSinceStart); if (_secondsSinceStart != LevelTimeInSeconds) { return; } TimerFinished?.Invoke(); StopTimer(); }
private void OnTimerElapsed(object sender, ElapsedEventArgs e) { _timeSinceStart += TimerInterval; if (_timeSinceStart >= Period) { _timeSinceStart = 0; TimerFinished?.Invoke(this, e); } DrawProgress(); }
// Update is called once per frame void Update() { if (running) { time -= Time.deltaTime; if (time <= 0) { time = 0; TimerFinished?.Invoke(); } Display(); } }
public void Update() { if (!isActive) { return; } if (Time.time >= startTime + duration) { TimerFinished?.Invoke(); if (!isRepeatitive) { Stop(); } Reset(); } }
/// <summary> /// Start the <see langword="timer" /> /// </summary> public void Start() { if (IsBusy) { throw new InvalidOperationException("Unable to start timer: it is already running"); } IsBusy = true; RemainingSeconds = Seconds; TimerStarted?.Invoke(this); for (var i = 0; i < Seconds; i++) { RemainingSeconds = Seconds - i - 1; Thread.Sleep(1000); TimerTick?.Invoke(this); } TimerFinished?.Invoke(this); IsBusy = false; }
/// <inheritdoc /> public void Update(GameTime gameTime) { if (!_enabled) { return; } _elapsedTime += gameTime.DeltaTimeMS; if (_elapsedTime >= TimerTick) { _elapsedTime -= TimerTick; TimerTicked?.Invoke(this); if (_maxIterations > 0 && ++CurrentIteration >= _maxIterations) { _enabled = false; TimerFinished?.Invoke(this); } } }
void Update() { if (_running) { _elapsedSeconds += Time.deltaTime; if (EventTickSeconds > 0f) { _eventTickAcc += Time.deltaTime; if (_eventTickAcc >= EventTickSeconds) { _eventTickAcc -= EventTickSeconds; TimerTick?.Invoke(TimedModifier); } } if (_elapsedSeconds >= _totalSeconds) { _running = false; TimerFinished?.Invoke(TimedModifier, this); } } }
//the coroutine thats actually run private IEnumerator StartCountdownCoroutine(float startValue, float waitForDelay, float countDownBy, TimerElapsedCallback t, TimerFinished tf) { Debug.Log("StartCountdownCoroutine"); //stopwatch to track time elapsed System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); while (startValue > 0) { sw.Start(); yield return(new WaitForSeconds(waitForDelay)); //update 'time-remaining' startValue -= countDownBy; sw.Stop(); //callback for interval t?.Invoke(sw.ElapsedMilliseconds); } //callback for end of timer tf?.Invoke(); Debug.Log("Timer finished " + sw.ElapsedMilliseconds); }
//start timer with full customisable public void StartTimer(float startValue, float waitForDelay, float countDownBy, TimerElapsedCallback t, TimerFinished tf) { Debug.Log("StartTimer2"); coroutine = StartCoroutine(StartCountdownCoroutine(startValue, waitForDelay, countDownBy, t, tf)); }
//start timer for seconds with default parameters public void StartTimer(float delayInSeconds, TimerElapsedCallback t, TimerFinished tf) { Debug.Log("StartTimer"); coroutine = StartCoroutine(StartCountdownCoroutine(delayInSeconds, delayInSeconds, delayInSeconds, t, tf)); }
/// <summary> /// Establece la funcion que sera llamada al acabarse el tiempo /// </summary> /// <param name="method">Funcion a llamar</param> public void SetMethod(TimerFinished method) { timerFinished_ = method; }
public void AddTimerFinishedListener(TimerFinished timerFinished) { timerFinishedListeners += timerFinished; }
protected virtual void OnTimerFinished(object sender, TimerFinishedEventArgs e) { TimerFinished?.Invoke(sender, e); }
private void Start() { this.timerFinished = new TimerFinished(); AddTimerFinishedListener(Hello); }
// restablece la variable que indica la funcion a llamar private void OnDestroy() { timerFinished_ = null; }
private void MyTimerOnTimerFinished() { TimerFinished?.Invoke(this, InitialNumberSeconds); }