SyncronizedTime
This is a simple universal component that you can call to start, stop and reset a timer. This timer is then syncronized across the server so everyone can reference this time. You are meant to tie into the available delegates to perform actions on timer start, stop, reset, and completion actions.
Available Delegates
| Name | Type | Description |
|---|---|---|
| OnTimeStarted | void | Called when the timer has started. |
| OnTimeStopped | void | Called when the timer has stopped. |
| OnTimeChangedRaw | double | Called everytime the timer changes it's value. |
| OnTimeChangedFormatted | string | Called everytime the timer changes its value. It returns the formatted string for you |
| OnTimeCountFinished | void | Called when the timer has completed. |
Public Functions
| Function | Description | | string GetFormattedTime() | Returns the selected formatted version to whomever is calling this |
How To Use These Delegates
The following is an example of how another script can tie into this SyncronizedTime component's delegates to get real time updates according to your desired changes.
protected virtual void OnEnable()
{
SyncronizedTime.instance.OnTimeStarted += () => timerStarted = true;
SyncronizedTime.instance.OnTimeStopped += () => timerStarted = false;
SyncronizedTime.instance.OnTimeChangedFormatted += UpdateWithFormattedText;
UpdateWithFormattedText(SyncronizedTime.instance.GetFormattedTime());
}
protected virtual void OnDisable()
{
SyncronizedTime.instance.OnTimeStarted -= () => timerStarted = true;
SyncronizedTime.instance.OnTimeStopped -= () => timerStarted = false;
SyncronizedTime.instance.OnTimeChangedFormatted -= UpdateWithFormattedText;
}
public virtual void UpdateWithFormattedText(string time)
{
textElement.text = time;
}
See Also
- WatchSyncTime