UnityUtilities
UnityUtilities.Countdown Class Reference

A handy countdown class providing a lot of convenience methods. More...

Inheritance diagram for UnityUtilities.Countdown:
UnityUtilities.CountdownProperty UnityUtilities.CountdownPropertyLoop UnityUtilities.CountdownPropertyOnce

Public Member Functions

 Countdown (bool loop)
 Creates a new countdown with no TotalTime duration set yet.

Parameters
loopShould the countdown loop automatically?
More...
 
 Countdown (bool loop, float startDuration)
 Creates a new countdown, starting at startDuration. More...
 
 Countdown (bool loop, Func< float > calculateDurationDelegate, float? startDuration=null)
 Creates a new countdown with a delegate specifying how long it should take. More...
 
bool Progress (float? deltaTime=null)
 Progresses the countdown by deltaTime (or Time.deltaTime). Returns true if the countdown it reached zero this frame. If the countdown is already at zero when this is called and Loop is true, it is restarted automatically. More...
 
void Reset ()
 Resets the countdown to TotalTime. If a CalculateDurationDelegate is supplied, a new TotalTime is picked first. More...
 
void Reset (float timeLeft)
 Sets the Duration and the TimeLeft. More...
 
void Refill ()
 Loops the countdown by adding TotalTime to TimeLeft. This should only be called when TimeLeft is already zero or less. If a CalculateDurationDelegate is supplied, a new TotalTime is picked first. More...
 
void Refill (float newTotalTimeLeft)
 Loops the countdown by settings TotalTime to newTotalTimeLeft and then adds it to TimeLeft. More...
 

Properties

float TimeLeft [get, set]
 The time left at the current countdown. More...
 
float Duration [get]
 The initial duration set. More...
 
Func< float > CalculateDurationDelegate [get, set]
 A delegate for automatically providing a new duration when the time left runs out. More...
 
bool Loop [get, set]
 Should the countdown automatically loop when it reaches zero? More...
 
bool ReachedZero [get]
 Returns true when the countdown reached zero (or less). More...
 
bool IsRunning [get]
 Returns true if the countdown is currently over zero. More...
 
float TimePassed [get]
 Returns the time passed for this countdown: (TotalTime-TimeLeft). More...
 
float PercentElapsed [get]
 Returns 0 when the countdown is just starting and 1 when it is elapsed. If TotalTime is 0, this returns 1. More...
 
float PercentLeft [get]
 Returns 1 when the countdown is just starting and 0 when it is elapsed. If TotalTime is 0, this returns 0. More...
 

Detailed Description

A handy countdown class providing a lot of convenience methods.

Constructor & Destructor Documentation

§ Countdown() [1/3]

UnityUtilities.Countdown.Countdown ( bool  loop)

Creates a new countdown with no TotalTime duration set yet.

Parameters
loopShould the countdown loop automatically?

§ Countdown() [2/3]

UnityUtilities.Countdown.Countdown ( bool  loop,
float  startDuration 
)

Creates a new countdown, starting at startDuration.

Parameters
loopShould the countdown loop automatically?
startDurationThe starting time to count down from.

§ Countdown() [3/3]

UnityUtilities.Countdown.Countdown ( bool  loop,
Func< float >  calculateDurationDelegate,
float?  startDuration = null 
)

Creates a new countdown with a delegate specifying how long it should take.

Parameters
loopShould the countdown loop automatically?
calculateDurationDelegateA delegate providing the value to count down from.
startDurationOptional: A one-time starting duration. Afterwards the calculateDurationDelegate is used.

Member Function Documentation

§ Progress()

bool UnityUtilities.Countdown.Progress ( float?  deltaTime = null)

Progresses the countdown by deltaTime (or Time.deltaTime). Returns true if the countdown it reached zero this frame. If the countdown is already at zero when this is called and Loop is true, it is restarted automatically.

Parameters
deltaTimeOptional: A deltaTime to use instead of Time.deltaTime.
Returns
True if the countdown reached zero this frame. False if it is still going or was already zero and isn't looping.

§ Refill() [1/2]

void UnityUtilities.Countdown.Refill ( )

Loops the countdown by adding TotalTime to TimeLeft. This should only be called when TimeLeft is already zero or less. If a CalculateDurationDelegate is supplied, a new TotalTime is picked first.

The difference between Reset() and Loop() is that Loop() factors in when TimeLeft is already less than zero and subtracts it from the TotalTime.

§ Refill() [2/2]

void UnityUtilities.Countdown.Refill ( float  newTotalTimeLeft)

Loops the countdown by settings TotalTime to newTotalTimeLeft and then adds it to TimeLeft.

The difference between Reset() and Loop() is that Loop() factors in when TimeLeft is already less than zero and subtracts it from the TotalTime.

Parameters
newTotalTimeLeftThe time to set TotalTime to and to add to TimeLeft.

§ Reset() [1/2]

void UnityUtilities.Countdown.Reset ( )

Resets the countdown to TotalTime. If a CalculateDurationDelegate is supplied, a new TotalTime is picked first.

§ Reset() [2/2]

void UnityUtilities.Countdown.Reset ( float  timeLeft)

Sets the Duration and the TimeLeft.

Parameters
timeLeftThe time to set TotalTime and TimeLeft to.

Property Documentation

§ CalculateDurationDelegate

Func<float> UnityUtilities.Countdown.CalculateDurationDelegate
getset

A delegate for automatically providing a new duration when the time left runs out.

§ Duration

float UnityUtilities.Countdown.Duration
get

The initial duration set.

§ IsRunning

bool UnityUtilities.Countdown.IsRunning
get

Returns true if the countdown is currently over zero.

§ Loop

bool UnityUtilities.Countdown.Loop
getset

Should the countdown automatically loop when it reaches zero?

§ PercentElapsed

float UnityUtilities.Countdown.PercentElapsed
get

Returns 0 when the countdown is just starting and 1 when it is elapsed. If TotalTime is 0, this returns 1.

§ PercentLeft

float UnityUtilities.Countdown.PercentLeft
get

Returns 1 when the countdown is just starting and 0 when it is elapsed. If TotalTime is 0, this returns 0.

§ ReachedZero

bool UnityUtilities.Countdown.ReachedZero
get

Returns true when the countdown reached zero (or less).

§ TimeLeft

float UnityUtilities.Countdown.TimeLeft
getset

The time left at the current countdown.

§ TimePassed

float UnityUtilities.Countdown.TimePassed
get

Returns the time passed for this countdown: (TotalTime-TimeLeft).


The documentation for this class was generated from the following file: