游戏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组件。

NetworkView的更多相关文章

  1. Unity自带网络功能——NetworkView组件、Serialize、RPC

    Unity拥有大量的第三方插件,专门提供了对网络功能的支持.可是,大部分开发人员第一次接触到的还是Unity自带的网络功能,也就是大家常常说到的Unity Networking API.这些API是借 ...

  2. Unity 编译错误记录

    1. 相关代码: NetworkView.RPC ("ReceiveMessage", RPCMode.All, message); 编译输出: Assets/cs/ClientC ...

  3. 关于Unity的网络框架

    注:Unity 5.1里引入了新的网络框架,未来目标应该是WOW那样的,现在还只是个P2P的架子. 网络的框架,无非是如何管理网络数据的收发,通信双方如何约定协议.之前做的框架与GameObject无 ...

  4. 实现类似QQ对话聊天功能脚本

    var skin : GUISkin; var showChat = false;private var inputField = "";private var display = ...

  5. Unity3D核心类型一览

    Unity3D核心类型一览 本文记录了Unity3D的最基本的核心类型.包括Object.GameObject.Component.Transform.Behaviour.Renderer.Colli ...

  6. 【Unity3D游戏开发】之常用代码 (十二)

    //创建一个名为"Player"的游戏物体 //并给他添加刚体和立方体碰撞器. player=new GameObject("Player"); player. ...

  7. [转]unity3d 脚本参考-技术文档

    unity3d 脚本参考-技术文档 核心提示:一.脚本概览这是一个关于Unity内部脚本如何工作的简单概览.Unity内部的脚本,是通过附加自定义脚本对象到游戏物体组成的.在脚本对象内部不同志的函数被 ...

  8. (转载)MonoBehaviour的事件和具体功能总结

    分享一点MonoBehaviour的事件和具体功能总结的基础知识,苦于Visual Studio 2013没有对MonoBehaviour的行为做出智能提示,写个函数都要全手打,记性好的将就着手打,脑 ...

  9. Unity3D脚本中文系列教程(十二)

    http://dong2008hong.blog.163.com/blog/static/4696882720140313545332/ GameObject类,继承自Object Unity场景中所 ...

随机推荐

  1. 关于htonl()

    htons #include <arpa/inet.h> uint16_t htons(uint16_t hostshort); htons的功能:                     ...

  2. DRF 的 版本,解析器,与序列化

    DRF 的 版本,解析器,与序列化 补充 配置文件中的 类的调用: (字符串) v1 = ["view.xx.apth.Role","view.xx.apth.Role& ...

  3. 你所不知道的,Java 中操作符的秘密?

    在 Java 编程的过程中,我们对数据的处理,都是通过操作符来实现的.例如,用于赋值的赋值操作符.用于运算的运算操作符等.用于比较的比较操作符,还包括逻辑操作符.按位操作符.移位操作符.三元操作符等等 ...

  4. ORM版,学生信息管理单表查询..

    mysql 建学生表及课程表 添加内容 view.py from django.shortcuts import render,HttpResponse,redirect from . import ...

  5. MATLAB的一些应用--最近用的比较多

    MATLAB的一些应用--最近用的比较多 1.MATLAB分析信号的频谱 快速Fourier变换(FFT)是离散傅里叶变换的快速算法,他是根据离散傅里叶变换的奇.偶.虚.实等特性,对离散傅里叶变换的算 ...

  6. 迭代器.NET实现—IEnumerable和IEnumerator (foreach实现)

    能用foreach遍历访问的对象需要实现什么接口或声明什么方法的类型? 答案:能用foreach遍历访问的对象必须是集合或数组对象,而这些都是靠实现超级接口IEnumerable或被声明 GetEnu ...

  7. 一次SQL Server 10054 Troubleshooting

    问题 对某个库新增了一个订阅节点,然后需要把一些应用切到新订阅库,以分散负载.当应用切换后,有一个应用每次启动不到30秒,总是报超时的错误,而error log中又没有任何记录: Timeout ex ...

  8. 洛谷P2661 信息传递

    传送门 题目大意:每个人每一轮可以把消息传给另一个人,问几轮后某个人可以从人 听到自己的消息. 题解:tarjian缩点,求缩点后缩的点包含的最少的点个数. 代码: 正解 #include<io ...

  9. Git克隆、修改、更新项目,及查看项目地址命令

    第一步:在本地新建一个文件夹,作为本地仓库,如“texzt”,直接打开该文件夹,并单击右键,选择git bash here 则可以直接进入到该文件夹目录下. 第二步:将本地仓库初始化,命令:git i ...

  10. sublime text 3设置浏览器快捷键

    一.设置默认浏览器 1,打开sublime 依次选择 tools > build system > new build system... 2,选择你喜欢的浏览器,右键 > 属性 把 ...