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
public int InitialBufferSize
Field Value
InitialInputDelay
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
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
public int Delay { get; set; }
Property Value
Fields
public CoherenceInput.Field[] Fields { get; }
Property Value
- Field[]
InitialBufferDelay
[Obsolete]
[Deprecated("16/02/2023", 1, 0, 0, Reason = "Misspelled InitialInputDelay")]
public int InitialBufferDelay { get; set; }
Property Value
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
public long LastAcknowledgedFrame { get; }
Property Value
LastConsumedFrame
public long LastConsumedFrame { get; }
Property Value
LastFrame
public long LastFrame { get; }
Property Value
LastReceivedFrame
public long LastReceivedFrame { get; }
Property Value
LastSentFrame
public long LastSentFrame { get; }
Property Value
MispredictionFrame
public long? MispredictionFrame { get; }
Property Value
- long?
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.
GetAxisState(string, long?)
[Obsolete("Please use the 'GetAxis2D' method instead.")]
[Deprecated("15/12/2022", 1, 0, 0, Reason = "Renamed to 'GetAxis2D'")]
public Vector2 GetAxisState(string axisName, long? simulationFrame = null)
Parameters
Returns
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.
GetButtonRangeState(string, long?)
[Obsolete("Please use the 'GetAxis' method instead.")]
[Deprecated("15/12/2022", 1, 0, 0, Reason = "Renamed to 'GetAxis'")]
public float GetButtonRangeState(string buttonRangeName, long? simulationFrame = null)
Parameters
Returns
GetButtonState(string, long?)
[Obsolete("Please use the 'GetButton' method instead.")]
[Deprecated("15/12/2022", 1, 0, 0, Reason = "Renamed to 'GetButton'")]
public bool GetButtonState(string buttonName, long? simulationFrame = null)
Parameters
Returns
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.
GetStringState(string, long?)
[Obsolete("Please use the 'GetString' method instead.")]
[Deprecated("15/12/2022", 1, 0, 0, Reason = "Renamed to 'GetString'")]
public string GetStringState(string stringName, long? simulationFrame = null)
Parameters
Returns
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
SetAxisState(string, Vector2)
[Obsolete("Please use the 'SetAxis2D' method instead.")]
[Deprecated("15/12/2022", 1, 0, 0, Reason = "Renamed to 'SetAxis2D'")]
public void SetAxisState(string axisName, Vector2 value)
Parameters
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
SetButtonRangeState(string, float)
[Obsolete("Please use the 'SetAxis' method instead.")]
[Deprecated("15/12/2022", 1, 0, 0, Reason = "Renamed to 'SetAxis'")]
public void SetButtonRangeState(string buttonRangeName, float value)
Parameters
SetButtonState(string, bool)
[Obsolete("Please use the 'SetButton' method instead.")]
[Deprecated("15/12/2022", 1, 0, 0, Reason = "Renamed to 'SetButton'")]
public void SetButtonState(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)
public void SetRotation(string rotationName, Quaternion value)
Parameters
rotationName
stringvalue
Quaternion
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
SetStringState(string, string)
[Obsolete("Please use the 'SetString' method instead.")]
[Deprecated("15/12/2022", 1, 0, 0, Reason = "Renamed to 'SetString'")]
public void SetStringState(string stringName, string value)
Parameters
ShouldPause(long)
public bool ShouldPause(long commonReceivedFrame)
Parameters
commonReceivedFrame
long
Returns
Update()
protected void Update()
Events
OnStaleInput
public event StaleInputHandler OnStaleInput