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
SimulatorConnectionEntry
The prefab to use when this CoherenceBridge
instantiates a simulator connection.
public CoherenceSyncConfig SimulatorConnectionEntry
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
public string networkPrefix
Field Value
onConnected
Invoked when the CoherenceBridge
has successfully connected.
public UnityEvent<CoherenceBridge> onConnected
Field Value
- UnityEvent<CoherenceBridge>
onConnectionError
Invoked when the CoherenceBridge
experiences a connection error.
public UnityEvent<CoherenceBridge, ConnectionException> onConnectionError
Field Value
- UnityEvent<CoherenceBridge, ConnectionException>
onDisconnected
Invoked when the CoherenceBridge
has disconnected.
public UnityEvent<CoherenceBridge, ConnectionCloseReason> onDisconnected
Field Value
- UnityEvent<CoherenceBridge, ConnectionCloseReason>
onLiveQuerySynced
Invoked when all entities that originated from a CoherenceLiveQuery have been synced.
public UnityEvent<CoherenceBridge> onLiveQuerySynced
Field Value
- UnityEvent<CoherenceBridge>
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
- UnityEvent<CoherenceBridge, NetworkEntityState>
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
AutoLoginAsGuest
public bool AutoLoginAsGuest { get; }
Property Value
Client
Reference to the IClient of the bridged connection.
public IClient Client { 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
FloatingOriginManager
Contains the API for manipulating with your Floating Origin.
public FloatingOriginManager FloatingOriginManager { get; }
Property Value
GlobalQueryGameObject
Reference to the GameObject of the global query object.
public GameObject GlobalQueryGameObject { get; set; }
Property Value
- GameObject
GlobalQueryOn
public bool GlobalQueryOn { get; set; }
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
IsConnected
public bool IsConnected { get; }
Property Value
IsConnecting
public bool IsConnecting { get; }
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.
Logger
public Logger Logger { get; }
Property Value
NetStats
public Stats NetStats { get; }
Property Value
NetworkPrefix
Entities spawned by other clients get this prefix attached to their name.
public string NetworkPrefix { get; }
Property Value
NetworkTime
NetworkTime provides access to the network synchronized time and frame state, NetworkTime.
public INetworkTime NetworkTime { get; }
Property Value
NetworkTimeAsDouble
public double NetworkTimeAsDouble { get; }
Property Value
OnAfterFloatingOriginShifted
Invoked after OnFloatingOriginShifted
public Action<FloatingOriginShiftArgs> OnAfterFloatingOriginShifted { get; set; }
Property Value
OnFloatingOriginShifted
Invoked at the end of the floating point origin shifting operation started via SetFloatingOrigin(Vector3d) or TranslateFloatingOrigin(Vector3d), after all objects have been shifted..
public Action<FloatingOriginShiftArgs> OnFloatingOriginShifted { get; set; }
Property Value
Ping
public Ping Ping { get; }
Property Value
Scene
Reference to the Scene of this bridge.
public Scene Scene { 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
Transform
public Transform Transform { get; }
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
WorldPositionMaxRange
Maximum abs position of an entity/liveQuery/floatingOrigin
public static float WorldPositionMaxRange { 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(Entity)
Get the CoherenceSync for a Entity.
public CoherenceSync EntityIdToCoherenceSync(Entity from)
Parameters
from
Entity
Returns
EntityIdToGameObject(Entity)
Get the GameObject
for a Entity.
public GameObject EntityIdToGameObject(Entity from)
Parameters
from
Entity
Returns
- GameObject
EntityIdToRectTransform(Entity)
Get the RectTransform
for a Entity.
public RectTransform EntityIdToRectTransform(Entity from)
Parameters
from
Entity
Returns
EntityIdToTransform(Entity)
Get the Transform
for a Entity.
public Transform EntityIdToTransform(Entity from)
Parameters
from
Entity
Returns
GetClientConnectionEntry()
public CoherenceSyncConfig GetClientConnectionEntry()
Returns
GetCoherenceSyncForEntity(Entity)
Get a CoherenceSync from the mapper.
public ICoherenceSync GetCoherenceSyncForEntity(Entity id)
Parameters
id
EntityA valid Entity (meaning it exists in the mapper)
Returns
GetFloatingOrigin()
Returns the current absolute position of the floating point origin.
public Vector3d GetFloatingOrigin()
Returns
GetNetworkEntityStateForEntity(Entity)
Get a Network Entity State from the mapper.
public NetworkEntityState GetNetworkEntityStateForEntity(Entity id)
Parameters
id
EntityA valid Entity (meaning it exists in the mapper)
Returns
GetSimulatorConnectionEntry()
public CoherenceSyncConfig GetSimulatorConnectionEntry()
Returns
JoinRoom(RoomData)
public void JoinRoom(RoomData room)
Parameters
room
RoomData
JoinWorld(WorldData)
public void JoinWorld(WorldData world)
Parameters
world
WorldData
OnNetworkEntityCreatedInvoke(NetworkEntityState)
public void OnNetworkEntityCreatedInvoke(NetworkEntityState state)
Parameters
state
NetworkEntityState
OnNetworkEntityDestroyedInvoke(NetworkEntityState, DestroyReason)
public void OnNetworkEntityDestroyedInvoke(NetworkEntityState state, DestroyReason destroyReason)
Parameters
state
NetworkEntityStatedestroyReason
DestroyReason
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(Vector3d)
Moves the floating point origin by a translation
vector.
Only works if bridge isConnected, otherwise nothing happens.
public bool TranslateFloatingOrigin(Vector3d translation)
Parameters
translation
Vector3d
Returns
- bool
Returns true if the floating origin was shifted, false if bridge was not connected.
TranslateFloatingOrigin(Vector3)
public bool TranslateFloatingOrigin(Vector3 translation)
Parameters
translation
Vector3
Returns
UnityObjectToEntityId(CoherenceSync)
Get the Entity for a CoherenceSync.
public Entity UnityObjectToEntityId(CoherenceSync from)
Parameters
from
CoherenceSync
Returns
UnityObjectToEntityId(GameObject)
Get the Entity for a
GameObject
with CoherenceSync.
public Entity UnityObjectToEntityId(GameObject from)
Parameters
from
GameObject
Returns
UnityObjectToEntityId(Transform)
Get the Entity for a
Transform
with CoherenceSync.
public Entity UnityObjectToEntityId(Transform from)
Parameters
from
Transform
Returns
Events
OnConnectedInternal
public event Action<ICoherenceBridge> OnConnectedInternal
Event Type
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, Ping) is called and at any subsequent call if ClientSimulationFrame and ServerSimulationFrame have drifter too far apart.
public event Action OnTimeReset