When scripting simulators, we need mechanisms to tell them apart.
Ask Coherence.SimulatorUtility.IsSimulator.
There are a few ways you can tell coherence if the instance should behave as a simulator:
Specifying a ConnectionType when connecting via Coherence.Network.Connect.
COHERENCE_SIMULATOR preprocessor define.
--coherence-simulation-server command-line argument.
Toggling on Simulator in the sample connection dialog.
Connect and ConnectionTypeThe Connect method on Coherence.Network accepts a ConnectionType parameter.
Whenever the project compiles with the COHERENCE_SIMULATOR preprocessor define, coherence understands that the game will act as a simulator.
Launching the game with --coherence-simulation-server will let coherence know that the loaded instance must act as a simulator.
You can define who simulates the object in the CoherenceSync inspector.
The provided includes auto-reconnect behaviour out of the box for simulators. The root GameObject has an AutoReconnect component attached to it.
If you need a different solution, take a look at its implementation use plug your own.
using Coherence;
if (SimulatorUtility.IsSimulator)
{
// I'm a simulator!
}using Network = Coherence.Network;
using ConnectionType = Replication.Client.Unity.Ecs.ConnectionType;
public class ConnectAsSimulator : MonoBehaviour
{
void Start()
{
if (Network.Connect("127.0.0.1:32001", ConnectionType.Simulator))
{
// Connection successful
}
else
{
// Connection failed
}
}
}#if COHERENCE_SIMULATOR
// simulator-specific code
#endif

