![]() |
Infohazard.Core 1.4.1
Infohazard Core Utility Library
|
A lightweight timer that does not need to be updated each frame. More...
Public Types | |
enum | TimeMode |
The various modes available for timers. More... | |
Public Member Functions | |
PassiveTimer (float interval, TimeMode mode=TimeMode.Scaled, bool initialize=true) | |
Construct a PassiveTimer with the given interval, which will be both the initial and repeat interval. More... | |
PassiveTimer (float initialInterval, float interval, TimeMode mode=TimeMode.Scaled, bool initialize=true) | |
Construct a PassiveTimer with the given interval. More... | |
void | Initialize () |
Initialize the timer. More... | |
bool | TryConsume () |
If the current interval has ended, reset the interval and return true, else return false without reset. More... | |
void | StartInterval () |
Restart the interval, so that the timer starts counting down from its repeat interval. More... | |
void | EndInterval () |
End the interval, so the timer is in the expired state. More... | |
Properties | |
float | InitialInterval [get, set] |
Initial interval to set the timer for in seconds. More... | |
float | Interval [get, set] |
The repeat interval for the in seconds. More... | |
TimeMode | Mode [get, set] |
What value for time that the timer uses (scaled, unscaled, or realtime). More... | |
bool | IsIntervalEnded [get] |
Whether the timer is in the expired state, meaning the current interval has elapsed. More... | |
float | IntervalStartTime [get, set] |
The start time for the current interval. More... | |
float | IntervalEndTime [get] |
The time at which the current interval will end (or has ended). More... | |
float | TimeSinceIntervalEnded [get] |
Time that has passed since the current interval ended (or, if not ended, a negative value). More... | |
bool | IsInitialized [get, private set] |
Whether the timer is initialized. More... | |
bool | HasIntervalStarted [get, private set] |
Whether an interval has started yet. More... | |
float | TimeUntilIntervalEnd [get] |
The time in seconds until the current interval ends. More... | |
float | RatioUntilIntervalEnd [get] |
A ratio going from one at interval start to zero at interval end. More... | |
float | TimeSinceIntervalStart [get] |
The time in seconds since the current interval started. More... | |
float | RatioSinceIntervalStart [get] |
A ratio going from zero at interval start to one at interval end. More... | |
bool | DidIntervalEndThisFrame [get] |
Whether the current interval ended during the current frame. More... | |
float | CurrentTimeWithoutPause [get] |
The current time read from Unity, based on the Mode. More... | |
float | CurrentTime [get] |
The current time read from Unity, taking into account time that the PassiveTimer has spent paused. More... | |
float | DeltaTime [get] |
The delta time read from Unity, based on the Mode. More... | |
float | PausedTime [get, private set] |
The time that the PassiveTimer has spent in a paused state. More... | |
bool | IsPaused [get, set] |
Get or set whether the PassiveTimer is paused. More... | |
A lightweight timer that does not need to be updated each frame.
Can be serialized directly in the inspector or created in code. If it is assigned in the inspector, you must call Initialize in Start/Awake/OnEnable/OnSpawned.
A PassiveTimer can be in one of four states:
The various modes available for timers.
Infohazard.Core.PassiveTimer.PassiveTimer | ( | float | interval, |
TimeMode | mode = TimeMode.Scaled , |
||
bool | initialize = true |
||
) |
Construct a PassiveTimer with the given interval, which will be both the initial and repeat interval.
interval | The initial and repeat interval. |
mode | Time mode to use. |
initialize | Whether to initialize the timer and start counting immediately. |
Infohazard.Core.PassiveTimer.PassiveTimer | ( | float | initialInterval, |
float | interval, | ||
TimeMode | mode = TimeMode.Scaled , |
||
bool | initialize = true |
||
) |
Construct a PassiveTimer with the given interval.
initialInterval | The initial interval. |
interval | The repeat interval. |
mode | Time mode to use. |
initialize | Whether to initialize the timer and start counting immediately. |
void Infohazard.Core.PassiveTimer.EndInterval | ( | ) |
End the interval, so the timer is in the expired state.
void Infohazard.Core.PassiveTimer.Initialize | ( | ) |
Initialize the timer.
You must call this when your script initializes if the timer was assigned in the inspector.
void Infohazard.Core.PassiveTimer.StartInterval | ( | ) |
Restart the interval, so that the timer starts counting down from its repeat interval.
bool Infohazard.Core.PassiveTimer.TryConsume | ( | ) |
If the current interval has ended, reset the interval and return true, else return false without reset.
This is useful to create ability cooldowns or weapon fire rates. See the following example:
|
get |
The current time read from Unity, taking into account time that the PassiveTimer has spent paused.
|
get |
|
get |
|
get |
Whether the current interval ended during the current frame.
This can be used to create actions that happen only once, the moment a timer expires.
|
getprivate set |
Whether an interval has started yet.
|
getset |
Initial interval to set the timer for in seconds.
This interval begins when Initialize is called, or when the timer is created from a non-default constructor.
|
getset |
The repeat interval for the in seconds.
This interval begins when StartInterval or TryConsume is used.
|
get |
The time at which the current interval will end (or has ended).
|
getset |
The start time for the current interval.
|
getprivate set |
Whether the timer is initialized.
|
get |
Whether the timer is in the expired state, meaning the current interval has elapsed.
|
getset |
Get or set whether the PassiveTimer is paused.
It is not necessary to pause timers to account for the game pausing, as long as they are using realtime. This allows an individual timer to be paused separately from the rest of the game.
|
getset |
What value for time that the timer uses (scaled, unscaled, or realtime).
|
getprivate set |
The time that the PassiveTimer has spent in a paused state.
|
get |
A ratio going from zero at interval start to one at interval end.
|
get |
A ratio going from one at interval start to zero at interval end.
|
get |
Time that has passed since the current interval ended (or, if not ended, a negative value).
|
get |
The time in seconds since the current interval started.
|
get |
The time in seconds until the current interval ends.