Quick Start Guide
The Eidolon.Timer
class provides a flexible and customizable timer functionality for Unity game development. It allows you to create timers with specific durations and attach callback functions to various events such as timer start, stop, pause, resume, and completion.
Example Usage
1. Creating a Timer and Starting it:
// Create a new timer with a duration of 10 secondsGameTimer timer = new GameTimer(10f);
// Start the timertimer.Start();
2. Pausing and Resuming a Timer:
// Pause the timertimer.Pause();
// Resume the timertimer.Resume();
3. Stopping and Resetting a Timer:
// Stop the timertimer.Stop();
// Reset the timertimer.Reset();
4. Checking Timer Status:
// Check if the timer is runningbool isRunning = timer.IsRunning();
// Check if the timer is pausedbool isPaused = timer.IsPaused();
5. Handling Timer Events:
// Attach callback functions to timer eventstimer.onStartCallback += () => Debug.Log("Timer started!");timer.onStopCallback += () => Debug.Log("Timer stopped!");timer.onPauseCallback += () => Debug.Log("Timer paused!");timer.onResumeCallback += () => Debug.Log("Timer resumed!");timer.onTimerCompleteCallback += () => Debug.Log("Timer completed!");
Remarks
- Ensure that you call the
Update()
method of theGameTimer
instance in theUpdate()
method of a MonoBehaviour to update the timer’s internal state. - You can attach callback functions to respond to timer events such as start, stop, pause, resume, and completion by using delegate assignment (
+=
) syntax. - The timer automatically stops when its duration is reached, and the associated completion callback is invoked.
- Use the
GetElapsedTime()
andGetDuration()
methods to retrieve the current elapsed time and total duration of the timer, respectively.