Unity5.1 new network engine UNET (8) UNET system summary, unity5.1unet
Sun Guangdong
Server and Host
In the Unity network system, the game has one server and multiple clients. When there is no dedicated server, one client plays the role of the server-we call this client "host"
A host is a server in the same process as a client. The host uses a special client called LocalClient, while other clients are RemoteClients. LocalClient communicates with (local) servers through direct function calls and message queues because it is in the same process. It is actually shared with the server. RemoteClients communicates with the server through regular network connections.
The goal of the network system is that the Code of LocalClients and RemoteClients is the same, so developers only need to think about one type of client most of the time.
Instantiate and Spawn
In Unity, GameObject. Instantiate creates a new Unity game object. But together with the networked system, the object must also be "spawned" to be activated on the network. This can only be performed on the server, and the object is created on the connected client. Once an object is generated by the Spawning System, the distributed object lifecycle management and State synchronization are performed.
Players, Local Players and Authority
In the network system, player objects are special. In addition, when playing games, the player Object and commands of each person are routed to this object. One person cannot call commands on another player object-only themselves. So it is the concept of "my" player Object. When a player and a contact are added to connect them, the player object becomes the "local player" object on the player client. It is set to true and calls back the OnStartLocalPlayer () attribute isLocalPlayer called by the object on the client. Display two clients and their local players ..
The isLocalPlayer flag is set for the player Object of "yours. This can be used to filter input, process camera attachments, or do anything other than your player client.
In addition to isLocalPlayer, the player object can have "local authority", which means that the player object on the client of the owner is the owner object-it has authorization. The most commonly used is to control motion, but other things are also used. The NetworkTransform component understands this and will send a mobile message from the client if this option is set. NetworkIdentity has a check box for setting LocalPlayerAuthority.
For non-player objects such as enemies, there are still clients that are not associated, so the authority resides on the server.
The attribute "isAuthority" on NetworkBehaviour can be used to tell whether an object has been authorized. Therefore, non-player objects are on the server, with authority and player objects and localPlayerAuthority authorized on the client of the owner.
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.