BuildPipeline.BuildStreamedSceneAssetBundle 编译流场景资源包

static function BuildStreamedSceneAssetBundle (levels : string[], locationPath : String, target : BuildTarget) : String

Description描述

Builds one or more scenes and all it's dependencies into a compressed asset bundle.

编译一个或多个场景和所有它依赖的压缩资源包。

The scene AssetBundle can be built for any target platform and always creates a single compressed unity3d file.

该场景资源包可以内置任意目标平台,并总是创建单一压缩的unity3d文件。

The scene can be downloaded and loaded using the WWW class. You can use WWW.LoadFromCacheOrDownload to cache the downloaded scene after it has been downloaded.

该场景可以被下载并使用WWW类加载。可以使用WWW.LoadFromCacheOrDownload已经被下载后,来缓存下载的场景。

// Build a streamed unity3d file. This contain one scene that can be downloaded
// on demand and loaded once it's asset bundle has been loaded.
//构建一个流unity3d文件,包含一个场景,可以按需下载,一旦资源包加载时加载。

@MenuItem ("Build/BuildWebplayerStreamed")
static function MyBuild(){
	var levels : String[] = ["Assets/Level1.unity"];
	BuildPipeline.BuildStreamedSceneAssetBundle( levels, "Streamed-Level1.unity3d", BuildTarget.WebPlayer);
}

When downloading the built compressed file, you need to call WWW.assetBundle in order to make the scene available to the Application.LoadLevel() and Application.LoadLevelAdditive() functions.

当下载内置的压缩文件,必须调用WWW.assetBundle以使场景Application.LoadLevel()和Application.LoadLevelAdditive()函数可用。

function Start () {
	// Download compressed scene. If version 5 of the file named "Streamed-Level1.unity3d" was previously downloaded and cached.
	// Then Unity will completely skip the download and load the decompressed scene directly from disk.
	//下载压缩的场景。如果名为Streamed-Level1.unity3d的文件版本为5,预先下载并缓存。
	//然后Unity将完全跳过下载并直接从磁盘加载解压的场景。
	var download = WWW.LoadFromCacheOrDownload ("http://myWebSite.com/Streamed-Level1.unity3d", 5);
	yield download;

	// Handle error
	if (download.error != null)
	{
		Debug.LogError(download.error);
		return;
	}

	// In order to make the scene available from LoadLevel, we have to load the asset bundle.
	// The AssetBundle class also lets you force unload all assets and file storage once it is no longer needed.
	//为了使场景LoadLevel可用,必须加载资源包
	//AssetBundle类,还可以强制卸载所有的资源和文件存储,一旦不再需要。
	var bundle = download.assetBundle;

	// Load the level we have just downloaded
	//加载刚才下载的关卡
	Application.LoadLevel ("Level1");
}
最后修改:2011年10月3日 Monday 14:42

本脚本参考基于Unity 3.4.1f5

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