Unity networking

16
Unity Networking Game networking, simplified

Transcript of Unity networking

Page 1: Unity networking

Unity NetworkingGame networking, simplified

Page 2: Unity networking

About UNet

◎UNet has been released with Unity 5.0◎UNet is a server created from a client◎UNet supports matchmaking

Page 3: Unity networking

High level APIWhat doesn’t kill you...

Page 4: Unity networking

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

Page 5: Unity networking

High Level API

Page 6: Unity networking

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.

Page 7: Unity networking

High Level API Components

Network IdentityThis component controls an object’s network identity, and it makes the networking system aware of it.

Page 8: Unity networking

High Level API Components

The NetworkManager is a class that allows control the state of a networked game.

Page 9: Unity networking

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.

Page 10: Unity networking

UNet ScriptingMakes the life easier for you

Page 11: Unity networking

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.

Page 12: Unity networking

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);}

Page 13: Unity networking

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();

Page 14: Unity networking

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);

}

Page 15: Unity networking

Final VerdictBecause you want it

Page 16: Unity networking

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