Struct NetworkTime
A struct to represent a point of time in a networked game. Time is stored as a combination of amount of passed ticks + a duration offset. This struct is meant to replace the Unity Time API for multiplayer gameplay.
Inherited Members
Namespace: Unity.Netcode
Assembly: solution.dll
Syntax
public struct NetworkTime
Constructors
NetworkTime(uint)
Creates a new instance of the NetworkTime struct.
Declaration
public NetworkTime(uint tickRate)
Parameters
Type | Name | Description |
---|---|---|
uint | tickRate | The tickrate. |
NetworkTime(uint, double)
Creates a new instance of the NetworkTime struct.
Declaration
public NetworkTime(uint tickRate, double timeSec)
Parameters
Type | Name | Description |
---|---|---|
uint | tickRate | The tickrate. |
double | timeSec | The time value as a float. |
NetworkTime(uint, int, double)
Creates a new instance of the NetworkTime struct.
Declaration
public NetworkTime(uint tickRate, int tick, double tickOffset = 0)
Parameters
Type | Name | Description |
---|---|---|
uint | tickRate | The tickrate. |
int | tick | The time will be created with a value where this many tick have already passed. |
double | tickOffset | Can be used to create a NetworkTime with a non fixed time value by adding an offset to the given tick value. |
Properties
FixedDeltaTime
Gets the fixed delta time. This value is based on the TickRate and stays constant. Similar to fixedUnscaledTime There is no equivalent to deltaTime.
Declaration
public float FixedDeltaTime { get; }
Property Value
Type | Description |
---|---|
float |
FixedTime
Gets he current fixed network time. This is the time value of the last network tick. Similar to fixedUnscaledTime.
Declaration
public double FixedTime { get; }
Property Value
Type | Description |
---|---|
double |
Tick
Gets the amount of network ticks which have passed until reaching the current time value.
Declaration
public int Tick { get; }
Property Value
Type | Description |
---|---|
int |
TickOffset
Gets the amount of time which has passed since the last network tick.
Declaration
public double TickOffset { get; }
Property Value
Type | Description |
---|---|
double |
TickRate
Gets the tickrate of the system of this NetworkTime. Ticks per second.
Declaration
public uint TickRate { get; }
Property Value
Type | Description |
---|---|
uint |
Time
Gets the current time. This is a non fixed time value and similar to time.
Declaration
public double Time { get; }
Property Value
Type | Description |
---|---|
double |
TimeAsFloat
Gets the current time as a float.
Declaration
public float TimeAsFloat { get; }
Property Value
Type | Description |
---|---|
float |
Methods
TimeTicksAgo(int)
Returns the time a number of ticks in the past.
Declaration
public NetworkTime TimeTicksAgo(int ticks)
Parameters
Type | Name | Description |
---|---|---|
int | ticks | The number of ticks ago we're querying the time |
Returns
Type | Description |
---|---|
NetworkTime |
ToFixedTime()
Converts the network time into a fixed time value.
Declaration
public NetworkTime ToFixedTime()
Returns
Type | Description |
---|---|
NetworkTime | A NetworkTime where Time is the FixedTime value of this instance. |
Operators
operator +(NetworkTime, double)
Computes the time a number of seconds later
Declaration
public static NetworkTime operator +(NetworkTime a, double b)
Parameters
Type | Name | Description |
---|---|---|
NetworkTime | a | The start time |
double | b | The number of seconds to add |
Returns
Type | Description |
---|---|
NetworkTime | The resulting time |
operator +(NetworkTime, NetworkTime)
Computes the sum of two times
Declaration
public static NetworkTime operator +(NetworkTime a, NetworkTime b)
Parameters
Type | Name | Description |
---|---|---|
NetworkTime | a | First time |
NetworkTime | b | Second time |
Returns
Type | Description |
---|---|
NetworkTime | The sum of the two times passed in |
operator -(NetworkTime, double)
Computes the time a number of seconds before
Declaration
public static NetworkTime operator -(NetworkTime a, double b)
Parameters
Type | Name | Description |
---|---|---|
NetworkTime | a | The start time |
double | b | The number of seconds to remove |
Returns
Type | Description |
---|---|
NetworkTime | The resulting time |
operator -(NetworkTime, NetworkTime)
Computes the time difference between two ticks
Declaration
public static NetworkTime operator -(NetworkTime a, NetworkTime b)
Parameters
Type | Name | Description |
---|---|---|
NetworkTime | a | End time |
NetworkTime | b | Start time |
Returns
Type | Description |
---|---|
NetworkTime | The time difference between start and end |