River Jiang
2020-10-22 6b3cb63ae5d3f3c4b196a236b08fc3a4e8dfd5c6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System;
 
namespace Core.Utilities
{
    /// <summary>
    /// A Timer that repeats until it is stopped - the callback is fired at the end of every repetition
    /// </summary>
    public class RepeatingTimer : Timer
    {
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="time">The time of one cycle</param>
        /// <param name="onElapsed">The event fired at the end of each cycle</param>
        public RepeatingTimer(float time, Action onElapsed = null)
            : base(time, onElapsed)
        {
        }
 
        /// <summary>
        /// Ticks and does not turn off on elapse
        /// </summary>
        /// <param name="deltaTime">The change in time since last tick</param>
        /// <returns>false always to ensure that the timer is not automatically removed</returns>
        public override bool Tick(float deltaTime)
        {
            if (AssessTime(deltaTime))
            {
                Reset();
            }
 
            return false;
        }
    }
}