Class CoherenceBridge
The CoherenceBridge
is the component that all coherence entities use to communicate to the replication
server, and other clients. It is also responsible for instantiating and destroying any remote entities that your
client should know about.
[NonBindable]
public sealed class CoherenceBridge : CoherenceBehaviour, ICoherenceBridge
- Inheritance
-
CoherenceBridge
- Implements
Constructors
CoherenceBridge()
public CoherenceBridge()
Fields
ClientConnectionEntry
The prefab to use when this CoherenceBridge
instantiates a client connection.
public CoherenceSyncConfig ClientConnectionEntry
Field Value
ClientConnectionPrefab
[Obsolete("Please use ClientConnectionEntry instead.")]
public CoherenceSync ClientConnectionPrefab
Field Value
OnAfterFloatingOriginShifted
Invoked after OnFloatingOriginShifted
public Action<FloatingOriginShiftArgs> OnAfterFloatingOriginShifted
Field Value
OnFloatingOriginShifted
Invoked at the end of the floating point origin shifting operation started via SetFloatingOrigin(Vector3d) or TranslateFloatingOrigin(Vector3), after all objects have been shifted..
public Action<FloatingOriginShiftArgs> OnFloatingOriginShifted
Field Value
SimulatorConnectionEntry
The prefab to use when this CoherenceBridge
instantiates a simulator connection.
public CoherenceSyncConfig SimulatorConnectionEntry
Field Value
SimulatorConnectionPrefab
[Obsolete("Please use SimulatorConnectionEntry instead.")]
public CoherenceSync SimulatorConnectionPrefab
Field Value
WorldPositionMaxRange
Maximum abs position of an entity/liveQuery/floatingOrigin
public const float WorldPositionMaxRange = 1.7014117E+38
Field Value
adjustSimulationFrameByPing
Adjusting the simulation frame by ping accounts for the time required for the packets to travel between the server and the client when calculating the client-server frame drift.
public bool adjustSimulationFrameByPing
Field Value
Remarks
This does not modify the ClientSimulationFrame directly, instead it affects the NetworkTimeScale.
controlTimeScale
Enables automatic client-server synchronization. Can be disabled temporarily for bullet time effects to intentionally desync clients for a short while. When set to true, Time.timeScale is nudged up/down so the game speed adapts to synchronize the game clock with the server clock.
public bool controlTimeScale
Field Value
globalQueryOn
public bool globalQueryOn
Field Value
networkPrefix
Entities spawned by other clients get this prefix attached to their name.
public string networkPrefix
Field Value
onConnected
Invoked when the CoherenceBridge
has successfully connected.
public UnityEvent<CoherenceBridge> onConnected
Field Value
onConnectionError
Invoked when the CoherenceBridge
experiences a connection error.
public UnityEvent<CoherenceBridge, ConnectionException> onConnectionError
Field Value
onDisconnected
Invoked when the CoherenceBridge
has disconnected.
public UnityEvent<CoherenceBridge, ConnectionCloseReason> onDisconnected
Field Value
onLiveQuerySynced
Invoked when all entities that originated from a CoherenceLiveQuery have been synced.
public UnityEvent<CoherenceBridge> onLiveQuerySynced
Field Value
Remarks
This event does not guarantee that all entities will be in the exact state as of the CoherenceLiveQuery creation, it does however guarantee that the entities that were present at the time of query creation have been synced with this client. Eventual consistency rules still apply.
onNetworkEntityCreated
public UnityEvent<CoherenceBridge, NetworkEntityState> onNetworkEntityCreated
Field Value
onNetworkEntityDestroyed
public UnityEvent<CoherenceBridge, NetworkEntityState, DestroyReason> onNetworkEntityDestroyed
Field Value
- UnityEvent<CoherenceBridge, NetworkEntityState, DestroyReason>
Properties
AuthorityManager
Handles authority requests over entities and adoptions of orphaned entities.
public AuthorityManager AuthorityManager { get; }
Property Value
ClientConnections
Holds information about all CoherenceClientConnections in this session. Can be used to send messages between clients if you're using Connection Prefabs.
public CoherenceClientConnectionManager ClientConnections { get; }
Property Value
ClientFixedSimulationFrame
Similar to ClientSimulationFrame but quantized to FixedTimeStep.
public long ClientFixedSimulationFrame { get; }
Property Value
ClientId
Unique ClientID of this connection as assigned by the server. If a ClientConnectionPrefab has been assigned, this value can also be accessed using GetMyConnection().ClientId.
public ClientID ClientId { get; }
Property Value
CloudService
Service to communicate with the coherence Cloud. You must be logged in with a coherence account, with an Organization and Project selected to be able to use it. Check the coherence Cloud tab in the coherence Hub window for more details.
public CloudService CloudService { get; }
Property Value
ConnectionType
The connection type that was used when connecting to the replication server, or Client if no connection attempt has yet been made.
public ConnectionType ConnectionType { get; }
Property Value
EntitiesManager
Holds information about all entities that are visible to this connection. Both entities you have authority over as well as remote entities.
public EntitiesManager EntitiesManager { get; }
Property Value
EntityCount
public int EntityCount { get; }
Property Value
FixedUpdateInput
public FixedUpdateInput FixedUpdateInput { get; }
Property Value
InputManager
Handles client entities with server-side input.
public CoherenceInputManager InputManager { get; }
Property Value
InstantiationScene
Scene where this Bridge will instantiate remote entities. Setting this value will register the bridge to its current scene.
public Scene? InstantiationScene { get; set; }
Property Value
IsSimulatorOrHost
EXPERIMENTAL - MIGHT CHANGE OR BE REMOVED IN THE NEAR FUTURE
If true this client is considered a host of this session. Any entities with CoherenceInputs, marked as ServerSideWithClientInput, will have their state authority transferred to this client. Any entities marked as ServerSide will remain active on this client.
public bool IsSimulatorOrHost { get; }
Property Value
Remarks
* Always true for Simulator.
* Only the client that created a room can become its host.
NetworkTime
NetworkTime provides access to the network synchronized time and frame state, NetworkTime.
public NetworkTime NetworkTime { get; }
Property Value
NetworkTimeAsDouble
public double NetworkTimeAsDouble { get; }
Property Value
Ping
public Ping Ping { get; }
Property Value
SceneManager
Contains the API for controlling what scene this client should receive and send updates for.
public CoherenceSceneManager SceneManager { get; set; }
Property Value
UniquenessManager
Holds information about all unique entities in this session. Unique entities are created by setting Uniqueness to No Duplicates in the CoherenceSync component.
public UniquenessManager UniquenessManager { get; }
Property Value
isConnected
public bool isConnected { get; }
Property Value
isConnecting
public bool isConnecting { get; }
Property Value
Methods
Connect(EndpointData, ConnectionSettings)
Attempts to connect to the given endpoint using the provided connection settings. The connection type will be determined by IsSimulator.
public void Connect(EndpointData endpoint, ConnectionSettings connectionSettings = null)
Parameters
endpoint
EndpointDataThe address of the replication server to connect to.
connectionSettings
ConnectionSettingsThe settings to be used for this connection. If null, Default will be used.
Connect(EndpointData, ConnectionType, ConnectionSettings)
Attempts to connect to the given endpoint using the provided connection type and connection settings.
public void Connect(EndpointData endpoint, ConnectionType connectionType, ConnectionSettings connectionSettings = null)
Parameters
endpoint
EndpointDataThe address of the replication server to connect to.
connectionType
ConnectionTypeUsed to specify if you are connecting as a client or simulator.
connectionSettings
ConnectionSettingsThe settings to be used for this connection. If null, Default will be used.
ConnectAsHost(EndpointData, ConnectionSettings)
EXPERIMENTAL - MIGHT CHANGE OR BE REMOVED IN THE NEAR FUTURE
Attempts to connect as a host-client to the given endpoint using the provided connection type and connection settings. Connected client will become a host of the room (see IsSimulatorOrHost).
public void ConnectAsHost(EndpointData endpoint, ConnectionSettings connectionSettings = null)
Parameters
endpoint
EndpointDataThe address of the replication server to connect to.
connectionSettings
ConnectionSettingsThe settings to be used for this connection. If null, Default will be used.
Disconnect()
public void Disconnect()
Dispose()
public void Dispose()
DontDestroyOnLoad()
Convenience method for moving making this CoherenceBridge not get destroyed when changing scene.
public void DontDestroyOnLoad()
EntityIdToCoherenceSync(SerializeEntityID)
Get the CoherenceSync for a Coherence.Entity.SerializeEntityID.
public CoherenceSync EntityIdToCoherenceSync(SerializeEntityID from)
Parameters
from
SerializeEntityID
Returns
EntityIdToGameObject(SerializeEntityID)
Get the GameObject
for a Coherence.Entity.SerializeEntityID.
public GameObject EntityIdToGameObject(SerializeEntityID from)
Parameters
from
SerializeEntityID
Returns
EntityIdToRectTransform(SerializeEntityID)
Get the RectTransform
for a Coherence.Entity.SerializeEntityID.
public RectTransform EntityIdToRectTransform(SerializeEntityID from)
Parameters
from
SerializeEntityID
Returns
EntityIdToTransform(SerializeEntityID)
Get the Transform
for a Coherence.Entity.SerializeEntityID.
public Transform EntityIdToTransform(SerializeEntityID from)
Parameters
from
SerializeEntityID
Returns
GetCoherenceSyncForEntity(SerializeEntityID)
Get a CoherenceSync from the mapper.
public ICoherenceSync GetCoherenceSyncForEntity(SerializeEntityID id)
Parameters
id
SerializeEntityIDA valid SerializeEntityID (meaning it exists in the mapper)
Returns
GetFloatingOrigin()
Returns the current absolute position of the floating point origin.
public Vector3d GetFloatingOrigin()
Returns
GetNetworkEntityStateForEntity(SerializeEntityID)
Get a Network Entity State from the mapper.
public NetworkEntityState GetNetworkEntityStateForEntity(SerializeEntityID id)
Parameters
id
SerializeEntityIDA valid SerializeEntityID (meaning it exists in the mapper)
Returns
JoinRoom(RoomData)
public void JoinRoom(RoomData room)
Parameters
room
RoomData
JoinWorld(WorldData)
public void JoinWorld(WorldData world)
Parameters
world
WorldData
Reconnect()
Attempts to reconnect to the replication server. Then endpoint, connectionSettings and connectionType used with the previous connection attempt will be used again.
public void Reconnect()
SetFloatingOrigin(Vector3d)
Sets the floating point origin absolute position to a new value. Only works if bridge isConnected, otherwise nothing happens.
public bool SetFloatingOrigin(Vector3d newOrigin)
Parameters
newOrigin
Vector3dNew floating point origin absolute position
Returns
- bool
Returns true if the floating origin was shifted, false if bridge was not connected.
SetInitialScene(uint)
Use this method to set the initial scene to connect to. Setting this value after connecting has no immediate effect (but will effect subsequent reconnect attempts.) To set the scene after connecting, use .
public void SetInitialScene(uint initialScene)
Parameters
initialScene
uint
SetRelay(IRelay)
Sets a IRelay to be managed.
public void SetRelay(IRelay newRelay)
Parameters
newRelay
IRelay
Remarks
Relay must be set before connecting using a CoherenceBridge. Setting relay during an active connection will keep it disabled and enable it only on the subsequent connection.
SetTransportFactory(ITransportFactory)
Sets the transport factory used when connecting to the replication server. A custom transport factory can be used to tunnel traffic via relay.
public void SetTransportFactory(ITransportFactory transportFactory)
Parameters
transportFactory
ITransportFactoryAn instance of a transport factory, or null to use the default transport factory.
TranslateFloatingOrigin(Vector3)
Moves the floating point origin by a translation
vector.
Only works if bridge isConnected, otherwise nothing happens.
public bool TranslateFloatingOrigin(Vector3 translation)
Parameters
translation
Vector3
Returns
- bool
Returns true if the floating origin was shifted, false if bridge was not connected.
UnityObjectToEntityId(CoherenceSync)
Get the Coherence.Entity.SerializeEntityID for a CoherenceSync.
public SerializeEntityID UnityObjectToEntityId(CoherenceSync from)
Parameters
from
CoherenceSync
Returns
- SerializeEntityID
UnityObjectToEntityId(GameObject)
Get the Coherence.Entity.SerializeEntityID for a
GameObject
with CoherenceSync.
public SerializeEntityID UnityObjectToEntityId(GameObject from)
Parameters
from
GameObject
Returns
- SerializeEntityID
UnityObjectToEntityId(Transform)
Get the Coherence.Entity.SerializeEntityID for a
Transform
with CoherenceSync.
public SerializeEntityID UnityObjectToEntityId(Transform from)
Parameters
from
Transform
Returns
- SerializeEntityID
Events
OnFixedNetworkUpdate
With MultiClientMode enabled it is recommended to put simulation code in OnFixedNetworkUpdate event handlers instead of FixedUpdate. This allows multiple connected clients within the application to execute at different frequencies for correct network synchronization. The Time.fixedDeltaTime should be applied similar to how it is normally used in FixedUpdate.
public event Action OnFixedNetworkUpdate
Event Type
OnLateFixedNetworkUpdate
Similar to OnFixedNetworkUpdate but guaranteed to be called later.
public event Action OnLateFixedNetworkUpdate
Event Type
OnTimeReset
Triggered the first time SetServerSimulationFrame(AbsoluteSimulationFrame) is called and at any subsequent call if ClientSimulationFrame and ServerSimulationFrame have drifter too far apart.
public event Action OnTimeReset