Пример #1
0
        /// <summary>
        /// Method for setting up the timer
        /// </summary>
        /// <param name="timeInSeconds">Time for timing in seconds</param>
        /// <param name="message">Message for sending to subscribers of <see cref="TimerEnded"/> event</param>
        public void StartTimer(int timeInSeconds, string message)
        {
            if (timeInSeconds == 0)
            {
                throw new ArgumentException($"{nameof(timeInSeconds)} can't be 0");
            }

            Start(timeInSeconds);

            TimerEnded?.Invoke(this, new TimerEventArgs(message));
        }
Пример #2
0
 public static void StartTimer() //Метод, который должен вызываться в FixUpdate
 {
     if (_timer >= 0)
     {
         _timer -= Time.deltaTime;
         TimerStarted?.Invoke($"Время осталось: {Mathf.Round(_timer).ToString()}"); //Событие при старте таймера.
     }
     else
     {
         TimerStatus();
         TimerEnded?.Invoke(String.Empty); //Событие при остановке таймера.
     }
 }
Пример #3
0
        public void UpdateTimer()
        {
            _elapsedTime++;

            if (_elapsedTime <= _currentLevelConfig.time + GameManager.TIME_BEFORE_LEAVE)
            {
                TimerUpdated?.Invoke(this, _elapsedTime);
            }
            else
            {
                TimerEnded?.Invoke(this, _elapsedTime);
            }
        }
Пример #4
0
    public void UpdateTimer()
    {
        _elapsedTime++;

        if (_elapsedTime <= GameManager.TIME_BEFORE_END)
        {
            TimerUpdated?.Invoke(this, _elapsedTime);
        }
        else
        {
            TimerEnded?.Invoke(this, _elapsedTime);
        }
    }
Пример #5
0
 private IEnumerator RunTimer(bool isClockwise, Action<float> callBack = null)
 {
     _circleImage.sprite = _runningSptite;
     while (_watch <= time)
     {
         _watch += Time.deltaTime;
         _circleImage.fillAmount = isClockwise ? _watch / time : 1 - _watch / time;
         callBack?.Invoke(_watch);
         yield return null;
     }
     TimerEnded?.Invoke();
     _circleImage.fillAmount =isClockwise ? 1 : 0;
     _circleImage.sprite = _readySprite;
 }
Пример #6
0
        /// <summary>
        /// Method subscribed to Elapsed event of System.Timers.
        /// </summary>
        /// <param name="source">Sender of an event.</param>
        /// <param name="e">Event args.</param>
        private void OnTimedEvent(object sender, ElapsedEventArgs e)
        {
            timerStart = timerStart.AddSeconds(-1);
            Console.Write("Time till event invoke: {0:HH}:{0:mm}:{0:ss}", timerStart);

            if (timerStart == DateTime.MinValue)
            {
                timer.Elapsed -= OnTimedEvent;
                Console.WriteLine();
                TimerEnded.Invoke(this, new ClockEventArgs(seconds, "Timer ended"));
            }

            Console.SetCursorPosition(0, Console.CursorTop);
        }
Пример #7
0
        private void OnTick(object sender, EventArgs e)
        {
            double elapsedTime = stopwatch.ElapsedMilliseconds / 1000.0;

            if (elapsedTime >= duration)
            {
                dispatcherTimer.Stop();
                TimerEnded?.Invoke();
            }
            else
            {
                TimerTicked?.Invoke(duration - elapsedTime);
            }
        }
Пример #8
0
        private void Timer_Tick(object sender, object e)
        {
            DateTime currentTime = DateTime.UtcNow;
            TimeSpan timeElapsed = currentTime - lastTime;

            lastTime     = DateTime.UtcNow;
            ticksPassed += timeElapsed.Ticks;
            Debug.WriteLine($"Ticks Passed: {ticksPassed}");
            if (ticksPassed > ticksToPass)
            {
                timer.Stop();
                TimerEnded?.Invoke(sender, EventArgs.Empty);
            }
            else
            {
                TimeSpan totalTimeElapsed = TimeSpan.FromTicks(ticksPassed);
                TimerTicked?.Invoke(this, totalTimeElapsed);
            }
        }
Пример #9
0
 protected virtual void OnTimerEnded()
 {
     TimerEnded?.Invoke(this, EventArgs.Empty);
 }
Пример #10
0
 private void OnRaiseTimerEndedEvent()
 {
     TimerEnded?.Invoke(this, new TimerEventArgs(true));
 }
 private void OnTimerEnded()
 {
     TimerEnded?.Invoke();
 }