Class TimeManager
Provides data and actions for network time and tick based systems.
Inheritance
Inherited Members
Namespace: FishNet.Managing.Timing
Assembly: FishNet.Runtime.dll
Syntax
[DisallowMultipleComponent]
[AddComponentMenu("FishNet/Manager/TimeManager")]
public sealed class TimeManager : MonoBehaviour
Fields
UNSET_TICK
Value for a tick that is invalid.
Declaration
public const uint UNSET_TICK = 0U
Field Value
| Type | Description |
|---|---|
| System.UInt32 |
Properties
ClientUptime
How long the local client has been connected.
Declaration
public float ClientUptime { get; }
Property Value
| Type | Description |
|---|---|
| System.Single |
FrameTicked
True if the TimeManager will or has ticked this frame.
Declaration
public bool FrameTicked { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
LastPacketTick
Tick on the last received packet, be it from server or client.
Declaration
public EstimatedTick LastPacketTick { get; }
Property Value
| Type | Description |
|---|---|
| EstimatedTick |
LocalTick
A tick that is not synchronized. This value will only increment. May be used for indexing or Ids with custom logic. When called on the server Tick is returned, otherwise LocalTick is returned. This value resets upon disconnecting.
Declaration
public uint LocalTick { get; }
Property Value
| Type | Description |
|---|---|
| System.UInt32 |
NetworkManager
NetworkManager used with this.
Declaration
public NetworkManager NetworkManager { get; }
Property Value
| Type | Description |
|---|---|
| NetworkManager |
PhysicsMode
How to perform physics.
Declaration
public PhysicsMode PhysicsMode { get; }
Property Value
| Type | Description |
|---|---|
| PhysicsMode |
PingInterval
How often in seconds to a connections ping. This is also responsible for approximating server tick. This value does not affect prediction.
Declaration
public byte PingInterval { get; }
Property Value
| Type | Description |
|---|---|
| System.Byte |
RoundTripTime
RoundTripTime in milliseconds. This value includes latency from the tick rate.
Declaration
public long RoundTripTime { get; }
Property Value
| Type | Description |
|---|---|
| System.Int64 |
ServerUptime
How long the local server has been connected.
Declaration
public float ServerUptime { get; }
Property Value
| Type | Description |
|---|---|
| System.Single |
Tick
Current approximate network tick as it is on server. When running as client only this is an approximation to what the server tick is. The value of this field may increase and decrease as timing adjusts. This value is reset upon disconnecting. Tick can be used to get the server time by using TicksToTime(). Use LocalTick for values that only increase.
Declaration
public uint Tick { get; }
Property Value
| Type | Description |
|---|---|
| System.UInt32 |
TickDelta
A fixed deltaTime for TickRate.
Declaration
[HideInInspector]
public double TickDelta { get; }
Property Value
| Type | Description |
|---|---|
| System.Double |
TickRate
How many times per second the server will simulate. This does not limit server frame rate.
Declaration
public ushort TickRate { get; }
Property Value
| Type | Description |
|---|---|
| System.UInt16 |
Methods
GetPhysicsTimeScale()
Gets the current physics time scale.
Declaration
public float GetPhysicsTimeScale()
Returns
| Type | Description |
|---|---|
| System.Single |
GetPreciseTick(TickType)
Returns a PreciseTick.
Declaration
public PreciseTick GetPreciseTick(TickType tickType)
Parameters
| Type | Name | Description |
|---|---|---|
| TickType | tickType | Tick to use within PreciseTick. |
Returns
| Type | Description |
|---|---|
| PreciseTick |
GetPreciseTick(UInt32)
Returns a PreciseTick.
Declaration
public PreciseTick GetPreciseTick(uint tick)
Parameters
| Type | Name | Description |
|---|---|---|
| System.UInt32 | tick | Tick to set within the returned PreciseTick. |
Returns
| Type | Description |
|---|---|
| PreciseTick |
GetTickPercentAsByte()
Returns the percentage of how far the TimeManager is into the next tick. Value will return between 0 and 100.
Declaration
public byte GetTickPercentAsByte()
Returns
| Type | Description |
|---|---|
| System.Byte |
GetTickPercentAsDouble()
Returns the percentage of how far the TimeManager is into the next tick as a double. Value will return between 0d and 1d.
Declaration
public double GetTickPercentAsDouble()
Returns
| Type | Description |
|---|---|
| System.Double |
GetTickPercentAsDouble(Byte)
Converts a 0 to 100 byte value to a 0d to 1d percent value. This does not check for excessive byte values, such as anything over 100.
Declaration
public static double GetTickPercentAsDouble(byte value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Byte | value |
Returns
| Type | Description |
|---|---|
| System.Double |
LocalTickToTick(UInt32)
Estimatedly converts a local tick to what it would be for the synchronized tick.
Declaration
public uint LocalTickToTick(uint localTick)
Parameters
| Type | Name | Description |
|---|---|---|
| System.UInt32 | localTick | Local tick to convert. |
Returns
| Type | Description |
|---|---|
| System.UInt32 |
SetPhysicsMode(PhysicsMode)
Updates physics based on which physics mode to use.
Declaration
public void SetPhysicsMode(PhysicsMode mode)
Parameters
| Type | Name | Description |
|---|---|---|
| PhysicsMode | mode |
SetPhysicsTimeScale(Single)
Sets the physics time scale. This is not automatically synchronized.
Declaration
public void SetPhysicsTimeScale(float value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Single | value | New value. |
SetTickRate(UInt16)
Sets the TickRate to use. This value is not synchronized, it must be set on client and server independently.
Declaration
public void SetTickRate(ushort value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.UInt16 | value | New TickRate to use. |
TicksToTime(PreciseTick)
Converts a PreciseTick to time.
Declaration
public double TicksToTime(PreciseTick pt)
Parameters
| Type | Name | Description |
|---|---|---|
| PreciseTick | pt | PreciseTick to convert. |
Returns
| Type | Description |
|---|---|
| System.Double |
TicksToTime(TickType)
Converts current ticks to time.
Declaration
public double TicksToTime(TickType tickType = TickType.LocalTick)
Parameters
| Type | Name | Description |
|---|---|---|
| TickType | tickType | TickType to compare against. |
Returns
| Type | Description |
|---|---|
| System.Double |
TicksToTime(UInt32)
Converts a number ticks to time.
Declaration
public double TicksToTime(uint ticks)
Parameters
| Type | Name | Description |
|---|---|---|
| System.UInt32 | ticks | Ticks to convert. |
Returns
| Type | Description |
|---|---|
| System.Double |
TickToLocalTick(UInt32)
Estimatedly converts a synchronized tick to what it would be for the local tick.
Declaration
public uint TickToLocalTick(uint tick)
Parameters
| Type | Name | Description |
|---|---|---|
| System.UInt32 | tick | Synchronized tick to convert. |
Returns
| Type | Description |
|---|---|
| System.UInt32 |
TimePassed(PreciseTick, Boolean)
Gets time passed from Tick to preciseTick.
Declaration
public double TimePassed(PreciseTick preciseTick, bool allowNegative = false)
Parameters
| Type | Name | Description |
|---|---|---|
| PreciseTick | preciseTick | PreciseTick value to compare against. |
| System.Boolean | allowNegative | True to allow negative values. When false and value would be negative 0 is returned. |
Returns
| Type | Description |
|---|---|
| System.Double |
TimePassed(UInt32, Boolean)
Gets time passed from Tick to previousTick.
Declaration
public double TimePassed(uint previousTick, bool allowNegative = false)
Parameters
| Type | Name | Description |
|---|---|---|
| System.UInt32 | previousTick | The previous tick. |
| System.Boolean | allowNegative | True to allow negative values. When false and value would be negative 0 is returned. |
Returns
| Type | Description |
|---|---|
| System.Double |
TimePassed(UInt32, UInt32)
Gets time passed from currentTick to previousTick.
Declaration
public double TimePassed(uint currentTick, uint previousTick)
Parameters
| Type | Name | Description |
|---|---|---|
| System.UInt32 | currentTick | The current tick. |
| System.UInt32 | previousTick | The previous tick. |
Returns
| Type | Description |
|---|---|
| System.Double |
TimeToPreciseTick(Double)
Converts time to a PreciseTick.
Declaration
public PreciseTick TimeToPreciseTick(double time)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Double | time | Time to convert. |
Returns
| Type | Description |
|---|---|
| PreciseTick |
TimeToTicks(Double, TickRounding)
Converts time to ticks.
Declaration
public uint TimeToTicks(double time, TickRounding rounding = TickRounding.RoundNearest)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Double | time | Time to convert. |
| TickRounding | rounding |
Returns
| Type | Description |
|---|---|
| System.UInt32 |
Events
OnFixedUpdate
Called when MonoBehaviours call FixedUpdate.
Declaration
public event Action OnFixedUpdate
Event Type
| Type | Description |
|---|---|
| System.Action |
OnLateUpdate
Called when MonoBehaviours call LateUpdate.
Declaration
public event Action OnLateUpdate
Event Type
| Type | Description |
|---|---|
| System.Action |
OnPostPhysicsSimulation
When using TimeManager for physics timing, this is called immediately after the physics simulation has occured for the tick. While using Unity for physics timing, this is called during Update, only if a physics frame. This may be useful if you wish to run physics differently for stacked scenes.
Declaration
public event Action<float> OnPostPhysicsSimulation
Event Type
| Type | Description |
|---|---|
| System.Action<System.Single> |
OnPostTick
Called after a tick occurs; physics would have simulated if using PhysicsMode.TimeManager.
Declaration
public event Action OnPostTick
Event Type
| Type | Description |
|---|---|
| System.Action |
OnPrePhysicsSimulation
When using TimeManager for physics timing, this is called immediately before physics simulation will occur for the tick. While using Unity for physics timing, this is called during FixedUpdate. This may be useful if you wish to run physics differently for stacked scenes.
Declaration
public event Action<float> OnPrePhysicsSimulation
Event Type
| Type | Description |
|---|---|
| System.Action<System.Single> |
OnPreTick
Called right before a tick occurs, as well before data is read.
Declaration
public event Action OnPreTick
Event Type
| Type | Description |
|---|---|
| System.Action |
OnRoundTripTimeUpdated
Called when the local clients ping is updated.
Declaration
public event Action<long> OnRoundTripTimeUpdated
Event Type
| Type | Description |
|---|---|
| System.Action<System.Int64> |
OnTick
Called when a tick occurs.
Declaration
public event Action OnTick
Event Type
| Type | Description |
|---|---|
| System.Action |
OnUpdate
Called when MonoBehaviours call Update.
Declaration
public event Action OnUpdate
Event Type
| Type | Description |
|---|---|
| System.Action |