WWW.LoadFromCacheOrDownload 加载自缓存或下载

static function LoadFromCacheOrDownload (url : string, version : int) : WWW

Parameters参数

Returns

WWW - a WWW instance, which can be used to access the data once the operation is completed. * var www = WWW.LoadFromCacheOrDownload("http://myserver.com/myassetBundle.unity3d", 5); * * yield www; * * if (www.error != null) * { * Debug.Log(www.error); * return null; * } * var myLoadedAssetBundle = www.assetBundle;

返回一个WWW实例,一旦操作完成,它可用于访问数据。

Description描述

Loads an assetBundle from the cache, or downloads it, in case it is not cached.

从缓存加载一个资源包,如果没有被缓存,或从下载加载。

This works just like "new WWW(url)", with the difference that the download will be written to the disk cache, and only be actually performed if the AssetBundle is not already cached. Unlike "new WWW()", this can only be used to load AssetBundles. A cached asset bundle is identified by the name / the last path component of the url. If a cached asset does not yet exist, or the version number for the cached asset does not match exactly, it will be downloaded and stored in the cache along with the version number provided by the version parameter. Since cached asset bundles are identified by name instead of full url, you can change the directory from where the asset bundle is downloaded at any time. This is useful for pushing out new versions of the game and ensuring that files are not cached incorrectly by the browser or by a CDN. If the cache folder does not have any space for caching additional files, LoadFromCacheOrDownload will try to delete the least-recently-used AssetBundle from the Cache. If making space is not possible (because the hard disk is full, or all files in the cache are in use), LoadFromCacheOrDownload() will simply download the file to memory like a normal "new WWW()" call.

这个工作就像"new WWW(url)",不同之处在于下载将被写入到磁盘高速缓存,并且如果资源包尚未被缓存,仅实际执行。不像"new WWW()"这只能用来加载资源包,一个缓存的资源包用过名称或URL的最后一个路径组件被识别。如果缓存的资源不存在,或资源的版本号不完全匹配,它将下载并连同有版本参数提供的版本号储存在缓存中。因为缓存的资源包是通过名称识别,而不是完整的URL,您可以更改从该资产包是在任何时候下载的目录。这对于发布了新游戏版本和确保文件不被浏览器或CDN不正确的缓存。如果缓存文件夹没有空间用于缓存其他文件,LoadFromCacheOrDownload将尝试从缓存删除最近最少使用的资源包。如果利用空间是不可能的(因为影片已满,或在缓存所有文件在使用),LoadFromCacheOrDownload()将会下载文件到内存,就像一个普通的"new WWW()"调用。

最后修改:2011年4月25日 Monday 10:26

本脚本参考基于Unity 3.4.1f5

英文部分版权属©Unity公司所有,中文部分© Unity圣典 版权所有,未经许可,严禁转载 。