/// <summary> /// Updates the timer's counters and values. /// </summary> private void Tick() { // Only update if running. if (TimerState != State.Running) { return; } switch (TimerMechanism) { case Mechanism.Timer: Value = Duration - (TimeUtility.GetCurrentTime(TimeMode) - StartTime) - TotalPauseTime; if (Value <= 0f) { FireElapsedEvent(); } break; case Mechanism.Stopwatch: Value = TimeUtility.GetCurrentTime(TimeMode) - StartTime - TotalPauseTime; // To determine when to elapse the stopwatch, the target is determined by // way of using an interval counter. if (Value >= Duration * _nextInterval) { _nextInterval++; FireElapsedEvent(); } break; } }
private void Update() { _offset += Speed * TimeUtility.GetCurrentTime(TimeMode); _offset.x %= 1f; _offset.y %= 1f; _material.SetTextureOffset("_MainTex", _offset); }
/// <summary> /// If currently paused, resumes the timer. /// </summary> public void Resume() { if (TimerState == State.Paused) { TimerState = State.Running; TotalPauseTime += TimeUtility.GetCurrentTime(TimeMode) - LastPauseTime; } }
/// <summary> /// If currently running, pauses the timer. /// </summary> public void Pause() { if (TimerState == State.Running) { TimerState = State.Paused; LastPauseTime = TimeUtility.GetCurrentTime(TimeMode); } }
/// <summary> /// If currently stopped, resets and then starts the timer. /// </summary> public void Start() { if (TimerState == State.Stopped) { Reset(); StartTime = TimeUtility.GetCurrentTime(TimeMode); TimerState = State.Running; } }