Class Timer
- Namespace
- Luny
- Assembly
- Luny.dll
A stateful manager for a countdown or count-up. Supports pausing, time-scaling, and auto-repeat.
public sealed class Timer
- Inheritance
-
objectTimer
Constructors
Timer(double)
Creates a new timer with duration in seconds.
public Timer(double duration)
Parameters
durationdouble
Properties
AutoRepeat
public bool AutoRepeat { get; set; }
Property Value
- bool
Current
public double Current { get; }
Property Value
- double
Duration
public double Duration { get; set; }
Property Value
- double
IsRunning
public bool IsRunning { get; set; }
Property Value
- bool
Progress
Returns the progress as a normalized value (0.0 to 1.0).
public double Progress { get; }
Property Value
- double
RemainingMilliseconds
Returns the remaining time in milliseconds.
public double RemainingMilliseconds { get; }
Property Value
- double
RemainingMinutes
Returns the remaining time in minutes.
public double RemainingMinutes { get; }
Property Value
- double
RemainingSeconds
Returns the remaining time in seconds.
public double RemainingSeconds { get; }
Property Value
- double
TimeScale
public double TimeScale { get; set; }
Property Value
- double
Methods
FromMilliseconds(double)
Creates a new timer with duration in milliseconds.
public static Timer FromMilliseconds(double ms)
Parameters
msdouble
Returns
FromMinutes(double)
Creates a new timer with duration in minutes.
public static Timer FromMinutes(double minutes)
Parameters
minutesdouble
Returns
FromSeconds(double)
Creates a new timer with duration in seconds.
public static Timer FromSeconds(double seconds)
Parameters
secondsdouble
Returns
Pause()
Pauses the timer. Does not reset Current time.
public void Pause()
Resume()
Resumes the timer if paused. Does nothing if not paused.
public void Resume()
Start()
Starts or restarts the timer from zero.
public void Start()
Stop()
Stops the timer and resets elapsed time to zero.
public void Stop()
Tick(double)
Advances the timer by the specified delta time, unless paused. Fires OnElapsed if duration is reached.
public void Tick(double deltaTime)
Parameters
deltaTimedouble
ToString()
public override string ToString()
Returns
- string
ToString(string)
Returns the current time formatted as a string using TimeSpan format.
public string ToString(string format)
Parameters
formatstring
Returns
- string
Events
OnElapsed
public event Action OnElapsed
Event Type
- Action