Web Player Streaming 网络播放器流处理
Web Player Streaming is critical for providing a great web gaming experience for the end user. The idea behind web games is that the user can view your content almost immediately and start playing the game as soon as possible instead of making him wait for a progress bar. This is very achievable, and we will explain how.
网络播放器流处理是为最终用户提供一个令人满意的网络游戏体验的关键。网页游戏能提供用户能几乎立即查看内容和尽快开始玩游戏而不是等待一个进度条。这是可以实现的,接下来我们讲解如何实现。
Tuning for Portals 对于门户网站优化
This section will focus on publishing to online game portals. Streaming is useful for all kinds of contents, and it can easily be applied to many other situations.
这部分着重介绍发布到在线游戏门户网站。流用来所有种类的内容,它可以很容易地应用到其他许多情况。
Online game portals expect that some form of game play really starts after downloading at most 1 MB of data. If you don't reach this makes it that much less likely for a portal to accept your content. From the user's perspective, the game needs to start quickly. Otherwise his time is being wasted and he might as well close the window.
在线游戏门户网站期望,游戏真正开始后下载最多1 MB的数据。如果你没有达到,这使得门户网站接受您的内容可能少得多。从用户的角度来看,游戏需要迅速启动。如果用户浪费的时间过多,他可能会关闭该窗口。
On a 128 kilobit cable connection you can download 16 KB per second or 1 MB per minute. This is the low end of bandwidth online portals target.
在128KB的网线,每秒下载16KB或每分钟下载1MB。这是在线游戏门户网站低带宽目标。
The game would optimally be set up to stream something like this:
游戏优化设置为流,像这样:
- 50 KB display the logo and menu (4 seconds)
50 KB显示标志和菜单(4秒) - 320 KB let the user play a tiny tutorial level or let him do some fun interaction in the menu (20 seconds)
320 KB 让容易玩一个小的教程关卡或让他做一些有趣的互动菜单(20秒) - 800 KB let the user play the first small level (50 seconds)
800 KB让用户玩第一个小关卡(50秒) - Finish downloading the entire game within 1-5 MB (1-5 minutes)
完成下载整个游戏在1-5MB(1-5分钟)
The key point to keep in mind is to think in wait times for a user on a slow connection. Never let him wait.
要牢记的关键一点是连接速度很慢的用户在等待时间。千万不要让他等。
Now, don't panic if your web player currently is 10 MB. It seems daunting to optimize it, but it turns out that with a little effort it is usually quite easy to structure your game in this fashion. Think of each above step as an individual scene. If you've made the game, you've done the hard part already. Structuring some scenes around this loading concept is a comparative breeze!
现在,如果你的当前游戏是10MB,不用担心。这似乎是艰巨的优化,但事实证明,一点点的努力,通常很容易让你的游戏有这种方式的结构。想一想上述步骤作为每个作为单独的场景。如果您所做的游戏,已经做了最困难的部分了。构建一些场景解决这个加载的概念,是比较轻而易举的事。
If you open the console log (Open Editor Log button in the Console window(Desktop Platforms); Help -> Open Editor console log menu OSX) after or during a build, you can see the size of each individual scene file. The console will show something like this:
如果你打开控制台日志(打开编辑器,在控制台窗口中日志"按钮(桌面平台);Help ->在OSX平台打开编辑器控制台日志菜单)之后或编译过程中,可以看到每个场景文件的大小。控制台会显示像这样:
***Player size statistics*** Level 0 'Main Menu' uses 95.0 KB compressed. Level 1 'Character Builder' uses 111.5 KB compressed. Level 2 'Level 1' uses 592.0 KB compressed. Level 3 'Level 2' uses 2.2 MB compressed. Level 4 'Level 3' uses 2.3 MB compressed. Total compressed size 5.3 MB. Total decompressed size 9.9 MB.
This game could use a little more optimization! For more information, we recommend you read the reducing file size page.
游戏使用更多的优化,有关更多的信息,建议阅读减少文件大小页面。
The Most Important Steps 最重要的步骤
- Load the menu first. Showing an animated logo is a great way to make time go by unnoticed, thus letting the download progress further.
首先加载菜单。显示动画徽标是的绝佳方式,这样就注意不到加载的时间,从而进一步下载进度。 - Make the first level be short and not use a lot of assets. This way, the first level can be loaded quickly, and by keeping the player occupied playing it for a minute or two you can be sure that the download of all remaining assets can be completed in the background. Why not have a mini tutorial level where the user can learn the controls of the game? No reason for high-res textures here or loads of objects, or having all your enemies in the first level. Use the one with the lowest poly-count. And yes, this means you might have to design your game with the web player experience in mind.
制作的第一个关卡并不适用大量资产。这样,第一个关卡可以被快速加载,并保持玩家游戏1-2分钟时间,可以确保在后台完成所有剩余资产的下载。为什么不有一个小的教程关卡,用户可以在其中学习的游戏控制呢?在第一个关卡里没有理由加载高解析度纹理或加载的对象,或所有的敌人,使用最低的多边形数,是的,这意味着你可能有了游戏设计与网络播放器的经验在头脑里。 - There is no reason why all music must be available when the game starts. Externalize the music and load it via the WWW class. Unity compresses audio with the high quality codec, Ogg Vorbis. However even when compressed, audio takes up a lot of space, and if you have to fit things into 3 MB, if you have 5 minutes of music all the compression in the world won't save you. Sacrifices are needed. Load a very short track that you can loop until more music has been downloaded. Only load more music when the player is hooked on the first level.
当游戏开始时,没有理由所有音乐必须可用,外部音乐通过WWW类来加载。Unity压缩音频具有高质量编译码器,Ogg Vorbis。不过,当压缩时,音频占用了大量的空间,如果所有的压缩你有3MB的东西,5分钟的音乐,那这救不了你,做些牺牲是必须的。加载一个很短的音轨,可以循环,直到更多的音乐已被下载。当播放器已经正常运行第一个关卡时,才加载更多的音乐。 - Optimize your textures using their Import Settings. After you externalize music, textures easily take up 90% of the game. Typical texture sizes are too big for web deployment. In a small browser window, sometimes big textures don't even increase the visual fidelity at all. Make sure you use textures that are only as big as they must be (and be ready for more sacrifices here). Halving the texture resolution actually makes the texture size a quarter of what it was. And of course all textures should be DXT compressed.
使用它们的导入设置优化纹理。外部音乐加载之后,纹理很容易占用游戏的90%。典型的是web部署时纹理尺寸过大。在小的浏览器窗口,有时候大纹理甚至不增加视觉的逼真度。确保使用的纹理和实际需要的一样大(这里做更多的优化贡献)。纹理分辨率减半,这使得是实际纹理的四分之一。当然所有纹理应DXT压缩。 - Generally reduce the size of your web players. There is a manual page committed to the utilities Unity offers for optimizing file size here. Although Unity uses cutting edge LZMA-based compression which usually compresses game data to anywhere from one half to a third of the uncompressed size, you'll need to try everything you can.
一般减少网络播放器文件的大小,手册有针对的工具,Unity提供的文件优化大小在这里。虽然Unity使用尖端的LZMA-based压缩,通常压缩游戏数据是原来大小的二分之一,三分之一。你需要尝试一切可能的。 - Try to avoid Resources.Load. While Resources.Load can be very handy, Unity will not be able to order your assets by when they are first used when you use Resources.Load, because any script could attempt to load the Resource. You can set which level will include all assets that can be loaded through Resources.Load in the Edit->Project Settings->Player using the First Streamed Level With Resources property. Obviously you want to move Resources.Load assets as late as possible into the game or not use the feature at all.
尽量避免使用Resources.Load,虽然Resources.Load是非常方便,当使用Resources.Load加载资源时,Unity将不会在它们第一次使用时对资源进行排序,因为任何脚本可能试图加载资源。[Resources.Load加载,不分先后,如果在资源过多,网速又达不到的情况下,容易进程阻塞]。你可以设置哪一个关卡包含所有资源通过Resources.Load加载,在Edit->Project Settings->Player使用第一个流关卡带有Resources属性。很明显,想要通过Resources.Load加载资源,比较慢到游戏或者不使用该功能。
Publishing Streaming Web Players 发布流网络播放器
Streaming in Unity is level based, and there is an easy workflow to set this up. Internally, Unity does all the dirty work of tracking assets and organizing them in the compressed data files optimally, ordering it by the first scene that uses them. You simply have to ensure that the first levels in the Build Settings use as few assets as possible. This comes naturally for a "menu level", but for a good web experience you really need make sure that the first actual game levels the player is going to play are small too.
流在Unity是基本的,有很简单的流程设置这个。在内部,Unity跟踪所有资源并组织它们在优化的压缩数据文件,在第一个场景排序使用它们。只需确保第一个关卡在Build Settings使用尽可能少的资源,这顺其自然的就是“菜单关卡”,但是为了良好的网络体验,你真的需要确保第一个实际游戏关卡玩家要玩的也是很小。
In order to use streaming in Unity, you select Web Player Streamed in the Build Settings. Then the content automatically starts as soon as all assets used by the first level are loaded. Try to keep the "menu level" to something like 50-100 KB. The stream continues to load as fast as it can, and meanwhile live decompresses. When you look at the Console during/after a build, you can see how large
为了在Unity使用流,在Build Settings选择Web Player Streamed开始编译。网页加载时内容会自动启动,由第一个关卡使用的所有资源被尽快加载。尝试保持“菜单关卡”大小在50-100KB,流能连续快速加载,并同时解压。在编译过程中或之后,在控制台可以看到有多大。
You can query the progress of the stream by level, and once a level is available it can be loaded. Use GetStreamProgressForLevel for displaying a progress bar and CanStreamedLevelBeLoaded to check if all the data is available to load a specific level.
可以按关卡查询流加载的进度,关卡被激活时它将被加载,使用GetStreamProgressForLevel来显示进度条,使用CanStreamedLevelBeLoaded来检查,是否所有数据可用以加载到指定的关卡。
This form of streaming is of course linear, which matches how games work in most cases. Sometimes that's not enough. Therefore Unity also provides you with API's to load a .unity3d file manually using the WWW class. Video and audio can be streamed as well, and can start playing almost immediately, without requiring the movie to be downloaded first. Finally Textures can easily be downloaded via the WWW class, as can any textual or binary data your game might depend on.
流的形式当然是线性的,匹配游戏在大多数情况下的工作方式。有时这是不够的,因此,Unity还提供了API来手动加载.unity3d文件,使用WWW类。视频和音频可以进行流式处理,并且可以几乎立即开始播放,而无需首先下载影片。最后,纹理很容易通过WWW类下载,依赖于游戏的任何文本或二进制数据。
页面最后更新:2010-09-07