unity5.X AB包打包插件研究
来源:互联网 发布:python 遗传算法 股票 编辑:程序博客网 时间:2024/05/16 14:01
AssetBundleManager中的Update方法,是程序前进的推动者,因为update方法是逐帧执行,时刻的都在观察执行
void Update() { var keysToRemove = new List<string>(); //检查所有正在下载的WWW,是否已经下载完毕 foreach (var keyValue in m_DownloadingWWWs) { WWW download = keyValue.Value; if (download.error != null) { m_DownloadingErrors.Add(keyValue.Key, download.error); keysToRemove.Add(keyValue.Key); continue; } // 如下载完成,进行封装保存到字典中 if(download.isDone) { //Debug.Log("Downloading " + keyValue.Key + " is done at frame " + Time.frameCount); m_LoadedAssetBundles.Add(keyValue.Key, new LoadedAssetBundle(download.assetBundle) ); keysToRemove.Add(keyValue.Key); } } // 从字典中移除已经下载完成的WWW,并且对WWW进行释放 foreach( var key in keysToRemove) { WWW download = m_DownloadingWWWs[key]; m_DownloadingWWWs.Remove(key); download.Dispose(); } // 检查是否可以从AB包中下载资源 for (int i=0;i<m_InProgressOperations.Count;) { if (!m_InProgressOperations[i].Update()) { //处理完就移掉 m_InProgressOperations.RemoveAt(i); } else { //当前暂不处理,接着处理下一个 i++; } } }
上面代码中这行代码m_InProgressOperations[i].Update()
其中Update 里面代码: 就是看 AB包是不是已经下载完成,如果下载完成,就开始异步加载AB包中的资源(asset)
public class AssetBundleLoadAssetOperationFull : AssetBundleLoadAssetOperation{ protected string m_AssetBundleName; protected string m_AssetName; protected string m_DownloadingError; protected System.Type m_Type; protected AssetBundleRequest m_Request = null; public AssetBundleLoadAssetOperationFull (string bundleName, string assetName, System.Type type) { m_AssetBundleName = bundleName; m_AssetName = assetName; m_Type = type; } public override T GetAsset<T>() { if (m_Request != null && m_Request.isDone) return m_Request.asset as T; else return null; } public override bool Update () { if (m_Request != null) return false; LoadedAssetBundle bundle = AssetBundleManager.GetLoadedAssetBundle (m_AssetBundleName, out m_DownloadingError); if (bundle != null) { m_Request = bundle.m_AssetBundle.LoadAssetAsync (m_AssetName, m_Type); return false; } else { Debug.Log("说明还在下AssetBundle"); return true; } } public override bool IsDone () { if (m_Request == null && m_DownloadingError != null) { Debug.LogError(m_DownloadingError); return true; } return m_Request != null && m_Request.isDone; }}
总体思想:
WWW下载,并将WWW对象保存字典
WWW下载完成,取出Assetbundle,封装到LoadedAssetBundle对象中,将封装对象保存字典中
开始异步加载AseetBundle中的asset
记载完成后,开始实例化
FR:海涛高软(QQ技术交流群:386476712)
阅读全文
0 0
- unity5.X AB包打包插件研究
- Unity5.x依赖打包
- Unity5.X AssetBundle打包
- Unity5.x 资源打包和加载
- Unity5.X打包与加载AssetBundle
- Unity5.x shader打包AssetBundle总结
- Unity5.x shader打包AssetBundle总结
- unity5.x assetbundle打包和加载
- unity5.X AssetBundle资源打包(一 )
- Unity5.x AssetBundle依赖项打包详解
- Unity5.x shader打包AssetBundle总结
- UIFramework之Unity5.x AssetBundle打包策略
- Unity5.x新依赖打包及加载
- Kibana 5.x插件打包为离线安装包
- 【Unity开发】Unity5.x版本的AssetBundle打包
- Unity5.x与Android相互通信时打包发布问题
- 关于Unity5.x版本AssetBundle打包Shader的问题
- Unity5.x AssetBundle打包和加载深入分析
- CentOS7 REDIS数据库单机版配置
- NYOJ H. 括号配对问题
- install PyQt4
- SVM算法 理论
- python基础-random、os模块、异常处理模块
- unity5.X AB包打包插件研究
- AngularJS路由代码案例
- javascript中创建文本节点createTextNode
- 迁移机房顺序
- 2017.11.15(let,closure)
- LLVM基本块频率术语
- 创建类ke
- sublime text3 常用快捷键
- JDK-jstat虚拟机统计信息监控工具