- 最后登录
- 2018-12-19
- 注册时间
- 2012-8-20
- 阅读权限
- 90
- 积分
- 54706
- 纳金币
- 32328
- 精华
- 41
|
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/ |
|