Class UnityTimer
Unity-specific timer component that provides countdown and countup functionality with hours, minutes, and seconds precision.
Supports both incremental and decremental timing modes with automatic overflow handling.
Namespace: Serenity.Timer.Infrastructure.Components
Assembly: Serenity.UnityTimer.Infrastructure.dll
Syntax
public class UnityTimer : MonoBehaviour, ITimer, IComponent, IFoundationSettings
Constructors
UnityTimer()
Declaration
public UnityTimer()
Properties
Guid
Gets or sets the unique GUID identifier for the timer instance.
Declaration
public string Guid { get; set; }
Property Value
| Type | Description |
|---|---|
| string | The unique GUID identifier string |
Id
Gets or sets the unique identifier for the timer instance.
Declaration
public string Id { get; set; }
Property Value
| Type | Description |
|---|---|
| string | The unique identifier string |
Methods
GetHours()
Gets the current hours value of the timer.
Retrieves the hours component from the timer's current state.
Declaration
public int GetHours()
Returns
| Type | Description |
|---|---|
| int | The current number of hours |
GetMinutes()
Gets the current minutes value of the timer.
Retrieves the minutes component from the timer's current state.
Declaration
public int GetMinutes()
Returns
| Type | Description |
|---|---|
| int | The current number of minutes |
GetSeconds()
Gets the current seconds value of the timer.
Retrieves the seconds component from the timer's current state.
Declaration
public float GetSeconds()
Returns
| Type | Description |
|---|---|
| float | The current number of seconds |
GetTimeInSeconds()
Gets the total timer duration converted to seconds.
Calculates the complete time value as a single seconds value for easy comparison and manipulation.
Declaration
public float GetTimeInSeconds()
Returns
| Type | Description |
|---|---|
| float | The total time in seconds (hours * 3600 + minutes * 60 + seconds) |
InitializeTimer()
Initializes the timer to zero values.
Resets all time components to their default state.
Declaration
public void InitializeTimer()
IsRunning()
Checks whether the timer is currently running.
Returns the current execution state of the timer.
Declaration
public bool IsRunning()
Returns
| Type | Description |
|---|---|
| bool | True if the timer is running, false otherwise |
SetHours(int)
Sets the hours value for the timer.
Directly modifies the hours component of the timer.
Declaration
public void SetHours(int value)
Parameters
| Type | Name | Description |
|---|---|---|
| int | value | The number of hours to set |
SetMinutes(int)
Sets the minutes value for the timer.
Directly modifies the minutes component of the timer.
Declaration
public void SetMinutes(int value)
Parameters
| Type | Name | Description |
|---|---|---|
| int | value | The number of minutes to set |
SetSeconds(float)
Sets the seconds value for the timer.
Directly modifies the seconds component of the timer.
Declaration
public void SetSeconds(float value)
Parameters
| Type | Name | Description |
|---|---|---|
| float | value | The number of seconds to set |
SetTimer(int, int, float)
Sets the timer to the specified hours, minutes, and seconds.
Directly configures the timer with individual time components.
Declaration
public void SetTimer(int hours, int minutes, float seconds)
Parameters
| Type | Name | Description |
|---|---|---|
| int | hours | The number of hours to set |
| int | minutes | The number of minutes to set |
| float | seconds | The number of seconds to set |
SetTimer(float)
Sets the timer using total seconds, automatically calculating hours, minutes, and seconds.
Converts the total seconds into appropriate time components with proper overflow handling.
Declaration
public void SetTimer(float seconds)
Parameters
| Type | Name | Description |
|---|---|---|
| float | seconds | The total number of seconds to set |
StartTimer()
Starts the timer running.
Activates the timer to begin time progression in the configured mode.
Declaration
public void StartTimer()
StopTimer()
Stops the timer from running.
Sets the timer state to inactive, pausing any time progression.
Declaration
public void StopTimer()
Tick(float)
Advances the timer by the given delta seconds.
Called centrally by the timer service. The timer never reads UnityEngine.Time directly.
Declaration
public void Tick(float deltaSeconds)
Parameters
| Type | Name | Description |
|---|---|---|
| float | deltaSeconds | The time delta in seconds to apply. |