存储并加载资源包中的二进制数据

第一步是将二进制数据文件扩展名保存为 “.bytes”。Unity 会将此文件作为文本资源 (TextAsset) 处理。构建资源包 (AssetBundle) 时,可将此文件作为文本资源 (TextAsset) 导入。下载应用程序中的资源包 (AssetBundle) 并加载文本资源 (TextAsset) 对象后,就可使用文本资源的 .bytes 属性检索二进制数据。

string url = "http://www.mywebsite.com/mygame/assetbundles/assetbundle1.unity3d";
IEnumerator Start () {
// Start a download of the given URL
WWW www = WWW.LoadFromCacheOrDownload (url, 1);

// Wait for download to complete
yield return www;

// Load and retrieve the AssetBundle
AssetBundle bundle = www.assetBundle;

// Load the TextAsset object
TextAsset txt = bundle.Load("myBinaryAsText", typeof(TextAsset)) as TextAsset;

// Retrieve the binary data as an array of bytes
byte[] bytes = txt.bytes;
}

返回资源包 (AssetBundles) 简介

Page last updated: 2013-06-26