public void OnSystemTimerFinishes(object state, System.Timers.ElapsedEventArgs e) { OpenTibiaUnity.GameManager.InvokeOnMainThread(() => { _timerEvent.Invoke(state, e); }); }
public void Increment() { // make sure the timer can run if (_currentTime >= _duration) { return; } // update and bound _currentTime _currentTime = Mathf.Min(_currentTime + Time.deltaTime, _duration); if (_currentTime >= _duration) { // check if looping if (_looping) { // decrement the duration and signal iteration _currentTime -= _duration; _onIterate.Invoke(); } else { _currentTime = _duration; // bound to duration } } // signal changed event _onUpdate.Invoke(_currentTime); _onProgress.Invoke(Progress); // check if finished if (Progress == 1.0f) { _onFinish.Invoke(); } }
/// <summary> /// タイマー動作中の動作 /// </summary> private void OnElapsed_TimersTimer(object sender, ElapsedEventArgs e) { if (_timerValue.Minute > MinTimerValue && _timerValue.Second == MinTimerValue) { // 1分減らして59秒にする _timerValue.Minute -= 1; _timerValue.Second = MaxTimerValue; } else { // 1秒減らす _timerValue.Second -= 1; } // UIに反映(別スレッドなので、Dispatcherを利用) Application.Current.Dispatcher.Invoke(() => { TimerEvent?.Invoke(_timerValue); }); // どちらも0になった場合はタイマー終了 if (_timerValue.Minute != MinTimerValue || _timerValue.Second != MinTimerValue) { return; } // タイマーを終了 _timerCount.Stop(); _timerCount.Dispose(); _timerCount = null; // ドミソミドと音を鳴らす BeepSound(); }
void OnUpdate() { onUpdate.Invoke(this); if (callbackUpdate != null) { callbackUpdate(this); } }
void OnTriggerEnter(Collider collision) { if (!started && collision.gameObject == toCheckFor) { startTimer.Invoke(); started = true; } }
// Update is called once per frame void Update() { secondsElapsed += Time.deltaTime; int minutes = (int)secondsElapsed / 60; int seconds = (int)secondsElapsed % 60; timerEvent.Invoke($"{minutes}:{seconds:00}"); }
//終了時に呼び出される void OnCompleteCallback() { onComplete.Invoke(this); if (callbackComplete != null) { callbackComplete(this); } callbackComplete = null; }
public void StartTimer() { IsPlaying = true; if (ElapsedGameTime == 0) { onStarted.Invoke(); } }
/// <summary> /// Event generating method /// </summary> public void Start() { timer.Enabled = true; while (timer.Enabled) { } TimerEvent?.Invoke(this, "Alarm!"); }
//更新時呼び出される void OnUpdate(WaitTimer timer) { this.Time = timer.Time; this.Time01 = timer.Time01; onUpdate.Invoke(this); if (callbackUpdate != null) { callbackUpdate(this); } }
//終了時に呼び出される void OnCompleteCallback() { IsPlaying = false; onComplete.Invoke(this); if (callbackComplete != null) { callbackComplete(this); } callbackComplete = null; }
private void Run(object state) { while (IsLess(DateTime.Now, _dateTime)) { Thread.Sleep(10); } TimerEventArgs eventArgs = new TimerEventArgs(DateTime.Now, "DateTime.Now"); TimerEvent.Invoke(this, eventArgs); }
private void Wait(object state) { while (DateTime.Now < this.dateTime) { Thread.Sleep(100); } TimerEventArgs timerEventArgs = new TimerEventArgs(DateTime.Now, "ring ring!"); TimerEvent.Invoke(this, timerEventArgs); }
private IEnumerator RunTimer(Action onCompleted) { isRunning = true; while (TimeLeft > 0) { OnTimerTick?.Invoke(TimeLeft); yield return(new WaitForSeconds(1)); TimeLeft--; } onCompleted(); isRunning = false; }
/// <summary> /// Update is called once per frame /// </summary> void Update() { // update timer and check for finished if (running) { elapsedSeconds += Time.deltaTime; if (elapsedSeconds >= totalSeconds) { running = false; timerEvent.Invoke(); } } }
/// <summary> /// ゲーム時間処理 /// </summary> private IEnumerator WaitUntilTimeOver() { onGameStart.Invoke((int)remainingGameTime); while (remainingGameTime > 0f) { var n = (int)remainingGameTime; remainingGameTime = Mathf.Max(0f, remainingGameTime - Time.deltaTime); if ((int)remainingGameTime != n) // 残り時刻の整数部が変化した。 { onTimeUpdate.Invoke((int)remainingGameTime); } yield return(null); } remainingGameTime = 0f; }
/// <summary> /// タイマーをリセット /// </summary> public void ResetTimer() { // タイマーが動作中の場合 if (_timerCount != null) { // タイマーを停止 _timerCount.Stop(); _timerCount.Dispose(); _timerCount = null; } // タイマーを最小値に戻す _timerValue.Minute = MinTimerValue; _timerValue.Second = MinTimerValue; TimerEvent?.Invoke(_timerValue); }
// Update is called once per frame void Update() { if (inited) { if (!paused) { timer += Time.deltaTime; if (timer >= totalTime) { Finish(); } else { OnTick?.Invoke(); } } } }
private void FixedUpdate() { if (!IsPlaying) { return; } ElapsedGameTime += Time.deltaTime * TimeScale; if (ElapsedGameTime - _secondsTimer >= 1) { _secondsTimer = Mathf.FloorToInt(ElapsedGameTime); onTick.Invoke(); } if (ElapsedGameTime >= TotalGameTime) { TimerCompleted(); } }
private void Update() { timeSoFar += Time.deltaTime; if (timers.Length == 0) { return; } if (timeSoFar < totalTime) { timers[currentSelection].ChangeTimer(timeSoFar / totalTime); } else { timers[currentSelection].ChangeTimer(1); if (currentSelection + 1 < timers.Length) { currentSelection++; timeSoFar = 0; onChangeImage.Invoke(currentSelection); } } }
static private void TimerUp(object value) { systemTimeMS += 50; TimerEvent?.Invoke(); }
private void InitGameTimer() { remainingGameTime = gameTime; onTimeUpdate.Invoke((int)gameTime); }
//遅延を考慮した開始時に呼び出される void OnStart(WaitTimer timer) { onStart.Invoke(this); }
protected virtual void RaiseTimerEvent() { TimerEvent?.Invoke(this, new TimerEventArgs()); Timer.UnregisterHook(this); }
public string OnTimerUpdateInvoke(TimeUpdateInfo t) { OnTimerUpdate.Invoke(OnTimerUpdateKey, t); return(OnTimerUpdateKey); }
public void StopTimer() { IsPlaying = false; ResetTimer(); onStopped.Invoke(); }
public void ResumeTimer() { IsPlaying = true; onResumed.Invoke(); }
public void PauseTimer() { IsPlaying = false; onPaused.Invoke(); }
public void OnTimerEvent(ISendResponse sendResponse) { TimerEvent?.Invoke(this, new TimerEventArgs(sendResponse)); }
private void TimerCompleted() { IsPlaying = false; onCompleted.Invoke(); }