AssetBundle加载资源的过程
2017-04-06 09:54
232 查看
参考:http://blog.csdn.net/jason_520/article/details/54616953
2、获取相关依赖文件列表;
3、加载所有相关依赖文件;
4、加载目标资源;
5、卸载所有相关依赖文件。
AssetBundle加载资源的过程
1、加载总Manifest文件;2、获取相关依赖文件列表;
3、加载所有相关依赖文件;
4、加载目标资源;
5、卸载所有相关依赖文件。
参考代码如下:
IEnumerator LoadAsset() { //首先加载总Manifest文件; WWW wwwAll = new WWW(BundleURL+ "StreamingAssets"); yield return wwwAll; if (!string.IsNullOrEmpty(wwwAll.error)) { Debug.LogError(wwwAll.error); } else { AssetBundle ab = wwwAll.assetBundle; AssetBundleManifest manifest = (AssetBundleManifest)ab.LoadAsset("AssetBundleManifest"); ab.Unload(false); //获取依赖文件列表; string[] depends = manifest.GetAllDependencies("cube.unity3d"); AssetBundle[] dependsAssetBundle = new AssetBundle[depends.Length]; for (int index = 0; index < depends.Length; index++) { //加载所有的依赖文件; WWW dwww = WWW.LoadFromCacheOrDownload(BundleURL + depends[index], 0); yield return dwww; dependsAssetBundle[index] = dwww.assetBundle; } //加载我们需要的文件; WWW www = new WWW(BundleURL + "cube.unity3d"); yield return www; if (!string.IsNullOrEmpty(www.error)) { Debug.LogError(www.error); } else { AssetBundle assetBundle = www.assetBundle; AssetBundleRequest request = assetBundle.LoadAssetAsync("cube", typeof(GameObject)); // Wait for completion yield return request; // Get the reference to the loaded object GameObject obj = request.asset as GameObject; Instantiate(obj); assetBundle.Unload(false); } //卸载依赖文件的包 for (int index = 0; index < depends.Length; index++) { dependsAssetBundle[index].Unload(false); } } }
相关文章推荐
- Unity3d发布Android版通过WWW加载本地AssetBundle资源
- Unity3D 关于资源加载(Resources和AssetBundle)和内存管理
- AssetBundle-----资源加载(读取assetbundle)
- Unity3D引擎WWW资源加载和缓存(AssetBundle、Texture、Audio)
- 详谈 Unity3D AssetBundle 资源加载,结合实际项目开发实例
- Unity3D之AssetBundle【3】AssetBundle资源加载管理器
- Unity3D 关于资源加载(Resources和AssetBundle)和内存管
- Unity3D AssetBundle 资源加载-IOS
- Unity资源处理机制(Assets/WWW/AssetBundle/...)读取和加载资源方式详解
- Unity资源处理机制(Assets/WWW/AssetBundle/...)读取和加载资源方式详解
- AssetBundle——外部加载资源Asset
- C# Unity用AssetBundle加载本地资源 (1)
- Unity3d热更新全书-资源加载(一):从AssetBundle说起
- Unity 关于AssetBundle(资源束)打包和加载(一)
- 【Unity3d】关于AssetBundle.CreateFromFile()方法加载资源失败解决方法
- Unity3D之AssetBundle资源加载封装
- AssetBundle系列——资源的加载、简易的资源管理器
- 关于unity 中使用AssetBundle加载资源,shader偶尔会丢失的问题解决办法
- unity AssetBundle 加载资源 笔记
- Unity中 BundleAsset资源的打包和解析加载