标题: [Unity 组件参考手册]桌面:网络参考指南之网络视图 [打印本页] 作者: . 时间: 2013-2-19 17:01 标题: [Unity 组件参考手册]桌面:网络参考指南之网络视图 Network Views are the vehicle used to share data across the network. They allow two kinds of network communication: State Synchronization and Remote Procedure Calls.网络视图是通过网络共享数据的传输工具。通过网络视图可以发起两种类型的网络通信:状态同步和远程过程调用。When you have many clients ***nning the same game, each client has a set of objects which all together make up the game itself. To make two or more clients seem identical, these objects need to be synchronized by sharing data. This is called State Synchronization. Synchronizing the state of every object in the game requires a massive amount of data, easily too much data to be practically sent across the network and keep your game playable. To address this, Network Views are used to specify what data will be shared, and therefore which objects will be synchronized. Each Network View watches a specific part of an object and makes sure it is synchronized with the same object on other clients. More information about State Synchronization can be found on the State Synchronization page.当你在一个游戏中友许多客户端运行。每一个客户端都有一个组成游戏的对象的集合。为了让两个或者多个客户端看起来一致,这些对象需要通过共享数据同步。这种行为叫做状态同步。如果在游戏中同步每个对象的状态需要传输大量的数据,为使你的游戏变得可玩,事实上这会很容易通过网络发送过多的数据。为了解决这一问题,网络视图被用于定义什么数据将被共享,哪一个对象将被同步。每一个网络视图观察对象的特定部分并使它和其他客户端的相同对象实现同步。更多关于状态同步的内容可以查阅State Synchronization page。There are other network scenarios like when you want to send out the position of an object or respawn an item for someone to pick up. Because these are one-time, infrequent operations, it does not make sense to synchronize the state of the involved objects. Instead, you use a Remote Procedure Call to tell the clients or server to perform an operation. More information about Remote Procedure Calls can be found on the RPC Details page.在某些网络使用的场景下,比如当你想发送一个对象的位置或者当某人捡起某个物体,你需要创建这个物品时。应为这是一次性,偶然的操作,它不需要对涉及的对象的状态进行连续的同步。因此,你可以使用远程调用来告诉客户端或者服务器执行这个操作,更多关于远程过程调用的内容请查阅RPC Details page。
Technical Details 技术细节Network Views are identified across the Network by NetworkViewID's. A NetworkViewID is basically a unique identifier of an object that all networked machines agree on. It is implemented as a 128 bit number but is automatically compressed down to 16 bit when transferred over the network where possible.网络视图通过网络视图ID唯一标志。一个网络视图ID是在所有网络机器都认可的一个对象的唯一标志。它被实现为128位的数字但当在通过网络传输时能被自动压缩为16位。Each packet that arrives on the client side needs to be applied to a specific Network View. The NetworkViewID uniquely identifies to which Network View it belongs. Using the NetworkViewID, Unity can find the right Network View, unpack the data and finally apply the incoming packet to the Network View's observed object.每一个在客户端接收的包都需要被指定到一个特殊的网络视图。网络视图ID唯一的标志了所归属的网络视图。使用网络视图ID,Unity能发现正确的网络视图,解包数据并最终将传入的包中的数据同步到网络视图所观察的对象。More details about using Network Views in the Editor can be found on the Network View Component Reference page.更多关于在编辑器中使用网络视图的细节能在Network View Component Reference page中找到。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 under the hood.如果你使用Network.Instantiate()来创建你的网络对象,你不需要关注如何分配网络视图和如何关联对象。所有工作在底层已被自动完成了。However, you can manually control the NetworkViewIDs of each Network View by using Network.AllocateViewID. The Scripting Reference documentation shows an example of how an object can be manually instantiated on every client with an RPC function and then the NetworkViewID manually set with AllocateViewID``.当然,你也能通过Network.AllocateViewID人为控制每个网络视图的网络视图ID。脚本索引文档里有个例子,展示了如何通过RPC函数在每个客户端人工实例化一个对象,然后通过AllocateViewID赋予网络视图ID。 【来源:互联网】
更多精彩教程,尽在web3D纳金网http://www.narkii.com/college/作者: nts 时间: 2013-10-20 13:05
网络参考指南之网络视图