SyncStopwatch
SyncStopwatch provides an efficient way to synchronize a stopwatch between server and clients.
Like SyncTimer, SyncStopwatch only updates state changes such as start or stopping, rather than each individual delta change.
private readonly SyncStopwatch _timePassed = new()Making changes to the timer is very simple, and like other SyncTypes must be done on the server.
// All of the actions below are automatically synchronized.
/* Starts the stopwatch while optionally sending a stop
* message first if stopwatch was already running.
* If the stopwatch was previously running the time passed
* would be reset. */
/* This would invoke callbacks indicating a stopwatch
* had stopped, then started again. */
_timePassed.StartStopwatch(true);
/* Pauses the stopwatch and optionally sends the current
* timer value as it is on the server. */
_timePassed.PauseStopwatch(false);
// Unpauses the current stopwatch.
_timePassed.UnpauseStopwatch();
/* Ends the Stopwatch while optionally sends the
* current value to clients, as it was during the stop. */
_timePassed.StopStopwatch(false);Updating and reading the timer value is much like you would a normal float value.
Like other SyncTypes, you can subscribe to change events for the SyncStopwatch.
Last updated