private void OnLoadBundleCompleted(string filename, bool result) { _bundleFiles.RemoveAt(0); _bundleLoading = false; if (result) { BundleMediator.GetInstance().UnloadBundle(filename, true); } }
/// <summary> /// 开始加载常驻的 AssetBundle /// </summary> /// <param name="completeCallBack"></param> public void StartResidentBundle(System.Action completeCallBack) { StartCoroutine(BundleMediator.GetInstance().LoadResidentBundles(delegate() { if (completeCallBack != null) { completeCallBack(); } })); }
/// 游戏更新检查后后启动 public void StartAfterUpdate(Action <bool> allCompletedCallback) { _allCompletedCallback = allCompletedCallback; #if USE_PACK_RES if (ResService.GetInstance().PackConfig == null) { JW.Common.Log.LogE("Preloader.StartAfterUpdate : resource initialize failed"); return; } // _bundleFiles = BundleMediator.GetInstance().GetPreloadBundles(); _bundleLoading = false; string filename = "main_shaders.ab"; _shaderBundle = BundleService.GetInstance().GetBundle(filename); if (_shaderBundle == null) { JW.Common.Log.LogE("Preloader.StartAfterUpdate : failed to get shader bundle"); } ResPackInfo pi = ResService.GetInstance().PackConfig.GetPackInfo(filename); if (pi == null) { _shaderFilename = new JWArrayList <string>(0); } else { _shaderFilename = new JWArrayList <string>(pi.Resources.Count); for (int i = 0; i < pi.Resources.Count; i++) { _shaderFilename.Add(pi.Resources[i].Path); } } #else _bundleFiles = new JWObjList <string>(0); _shaderBundle = null; _shaderFilename = new JWArrayList <string>(0); #endif //真正的开始预加载协成 StartCoroutine(PreloadCoroutine()); }
private bool PreloadCoroutine_Bundle() { if (_bundleFiles == null) { return(false); } if (_bundleFiles.Count == 0) { return(true); } if (!_bundleLoading) { _bundleLoading = true; BundleMediator.GetInstance().LoadBundle(_bundleFiles[0], OnLoadBundleCompleted); } return(false); }
private IEnumerator AsynchronousLoad_LoadAssetBundle(JWObjList <string> stringList, JWArrayList <AssetData> assetDataList) { while (true) { stringList.Clear(); assetDataList.Clear(); for (int i = 0; i < _data.Count;) { AssetData data = _data[i]; if (data.Priority != _loadAssetBundlePriority) { ++i; continue; } _data.RemoveAt(i); if (_assetManager.GetCacheCount(data.Name) >= data.Count) { if (data.Callback != null) { assetDataList.Add(data); } continue; } LoadData loadData; loadData.Data = data; loadData.LoadBundleState = LoadStateLoading; loadData.Request = null; bool insert = false; for (int j = _resourceRequesting.Count - 1; j >= 0; --j) { if (_resourceRequesting[j].Data.Priority <= data.Priority) { _resourceRequesting.Insert(j + 1, loadData); insert = true; break; } } if (!insert) { _resourceRequesting.Insert(0, loadData); } stringList.Add(data.Filename); if (_loadAssetBundlePriority >= LoadPriority.Preprocess) { break; } } yield return(null); if (stringList.Count > 0) { #if USE_PACK_RES BundleMediator.GetInstance().LoadBundle(stringList, OnBundleLoadCompleted); #else OnBundleLoadCompleted(stringList, true); #endif } yield return(null); for (int i = 0; i < assetDataList.Count; i++) { AssetData data = assetDataList[i]; if (data.Callback != null) { data.Callback.OnLoadAssetCompleted(data.Name, AssetLoadResult.Success, null); yield return(null); } } yield return(InstructionEnd); } }