Class ManualTickClock

Namespace
Unity.Multiplayer.Core

An ITickClock driven by hand: Step(int) ticks once, Advance(double) turns elapsed seconds into whole ticks and carries the remainder. For tests and engine-free simulations; in a running game the adapter's NetworkTickClock is used instead.

public sealed class ManualTickClock : ITickClock
Inheritance
ManualTickClock
Implements
Inherited Members

Constructors

ManualTickClock(int)

Creates a clock at tick 0.

public ManualTickClock(int tickRate = 30)

Parameters

tickRate int

Exceptions

ArgumentOutOfRangeException

tickRate is below 1.

Properties

CurrentTick

Ticks elapsed since the clock started; 0 before the first tick.

public long CurrentTick { get; }

Property Value

long

Pending

Seconds accumulated towards the next tick, in [0, TickInterval).

public double Pending { get; }

Property Value

double

TickInterval

Seconds per tick: 1 / TickRate.

public double TickInterval { get; }

Property Value

double

TickRate

Ticks per second.

public int TickRate { get; }

Property Value

int

Time

Simulation time in seconds: CurrentTick × TickInterval.

public double Time { get; }

Property Value

double

Methods

Advance(double)

Adds seconds of elapsed time and ticks once per whole interval it completes. Returns the number of ticks run.

public int Advance(double seconds)

Parameters

seconds double

Returns

int

Exceptions

ArgumentOutOfRangeException

seconds is negative, NaN or infinite.

Step(int)

Ticks ticks times, raising Ticked for each.

public void Step(int ticks = 1)

Parameters

ticks int

Exceptions

ArgumentOutOfRangeException

ticks is negative.

Events

Ticked

Raised once per tick with the new CurrentTick.

public event Action<long> Ticked

Event Type

Action<long>