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

[Unity 组件参考手册]桌面:网络参考指南之状态同步的细节

[复制链接]
.    

3797

主题

11

听众

5万

积分

首席设计师

Rank: 8Rank: 8

纳金币
32328
精华
41

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

跳转到指定楼层
楼主
发表于 2013-2-19 17:03:01 |只看该作者 |倒序浏览
You can enable State Synchronization per Network View by choosing either Reliable Delta Compressed or Unreliable from the State Synchronization drop-down. You must then choose what kind of data will synchronized in the Observed property.每个NetworkView都能通过在状态共享下拉菜单中选择可靠的有延迟的压缩或者不可靠的选项来开启状态共享,而在Observed(观察者)属性中必须选择设定同步的数据引用。Unity can pack/unpack some specific classes: Transform, Animation, Rigidbody and MonoBehaviour.Unity可以打包/解包一些特殊的类:如变换,动画,刚体,或者是组件。Transforms are serialized by storing position, rotation and scale. Parenting information is not transferred over the network.变换被设计用来保持位置,角度,尺寸。而父层次信息不会通过网络传输。Animation serializes each&nbsp***nning animation state, that is time, weight, speed and enabled.动画内含每一个运行中的动画状态,如时间,重力,速度,和是否激活。Rigidbody serializes position, rotation, velocity and angular velocity.刚体包含了位置,角度,速度和角速度。Scripts (MonoBehaviours) call the function OnSerializeNetworkView().脚本(组件对象)调用OnSerializeNetworkView()函数。
Reliability and bandwidth 可靠性和带宽Network Views currently support two types of reliability. Reliable Delta Compressed and Unreliable.网络视图当前支持两种类型的可靠性设定。压缩的延迟的可靠性和不可靠。Both have their own advantage and disadvantages, and the right mode should be chosen on a case by case basis.这两种都有着自己的优势和劣势,正确的模式应该具体问题具体分析。For additional information about minimizing bandwidth, please read the Minimizing Bandwidth page.更多关于最小化带宽的附加信息,请查阅Minimizing Bandwidth page。
Reliable Delta Compressed 压缩的延迟的可靠性Reliable Delta Compressed mode will automatically compare the data that was last received by the client. If no data has changed compared to it, no data will be sent. But on top of that the data will also be compared on a per property basis. For example, if your position has changed but your rotation has not. Only the position has to be sent across the network.RDC(压缩的延迟的可靠性,我简写了,大家没意见吧)模式自动比对最后从客户端接收的数据。如果没有变化,没有数据会被发送。由于这个过程是按属性进行的,那么举个例子,如果你的位置变了,但角度没变,那么只有位置会被通过网络发送。In this mode, Unity internally packs one bit prior to each property that determines if the data has actually changed. If it has not changed, the property will not be included in the serialized data thus saving a lot of bandwidth.在这种模式下,如果数据确实的改变了,Unity内部会将改变了的每个属性转换成位。如果没有改变,属性不会被包括尽串行数据汇中,因此会节约大量带宽。Unity will also ensure that every packet that is sent will arrive by resending the packet in the case of UDP packet drop until it is received. This means that if a packet is dropped, any packets sent later will not be applied until the dropped packet is re-sent and received. Until then, all later packets will wait in the buffer.Unity会确保被发送的每一个包都会到达,甚至是在UDP包丢失的情况下也会通过重发确保其被送达。这意味着如果有一个包丢失,直到丢失的包被重发接收之前,所有之后发送的包都不会被应用,所有后发的包会等待在缓冲中。
Unreliable 不可靠In Unreliable mode, Unity will send out the current state regardless of if it has changed or not. State will not be delta compressed since it is unknown if the sent data will actually arrive on the receiver.在不可靠模式下,Unity会发送所有的状态而不管它是否改变。状态不会压缩的延迟,无法得知发送的数据是否被接收者收到。
Deciding which method to use 决定使用何种方法The Network layer uses UDP which is an unreliable unordered protocol but it can send reliable ordered packets, just like TCP does. It internally uses ACKs and NACKs to control packet transmission, ensuring no packets are dropped. The downside to using reliable ordered packets is that if a packet is dropped or delayed, everything stops until that packet has arrived safely. This can cause noticeable delays in transmission in lag intensive networks.网络层使用UDP工作,这是一种不可靠无次序的协议,但它也能发送可靠次序的包,就如同TCP能做到的一样。内在的它使用ACKs和NACKs(确认和反确认)来控制包的传输,可以保证没有包丢失。使用可靠次序的包的机制,在一个包丢失或者延迟的情况下,会带来性能损失。在丢失的包安全到达前所有的事情都会暂停。在滞后的网络条件下,这会导致明显能被察觉的延迟。Unreliable sending is useful for data where you know that it is going to change every frame anyway. For example, in a racing game, you can practically rely on that the player's car is always moving. Thus delta compression and reliable transfer only adds overhead without adding an practical gain.不可靠的发送对于你所发现的每帧都会发生变化的数据是非常有用的。例如,一个赛车游戏几乎完全依赖玩家的车体始终不停的移动。然而延迟的压缩和可靠传输只会增加增加你的管理费用而不会增加你的收入。(隐寓)In general, you should use Unreliable sending when you know data is changing all the time and minimizing lag is critical. If the data tracked by the Network View is not changing every frame and bandwidth is important to you, then delta compressed is preferred.通常来说,当你发现数据总是变化而且需要最小化数据延迟,你应该使用不可靠的传输。如果网络视图追踪的数据并不是每帧都发生变化,而且带宽对你来说更重要的话,请使用延迟的压缩模式。It is important to understand that lag is not the same thing as bandwidth. They are two separate properties that you want to optimize for in different use case.有一点很重要,延迟和带宽并不是同一件事。他们是在你想要为不同场景优化时存在的两个分离的属性。
Prediction 预测When the server has full authority over the world state, the clients only update the game according to these states they receive from the server. One problem which arises is that controls feel unnatural as when a player pushes the forward button for example, he won't move until the updated state is received from the server. This delay depends on the latency of the connection so the worse the connection the more unnatural the actions of the player become.当服务器全权管理世界状态时,客户端只是根据他们从服务器接收的状态更新游戏。当一个用户按住向前按钮时可能会出现意外,控制会变得不自然。在直到状态从服务器返回前他的角色不能移动。基于连接的延迟在较差的连接下会使用户的动作变得更糟。One way to help with this is Player Prediction which means the client, knowing how the server calculates his movement, predicts the movement himself. So the player moves instantly with the control but the server sees his position from his last update. When the state update arrives from the server, the client will compare what he predicted with what actually happened. This might differ as the server might know more about the environment around the player, the client just knows what he needs to know. Errors in prediction are corrected as they happen, if they are corrected gradually the correction will look more smooth and less noticeable.解决之道是客户端的角色预判技术,假设服务器会如何计算角色的移动,并预测角色的移动情况。因此用户角色即时的跟随用户的控制移动但在服务器看来角色最后的位置并没有移动。当状态的更新到达服务器时,客户端会比较他对角色的预测和服务器内实际发生的变化。服务器可能更多的了解客户端周围的环境,客户端却只知道他需要知道的部分,这两者间是有差异的。预判的错误发生时会得到修正,如果他们被逐步的修正屏幕上看起来会更加细腻而更少被玩家所察觉。
Dead reckoning or interpolation/extrapolation 航位推测法或内插/外插法It is possible to apply the same principle with player prediction to the opponents of the player. Extrapolation is when several last (buffered) known position, velocity and direction of an opponent is used to predict where he will be in the next frames. When the next state update finally arrives with the correct position, the client state will be updated with accurate information, possibly skipping if the prediction was bad. In FPS games the behavior of players can be very erratic so this kind of prediction only has limited effect. If the lag gets high enough the opponent will skip badly as the errors in prediction get larger.如果可能请给玩家角色以外的角色也使用同样的预测技术。外推(法)是指当几个最近(缓冲)确认的对手位置、对手速度和对手方向被用于预测玩家角色下一帧会出现的位置。当下一个状态最终被正确的位置更新时,客户端的状态会被精确的信息更新,如果预测错误可能会出现闪烁。在每秒帧数比较重要的游戏中,角色的行为会变得非常古怪,因此这种预测只能带来有限的效果。足够高的延迟情况下,预测会产生更大的错误而使对手的位置飘忽不定而变得更糟。Interpolation is when packets get dropped on the way to the client and the opponent position would normally pause and then jump to the newest position when a new packet finally arrives. By delaying the world state by some set amount of time (like 100 ms) and then interpolating the last known position with the new one, the movement between these two points, where packets were dropped, will be smooth.内插法指发向客户端的包丢失的时候,对手的位置一般情况下会暂停,然后当最终一个新的包送到本地时对手会跳跃至最新的位置。通过设定世界状态的延迟的数值(比如100ms),然后通过外插法根据最后的已知位置得出新的在两点中的移动位置。这种做法在有包丢失的情况下,会使得运动变得柔和。
【来源:互联网】
更多精彩教程,尽在web3D纳金网http://www.narkii.com/college/
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

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

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

GMT+8, 2024-11-23 09:44 , Processed in 0.598959 second(s), 32 queries .

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

© 2008-2019 Narkii Inc.

回顶部