NetworkView

游戏Server中Server的类别

  There are two common and proven approaches to structuring a network game which are known as Authoritative Server and Non-Authoritative Server. 

1、Authoritative Server

  The authoritative server approach requires the server to perform all world simulation, application of game rules and processing of input from the player clients. Each client sends their input (in the form of keystrokes or requested actions) to the server and continuously receives the current state of the game from the server. The client never makes any changes to the game state itself. Instead, it tells the server what it wants to do, and the server then handles the request and replies to the client to explain what happened as a result.

  An advantage of this approach is that it makes cheating much harder for clients. For example, clients do not have the possibility of cheating by telling the server (and thereby other clients) that an enemy has been killed, since they don‘t get to make that decision by themselves. They can only tell the server that a weapon was fired and from there, it is up to the server to determine whether or not a kill was made.

2、Non-Authoritative Server

  与Authoritative Server相反,把逻辑放在客户端。

Methods of Network Communication

1、RPC。适合于非频繁的调用。

2、State Synchronization

  State Synchronization is used to share data that is constantly changing. The best example of this would be a player‘s position in an action game. The player is always moving, running around, jumping, etc. All the other players on the network, even the ones that are not controlling this player locally, need to know where he is and what he is doing. By constantly relaying data about this player‘s position, the game can accurately represent that position to the other players.

Networking Elements in Unity

1、Creating a Server:

  you simply call Network.InitializeServer() from a script. When you want to connect to an existing server as a client, you call Network.Connect()instead.

2、Network View

  Is a Component that sends data across the network. Network Views make your GameObject capable of sending data using RPC calls or State Synchronization

  1)RPC

    Are functions declared in scripts that are attached to a GameObject that contains a Network View.

3、Network.Instantiate()

  Network.Instantiate() lets you instantiate a prefab on all clients in a natural and easy way. Essentially this is an Instantiate() call, but it performs the instantiation on all clients.

 

NetworkView,布布扣,bubuko.com

NetworkView

上一篇:exec php


下一篇:php拾遗: 类型约束