zoukankan      html  css  js  c++  java
  • 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.

    4、State Synchronization有三种取值:

       

    5、RPC的最后一个参数是一个可选的NetworkMessageInfo类型参数:

      

    6、Buffered RPC。

      Buffered RPC calls are stored up and executed in the order they were issued for each new client that connects. This can be a useful way to ensure that a latecoming player gets all necessary information to start.

    7、RPC注意要点:

      1)RPC function names should be unique accross the scene, if two RPC functions in different scripts have the same name only one of them is called when RPC is invoked.

      2)RPC calls are always guaranteed to be executed in the same order as they are sent. 

    8、Networkview的背后:

      1)A Network View is identified across the network by its NetworkViewID which is basically just a identifier which is negotiated to be unique among the networked machines. It is represented as a 128 bit number but is automatically compressed down to 16 bits when transferred over the network if possible.

        每个客户端的NetworkView通过NetworkViewID惟一标识。

      2)Each packet that arrives on the client side needs to be applied to a specific Network View as specified by the NetworkViewID. Using this, Unity can find the right Network View, unpack the data and apply the incoming packet to the Network View’s observed object.

        当收到一个数据包时,根据NetworkView的NetworkView的ID来进行派发。

      3)If you use Network.Instantiate() to create your Networked objects, you do not need to worry about allocating Network Views and assigning them yourself appropriately. It will all work automatically behind the scenes.

        当使用Network.Instantiate(),创建的对象会自动绑定一个NetworkView组件。

     

  • 相关阅读:
    selenium的鼠标事件操作
    selenium选择框
    selenium的三种等待方法
    selenium定位方法-iframe元素定位方法
    selenium的元素定位方法-By
    selenium的定位方法-多元素定位
    selenium的定位方法-单元素定位
    GUP架构---显卡(一)
    关于不同开发语言之间,内存(数据or对象)交互之间的一些总结
    tolua中的peer表简单总结
  • 原文地址:https://www.cnblogs.com/tekkaman/p/3800167.html
Copyright © 2011-2022 走看看