NetManager
NetManager is a MonoSingleton. It contains a Client and manages connection and requests with it.
Version is the Application.version
. It is sent to the server at connection. The first connected client defines the server version with it. After, all other clients must have the same version.
Connection to a server
First, instantiate a GameObject with a NetManager
component (or create it in a scene).
If Auto connect
is checked, it logins on start. (used in development)
Else, use
bool success = await NetManager.Connect(address, port, password, version);
If version
is null or empty, Application.version
is used.
Close connection
Client gets disconnected when NetManager is destroyed or if you call the Disconnect
method.
NetManager.Disconnect();
Host priority
Host priority is a number [0:255]. It can be used to defines who is the hosters. (less priority = host).
example
Host | Priority | Hoster ? |
---|---|---|
Player 1 | 1 | No |
Player 2 | 0 | Yes |
Player 3 | 1 | No |
Player 4 | 0 | Yes |
Player 5 | 2 | No |
await NetManager.SetHostPriority(value)
Get Informations
// Get a list of players IDs.
NetManager.GetPeerIdList();
// Get Latency.
NetManager.GetLatency();
NetManager.GetLatency(int peerId);
// Get a list of Host priorities.
NetManager.GetHostsPriorityList();
// Get main Cloud
NetManager.GetCloud();
// get the Client object
NetManager.GetClient();
// Get local peer Id
NetManager.GetPeerId();
// Get the scene ID from asset ID
NetManager.GetSUIDFromGUID(string guid);