unity networking
TRANSCRIPT
Unity NetworkingGame networking, simplified
About UNet
◎UNet has been released with Unity 5.0◎UNet is a server created from a client◎UNet supports matchmaking
High level APIWhat doesn’t kill you...
High Level API (HLAPI)
◎Built on top of of Transport Real Time Layer
◎Work in conjunction with Internet Services◎Provides services for multiplayer such as:
Message handlersHigh performance serializationDistributed object managementState synchronizationNetwork classes: Server, Client, Connection, etc
High Level API
High Level API Components
NetworkReader◎ NetworkReader is a class for reading objects from byte streams.
NetworkServer◎ NetworkServer is a High-Level-API class that manages connections from
multiple clients.NetworkClient◎ NetworkClient is a class that manages a network connection to a server ◎ It is used to send messages and receive messages from the server. ◎ The NetworkClient also helps manage spawned network objects, and
routing of RPC message and network events.
High Level API Components
Network IdentityThis component controls an object’s network identity, and it makes the networking system aware of it.
High Level API Components
The NetworkManager is a class that allows control the state of a networked game.
High Level API Components
The NetworkLobbyManager is a specialized type of NetworkManager that provides a multiplayer lobby before entering the main play scene of the game.
UNet ScriptingMakes the life easier for you
High Level API Components
[ServerCallback]Do server-side stuff, initializing game objects can be used here. Syncing objects can also be used here.newObject.transform.position = newObjectPosition; Network Transform will sync new position across all clients. Values are updated on the server side, clients will have their old positions marked as Dirty() and update to the server's values.
High Level API Components
[ClientCallback]Do client-side stuff, make them only run on clients, but not generate warnings. Client may have registered prefab from the Network Manager, but it's better to have it available in the Hierarchy before continuing.GameObject prefabObject = GameObject.FindGameObjectWithTag("SamplePrefab");if (prefabObject != null) { CmdDoAction(prefabObject);}
High Level API Components
[Command]You do stuffs that the client wants the server to do or just have the server do something for the client.GameObject obj = Instantiate(objectToUse);NetworkServer.SpawnWithClientAuthority(obj, this.connectionToClient);Once the server has done whatever it needs to do, you can choose if you want to have all clients do other actions. RpcDoAction();
High Level API Components
[ClientRpc]Do broadcasting, where all clients will do.if (!this.hasAuthority) { //Clients with no authority can do.
Ping(new Vector3(0f, 10f, 0f), Color.red); } else {
//Do something in which the client itself has Ping(new Vector3(0f, 10f, 0f), Color.green);
}
Final VerdictBecause you want it
High Level API Components
Pros◎ Free to use, if using Unity service, free package covers max 20 users.◎ If using own server, unlimited usage◎ Deep customizable API, both on lower and higher levels◎ Matchmaking, ‘nuff said◎ Having both client and server codes in the same project◎ Much quicker to program than usual server
Cons◎ If there is one, I don’t see it yet