Class CoherenceInput
This component can be added to a GameObject with CoherenceSync to be able to define which inputs it accepts.
This feature can be used to improve game feel and to prevent cheating by replaying inputs on a simulator or another client. See the coherence docs (section "Input prediction and rollback") for more information.
[NonBindable]
public class CoherenceInput : MonoBehaviour, ICoherenceInput
- Inheritance
-
CoherenceInput
- Implements
Constructors
CoherenceInput()
public CoherenceInput()
Fields
DestroyOnInputAuthorityDisconnected
Defines whether the simulator or host that has the state authority over this entity should destroy it when the client with input authority disconnects from the session. Works with server-side simulation.
public bool DestroyOnInputAuthorityDisconnected
Field Value
DisconnectOnTimeReset
Defines whether the client should automatically disconnect in case of unexpected time resync with the server. Works only with the client-side simulation.
public bool DisconnectOnTimeReset
Field Value
InitialBufferSize
Size of the buffer. Dictates how many frames worth of inputs can be stored. When buffer reaches its capacity a pause is requested through the ShouldPause(long, long).
public int InitialBufferSize
Field Value
InitialInputDelay
Delay applied to the stored inputs.
public int InitialInputDelay
Field Value
MaxInputs
Defines the max number of input fields per CoherenceInput
public const int MaxInputs = 32
Field Value
UseFixedSimulationFrames
If true the input system will use the NetworkTime.ClientFixedSimulationFrame (otherwise the NetworkTime.ClientSimulationFrame will be used). When using fixed frames, if deterministic output is desired, it is recommended to update the input driven logic through the OnFixedNetworkUpdate.
public bool UseFixedSimulationFrames
Field Value
internalGetAxis
public Func<string, long?, float> internalGetAxis
Field Value
internalGetAxis2D
public Func<string, long?, Vector2> internalGetAxis2D
Field Value
internalGetAxis3D
public Func<string, long?, Vector3> internalGetAxis3D
Field Value
internalGetButton
public Func<string, long?, bool> internalGetButton
Field Value
internalGetInteger
public Func<string, long?, int> internalGetInteger
Field Value
internalGetRotation
public Func<string, long?, Quaternion> internalGetRotation
Field Value
- Func<string, long?, Quaternion>
internalGetString
public Func<string, long?, string> internalGetString
Field Value
internalOnInputReceived
public Action<IEntityInput, long> internalOnInputReceived
Field Value
internalRequestBuffer
public Func<IInputBuffer> internalRequestBuffer
Field Value
internalSetAxis
public Action<string, float> internalSetAxis
Field Value
internalSetAxis2D
public Action<string, Vector2> internalSetAxis2D
Field Value
internalSetAxis3D
public Action<string, Vector3> internalSetAxis3D
Field Value
internalSetButton
public Action<string, bool> internalSetButton
Field Value
internalSetInteger
public Action<string, int> internalSetInteger
Field Value
internalSetRotation
public Action<string, Quaternion> internalSetRotation
Field Value
internalSetString
public Action<string, string> internalSetString
Field Value
Properties
Buffer
Returns an underlying input buffer.
public IInputBuffer Buffer { get; }
Property Value
Remarks
For advanced use cases, use with care.
BufferSize
Size of the buffer. Dictates how many frames worth of inputs can be stored. When buffer reaches its capacity a pause is requested through the ShouldPause(long, long).
public int BufferSize { get; }
Property Value
CurrentSimulationFrame
Current simulation frame as seen by this client. If the UseFixedSimulationFrames is true this returns the ClientFixedSimulationFrame, otherwise the ClientSimulationFrame is returned.
public long CurrentSimulationFrame { get; }
Property Value
Delay
Delay applied to the stored inputs.
public int Delay { get; set; }
Property Value
Fields
public Field[] Fields { get; }
Property Value
- Field[]
IsInputOwner
Determines whether this client is responsible for producing inputs using SetXXX
methods.
public bool IsInputOwner { get; }
Property Value
IsProducer
If true, this client is responsible for producing inputs using SetXXX
methods.
public bool IsProducer { get; }
Property Value
IsReadyToProcessInputs
Determines whether this input is ready for processing input data. Until this is true, all the inputs set through
the SetXXX
methods are overwriting each other. Only the last value set will be sent as soon as this property
becomes true.
public bool IsReadyToProcessInputs { get; }
Property Value
IsServerSimulated
If true the input system assumes that there's a simulator or host running that processes all inputs sent by the clients while clients merely produce inputs and sync their entities with the host. Authority over this entity will be automatically transferred to the host.
public bool IsServerSimulated { get; }
Property Value
LastAcknowledgedFrame
Last frame received that didn't trigger a misprediction, or -1 if nothing was acknowledged yet. Might be greater than LastConsumedFrame.
public long LastAcknowledgedFrame { get; }
Property Value
LastConsumedFrame
Last frame that was fetched from the buffer and was not predicted.
public long LastConsumedFrame { get; }
Property Value
LastFrame
Last (latest) frame number for which an input was stored, received or predicted. -1 if nothing was added to the buffer yet.
public long LastFrame { get; }
Property Value
LastReceivedFrame
Last frame number that was received from the remote input producer, or -1 if nothing was received yet.
public long LastReceivedFrame { get; }
Property Value
LastSentFrame
Last frame number that was dequeued for sending, or -1 if nothing was sent yet.
public long LastSentFrame { get; }
Property Value
MispredictionFrame
Frame at which last prediction failure has been detected.
public long? MispredictionFrame { get; }
Property Value
- long?
Remarks
Value is nulled-out as soon as the input is retrieved for that or subsequent frames. For this reason this property should be inspected before any input retrieving method in a given frame in order to check whether the simulation correction is required.
ProcessingEnabled
Determines whether the input processing will happen. If disabled inputs won't be stored in the buffer and won't be sent. Affects only the input-producing side. Defaults to true.
public bool ProcessingEnabled { get; set; }
Property Value
Methods
DebugOnInputReceived(long, object)
[Conditional("COHERENCE_INPUT_DEBUG")]
public void DebugOnInputReceived(long frame, object input)
Parameters
DebugOnInputSent(long, object)
[Conditional("COHERENCE_INPUT_DEBUG")]
public void DebugOnInputSent(long frame, object input)
Parameters
GetAxis(string, long?)
Returns a state of the axis as of the given simulation frame.
public float GetAxis(string axisName, long? simulationFrame = null)
Parameters
axisName
stringName of the axis.
simulationFrame
long?Simulation frame for which state is requested. If
null
the CurrentSimulationFrame will be used.
Returns
- float
Value of the axis as of the given simulation frame.
GetAxis2D(string, long?)
Returns a state of the axis2D as of the given simulation frame.
public Vector2 GetAxis2D(string axis2DName, long? simulationFrame = null)
Parameters
axis2DName
stringName of the axis2D.
simulationFrame
long?Simulation frame for which state is requested. If
null
the CurrentSimulationFrame will be used.
Returns
- Vector2
Value of the axis2D as of the given simulation frame.
GetAxis3D(string, long?)
Returns a state of the axis3D as of the given simulation frame.
public Vector3 GetAxis3D(string axis3DName, long? simulationFrame = null)
Parameters
axis3DName
stringName of the axis3D.
simulationFrame
long?Simulation frame for which state is requested. If
null
the CurrentSimulationFrame will be used.
Returns
- Vector3
Value of the axis3D as of the given simulation frame.
GetButton(string, long?)
Returns a state of the button as of the given simulation frame.
public bool GetButton(string buttonName, long? simulationFrame = null)
Parameters
buttonName
stringName of the button.
simulationFrame
long?Simulation frame for which state is requested. If
null
the CurrentSimulationFrame will be used.
Returns
- bool
Value of the button as of the given simulation frame.
GetInteger(string, long?)
Returns a state of the integer as of the given simulation frame.
public int GetInteger(string integerName, long? simulationFrame = null)
Parameters
integerName
stringName of the integer.
simulationFrame
long?Simulation frame for which state is requested. If
null
the CurrentSimulationFrame will be used.
Returns
- int
Value of the integer as of the given simulation frame.
GetRotation(string, long?)
Returns a state of the rotation as of the given simulation frame.
public Quaternion GetRotation(string rotationName, long? simulationFrame = null)
Parameters
rotationName
stringName of the rotation.
simulationFrame
long?Simulation frame for which state is requested. If
null
the CurrentSimulationFrame will be used.
Returns
- Quaternion
Value of the rotation as of the given simulation frame.
GetString(string, long?)
Returns a string state as of the given simulation frame.
public string GetString(string stringName, long? simulationFrame = null)
Parameters
stringName
stringName of the string.
simulationFrame
long?Simulation frame for which state is requested. If
null
the CurrentSimulationFrame will be used.
Returns
- string
Value of the string as of the given simulation frame.
SetAxis(string, float)
Sets an axis state for this input. Input is stored as of the CurrentSimulationFrame.
public void SetAxis(string axisName, float value)
Parameters
SetAxis2D(string, Vector2)
Sets an axis2D state for this input. Input is stored as of the CurrentSimulationFrame.
public void SetAxis2D(string axis2DName, Vector2 value)
Parameters
SetAxis3D(string, Vector3)
Sets an axis3D state for this input. Input is stored as of the CurrentSimulationFrame.
public void SetAxis3D(string axis3DName, Vector3 value)
Parameters
axis3DName
stringName of the axis3D to update.
value
Vector3Value to set.
SetButton(string, bool)
Sets a button state for this input. Input is stored as of the CurrentSimulationFrame.
public void SetButton(string buttonName, bool value)
Parameters
SetInteger(string, int)
Sets an integer state for this input. Input is stored as of the CurrentSimulationFrame.
public void SetInteger(string integerName, int value)
Parameters
SetRotation(string, Quaternion)
Sets a rotation state for this input. Input is stored as of the CurrentSimulationFrame.
public void SetRotation(string rotationName, Quaternion value)
Parameters
rotationName
stringName of the rotation to update.
value
QuaternionValue to set.
SetString(string, string)
Sets a string state for this input. Input is stored as of the CurrentSimulationFrame.
public void SetString(string stringName, string value)
Parameters
ShouldPause(long)
If true, the buffer cannot do any more predictions. Client should pause the game and stop polling inputs to not lose any data required for a rollback.
public bool ShouldPause(long commonReceivedFrame)
Parameters
commonReceivedFrame
longCommon (lowest) received frame for all inputs in the simulation.
Returns
Update()
protected void Update()
Events
OnStaleInput
Called when an input is received that is older than the oldest input in the buffer.
public event StaleInputHandler OnStaleInput