示例#1
0
        /// <summary>
        /// Updates the time of timing by delta time.
        /// </summary>
        /// <param name="deltaTime">The delta time.</param>
        public void Tick(float deltaTime)
        {
            if (TimerState != TimerState.Running)
            {
                return;
            }

            time += deltaTime;
            if (time < Interval)
            {
                return;
            }

            CurrentCount++;

            // Raise Ticking event
            Ticking?.Invoke(this, new TimerTickingEventArgs(CurrentCount));

            if (RepeatCount != 0 && CurrentCount >= RepeatCount)
            {
                Reset();

                OnCompleted?.Invoke(this, EventArgs.Empty);
            }

            time -= Interval;
        }
示例#2
0
        /// <summary>
        /// Updates the time of timing by delta time.
        /// </summary>
        /// <param name="deltaTime">The delta time.</param>
        public void Tick(float deltaTime)
        {
            if (TimerState != TimerState.Running)
            {
                return;
            }

            time += deltaTime;

            if (time >= Interval)
            {
                CurrentCount++;

                // Raise Ticking event
                if (Ticking != null)
                {
                    Ticking.Invoke(this, new TimerTickingEventArgs(CurrentCount));
                }

                if (RepeatCount != 0 && CurrentCount >= RepeatCount)
                {
                    Reset();

                    if (Completed != null)
                    {
                        Completed.Invoke(this, EventArgs.Empty);
                    }
                }

                time = time - Interval;
            }
        }
示例#3
0
        public void Start()
        {
            CancellationTokenSource cts = _cancellationTokenSource;

            foreach (var ts in _timeSpanList)
            {
                Device.StartTimer(ts, () =>
                {
                    if (cts.IsCancellationRequested)
                    {
                        return(false);
                    }
                    var result = _callback.Invoke();
                    Ticking?.Invoke(null, EventArgs.Empty);
                    return(result);
                });
            }
        }
示例#4
0
 protected virtual void OnTicking(PlayerEventArgs e)
 {
     Ticking?.Invoke(this, e);
 }