查看: 3049|回复: 0
打印 上一主题 下一主题

[Unity 组件参考手册]桌面:网络参考指南之网络实例化

[复制链接]
.    

3797

主题

11

听众

5万

积分

首席设计师

Rank: 8Rank: 8

纳金币
32328
精华
41

活跃会员 优秀版主 荣誉管理 论坛元老

跳转到指定楼层
楼主
发表于 2013-2-19 17:03:39 |只看该作者 |倒序浏览
Network Instantiate lets you Instantiate a prefab on all clients in a very easy to use way. When a player calls Network.Instantiate(), they control any Input commands on that GameObject. All the setup and handling is performed under the hood, so all you need to do to assign control is make each player call Network.Instantiate() on the GameObject they should control.网络实例化让你可以非常容易的在所有客户端实例化一个预制件。当一个玩家调用Network.Instantiate(),可以控制游戏对象上的任何输入命令。所有的安装和处理都被隐藏在实现中,因此你所需要做的只是在每个玩家所能控制的游戏对象上调用Network.Instantiate()使玩家能控制该对象。Instantiating prefabs is one of the most important concepts in Unity. Network Instantiate is an extension to it, which lets you with a single function call instantiate an object across all machines on the network.可实例化预制件是Unity最重要的组成之一。Network Instantiate是对这个组成的扩展,让你可以通过使用一个函数在所有连接的机器上实例化一个游戏对象。The argument list for Network.Instantiate() is as follows:Network.Instantiate()的参数如下:static function Instantiate (prefab : Object, position : Vector3, rotation : Quaternion, group : int) : ObjectLike Instantiate the first three parameters describe the prefab to be instantiated and the position and rotation of where it should be placed. Additionally the group is passed in as an argument. Usually you just pass in 0 as the group. The group number allows you to group together network messages which allows you to filter them if so desired.如同实例化一样 ,头三个参数描述了被用于实例化的预制件和将放置预制件的位置和角度。组做为附加的参数也被作为参数传递。通常你只是默认传递0值。 组号码允许你过滤期望的网络信息并把它们组织在一起。
Technical Details 技术细节Behind the scenes, Network Instantiate is simply a convenience function built around RPC calls. It serializes an identifier of the prefab that is to be instantiated, serializes all allocated NetworkViewID's, serializes the position, and send it across the network using an RPC call. Network.Instantiate() will always buffer the Instantiate call in the RPC buffer, this also means it can be removed from the buffer in the same way as other RPC calls.在场景的背后,网络实例化只是一个依赖RPC调用的方便函数。通过序列化一个被实例化的预制件的编号,和所有分配的NetworkViewID和位置,然后通过网络使用RPC调用传递。Network.Instantiate()总是会在RPC buffer中缓冲实例化调用,这也意味着能像其他RPC调用那样能从缓冲中移除。In essence this is a regular instantiation that is performed on all clients and automatically buffered. Players that join after the instantiation was performed will also receive the Instantiate call.本质上来说这是一个在所有客户端执行并自动缓冲的标准实例化。在实例化后加入的玩家也会收到实例化调用并执行。
Communication Groups 通信组Communication groups are important to differentiate communication and disable receiving/sending to some clients.通信组对于有区别的通信和取消一些客户端的发送接收操作有重要的作用。For example, two connected players might be in separate room without being able to meet. Thus there is no reason to transfer state of the two player avatars and depending on your situation. You could have one group for game data and one for chat communication. The game data group might be blocked when loading a level but the chat group kept open so players can communicate.例如,两个已连接的用户可以在不同的房间中而没有可能相互接触,因此在你的方案中没有理由在两个用户之间传输替身的状态。你能使用一个组来传输游戏状态,然后用另外一组来传输聊天通信。游戏数据组能在加载一个关卡时被中止。但聊天组可以保持开放,因为用户总是想要相互发消息。 【来源:互联网】
更多精彩教程,尽在web3D纳金网http://www.narkii.com/college/
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

手机版|纳金网 ( 闽ICP备2021016425号-2/3

GMT+8, 2024-11-15 23:03 , Processed in 0.298073 second(s), 33 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部