API TimeManager - shmellyorc/Box GitHub Wiki
TimeManager
Namespace: Box.Utils
Manages scheduled actions (timers) using coroutines. Supports named or anonymous timers, one-shot or repeating execution, and stopping/removing timers by name or enum.
Constructors
No public constructors — use new TimeManager()
to create an instance.
Properties
Name | Type | Description |
---|---|---|
int Count |
int |
Gets the number of active timers. |
Methods
Signature | Description |
---|---|
void Add(string name, float delay, bool repeat, Action action) |
Schedule a timer identified by name . After delay seconds, invoke action . If repeat is true, repeat indefinitely. |
void Add(Enum name, float delay, bool repeat, Action action) |
Overload using an enum as the timer identifier. |
void Add(float delay, bool repeat, Action action) |
Schedule an anonymous timer with a generated GUID as its name. |
bool Exists(string name) |
Returns true if a timer with the given name is active. |
bool Exists(Enum name) |
Returns true if a timer with the enum key (via name.ToEnumString() ) is active. |
bool Stop(string name) |
Stop and remove the timer identified by name . Returns true if found and stopped. |
bool Stop(Enum name) |
Stop and remove the timer for the enum key. Returns true if found and stopped. |
void Clear() |
Stop and remove all active timers. |
Usage Example
// Create a TimeManager instance
var timerMgr = new TimeManager();
// Schedule a one-shot timer by name
timerMgr.Add("spawn_enemy", 5.0f, false, () => SpawnEnemy());
// Schedule a repeating timer using an enum identifier
enum TimerType { PowerUp, SaveGame }
timerMgr.Add(TimerType.PowerUp, 10.0f, true, () => GrantPowerUp());
// Check and stop a timer
if (timerMgr.Exists("spawn_enemy"))
timerMgr.Stop("spawn_enemy");
// Clear all timers
timerMgr.Clear();