private static void unZipEnd(LoadData data) { if(data.fullName == LoadConstant.DB_FILE) { GameStart.setProgressData(97, "加载进程:"); DBXMLManager.instance.init((data.assets[0] as TextAsset).text); //加载MainUI LoadManager.instance.addLoad("mainui.assets", LoadPriority.zero, LoadType.local, null, null, null, null, null, null, unZipEnd); } else if (data.fullName == "mainui.assets") { GameStart.setProgressData(99, "加载进程:"); AssetsManager.instance.setMainUIAssets(data.assets[0] as GameObject); //加载模块第一个场景 LoadManager.instance.addLoad("cell_war_scene.assets", LoadPriority.two, LoadType.local, null, null, null, null, null, null, unZipEnd); } else if (data.fullName == "cell_war_scene.assets") { GameStart.setProgressData(100, "加载进程:"); LevelModel levelModel = MVCCharge.instance.getInstance(typeof(LevelModel) as ICLRType) as LevelModel; levelModel.initLevelData(); Application.LoadLevel("cell_war_scene"); OpenGateView view = MVCCharge.instance.getInstance(typeof(OpenGateView) as ICLRType) as OpenGateView; view.show(); } }
/// <summary> /// 创建一个的LoadData /// </summary> /// <param name="fullName"></param> /// <param name="loadProgressNum"></param> /// <param name="error"></param> /// <param name="assetBundle"></param> /// <param name="unZipProgressNum"></param> /// <param name="objects"></param> /// <returns></returns> public static LoadData getLoadData(string fullName, float loadProgressNum = 0, string error = null, AssetBundle assetBundle = null, float unZipProgressNum = 0, Object[] assets = null) { LoadData data = new LoadData(); data.fullName = fullName; data.loadProgressNum = loadProgressNum; data.error = error; data.assetBundle = assetBundle; data.unZipProgressNum = unZipProgressNum; data.assets = assets; return data; }
private void unZipStart(LoadData data) { }
private void unZipProgress(LoadData data) { }
private void unZipEnd(LoadData data) { if (data.fullName == LoadConstant.MANIFEST_FILE) { //从网络下载更新资源包到本地 List<string> list = ManifestManager.instance.getAllFullName; for (int i = 0, len = list.Count; i < len; i++) { BundleLoadManager.instance.addLoad(list[i], LoadPriority.zero, LoadType.web, loadStart, loadProgress, loadEnd, loadFail); } } else if (data.fullName == GameConstant.MODULES + GameConstant.SUFFIX) { GameStart.setProgressData(95, "加载进程:"); //加载并解压dll文件包结束 CLRSharpManager.instance.init(data.assets[0] as TextAsset); //开启模块 startModules(); } }
private void loadStart(LoadData data) { if (data.fullName == LoadConstant.MANIFEST_FILE) { GameStart.setProgressData(0, "加载进程:"); } }
private void loadProgress(LoadData data) { if (data.fullName == LoadConstant.MANIFEST_FILE) { GameStart.setProgressData((int)data.loadProgressNum * 10, "加载进程:"); } }
private void loadFail(LoadData data) { if (data.fullName == LoadConstant.MANIFEST_FILE) { Debug.Log(LoadConstant.MANIFEST_FILE + "网络加载失败,放弃更新!"); string url = LoadConstant.LOCAL_TITLE + LoadConstant.localFilesPath + "/" + LoadConstant.MANIFEST_FILE; ManifestManager.instance.init(url, loadStart, loadProgress, loadEnd, loadFail, unZipStart, unZipProgress, unZipEnd); } }
private void loadEnd(LoadData data) { if (data.fullName != LoadConstant.MANIFEST_FILE) { if (BundleLoadManager.instance.loadingAndWaitNum == 0) { GameStart.setProgressData(90, "加载进程:"); LoadManager.instance.addLoad(GameConstant.MODULES + GameConstant.SUFFIX, LoadPriority.zero, LoadType.local, null, null, null, null, unZipStart, unZipProgress, unZipEnd); } else { int totleCount = ManifestManager.instance.getAllFullName.Count; int loadingAndWaitNum = BundleLoadManager.instance.loadingAndWaitNum; int progress = 10 + 80 * (totleCount - loadingAndWaitNum) / totleCount; GameStart.setProgressData(progress, "加载进程:"); } } else { GameStart.setProgressData(10, "加载进程:"); } }
private void unZipEnd(LoadData data) { string viewName = clrType.Name; if (data.fullName == viewName.ToLower() + ".assets") { UIManager.instance.setModel(viewName, false); GameObject assetsGO = data.assets[0] as GameObject; Assets assets = assetsGO.GetComponent<Assets>(); if (assets == null) { throw new Exception(clrType.FullName + "面板资源包中不存在Assets组件"); } assetsDic = new Dictionary<string, UnityEngine.Object>(); foreach (UnityEngine.Object obj in assets.assetsList) { assetsDic.Add(obj.name, obj); } GameObject prefab = getAssetsByName(viewName) as GameObject; GameObject go = GameObject.Instantiate<GameObject>(prefab); go.name = viewName; init(go); } }
/// <summary> /// 开始解压 /// </summary> /// <param name="loadData"></param> private void unZipStart(LoadData loadData) { LoadInfo loadInfo = loadDic[loadData.fullName]; loadInfo.request = loadData.assetBundle.LoadAllAssetsAsync(); unZipList.add(loadData.fullName, loadInfo); loadDic.Remove(loadData.fullName); EnterFrame.instance.addEnterFrame(enterFrame); if (loadInfo.unZipStart != null) { loadInfo.unZipStart(loadData); } }
/// <summary> /// 解压完毕 /// </summary> /// <param name="loadData"></param> private void unZipEnd(LoadData loadData) { LoadInfo loadInfo = unZipList.remove(loadData.fullName); Debug.Log(loadInfo.fullName + "解压完成"); if (unZipList.count == 0) { EnterFrame.instance.removeEnterFrame(enterFrame); } if (loadInfo.unZipEnd != null) { loadInfo.unZipEnd(loadData); } }
/// <summary> /// 加载结束 /// </summary> /// <param name="loadData"></param> private void loadEnd(LoadData loadData) { if (loadDic.ContainsKey(loadData.fullName)) { unZipStart(loadData); } }