/// <summary> /// 根据资源列表取bundle列表 /// </summary> /// <param name="resourceList"></param> /// <param name="recordResources"></param> public JWObjList <BundlePackInfo> GetBundlePackInfoListForResources(JWObjList <string> resourceList, bool recordResources) { if (resourceList == null || resourceList.Count == 0) { return(null); } ResPackConfig config = ResService.GetInstance().PackConfig; if (config == null) { if (recordResources) { _unbundledResources.AddRange(resourceList); } return(null); } JWObjList <BundlePackInfo> bundleList = null; for (int i = 0; i < resourceList.Count; i++) { string path = resourceList[i]; BundlePackInfo info = config.GetPackInfoForResource(JW.Res.FileUtil.EraseExtension(path)) as BundlePackInfo; if (info != null) { if (bundleList == null) { bundleList = new JWObjList <BundlePackInfo>(); } if (!bundleList.Contains(info)) { bundleList.Add(info); } // bundle正在加载中的资源 if (recordResources && !_loadingResources.Contains(path)) { _loadingResources.Add(path); } } else { if (recordResources && !_unbundledResources.Contains(path)) { _unbundledResources.Add(path); } } } return(bundleList); }
/// <summary> /// 回收 /// </summary> /// <param name="r"></param> public static void Recycle(ResObj r) { if (r != null) { r.Reset(null); if (!_pool.Contains(r)) { _pool.Add(r); } } }
/// <summary> /// 显示或者关闭菊花 /// </summary> /// <param name="key">键</param> /// <param name="isShow">是否显示</param> public void ShowWaiting(string key, bool isShow, string tip = "") { if (isShow) { if (_waitingKeyList.Contains(key)) { //JW.Common.Log.LogE("ShowWaiting Logic Error Repeat Key:" + key); if (_waiting != null) { _waiting.ShowTip(tip); } return; } _waitingKeyList.Add(key); if (_waiting == null) { _waiting = UIFormHelper.CreateResidentFormClass <UIWaiting>(); _waiting.ShowTip(tip); } else { _waiting.ActiveForm(true); _waiting.ShowTip(tip); } } else { int firstIndex = _waitingKeyList.IndexOf(key); if (firstIndex >= 0 && firstIndex < _waitingKeyList.Count) { _waitingKeyList.RemoveAt(firstIndex); } if (_waitingKeyList.Count == 0) { if (null != _waiting) { _waiting.ActiveForm(false); //UIFormHelper.DisposeFormClass<UIWaiting>(ref _waiting); //_waiting = null; } } } }
/// <summary> /// 异步Bundle加载完成回调 /// </summary> /// <param name="resourcePath"></param> /// <param name="succeed"></param> private void OnBundleLoadCompleted(JWObjList <string> resourcePath, bool succeed) { if (resourcePath == null || resourcePath.Count == 0) { JW.Common.Log.LogE("Loader.OnBundleLoadCompleted : invalid parameter"); return; } for (int i = 0; i < _resourceRequesting.Count; i++) { LoadData loadData = _resourceRequesting[i]; if (loadData.LoadBundleState != LoadStateLoading || !resourcePath.Contains(loadData.Data.Filename)) { continue; } loadData.LoadBundleState = succeed ? LoadStateSuccess : LoadStateFail; _resourceRequesting[i] = loadData; } }
/// <summary> /// 获取已加载的bundle对应的资源 /// </summary> /// <param name="bundlePath"></param> /// <returns></returns> public JWObjList <string> GetLoadedBundleResources(string bundlePath) { if (string.IsNullOrEmpty(bundlePath) || _loadingResources.Count == 0) { return(null); } ResPackConfig config = ResService.GetInstance().PackConfig; if (config == null) { return(null); } BundlePackInfo pi = config.GetPackInfo(bundlePath) as BundlePackInfo; if (pi == null) { return(null); } for (int i = _loadingResources.Count - 1; i >= 0; i--) { string path = _loadingResources[i]; if (pi.Contains(path)) { if (!_relatedResources.Contains(path)) { _relatedResources.Add(path); } _loadingResources.Remove(path); } } return(_relatedResources); }
/// <summary> /// 卸载资源 /// </summary> public void UnloadUnusedResources(JWObjList <string> willUseAssets = null) { JWObjList <string> unloaded = null; var itor = _resources.GetEnumerator(); while (itor.MoveNext()) { if (itor.Current.Value.RefCnt <= 0) { if (willUseAssets != null && willUseAssets.Contains(itor.Current.Key)) { willUseAssets.Remove(itor.Current.Key); continue; } if (unloaded == null) { unloaded = new JWObjList <string>(); } unloaded.Add(itor.Current.Key); // unload itor.Current.Value.Unload(); // recycle ResObj instance 回池 ResObj.Recycle(itor.Current.Value); } } for (int i = 0; unloaded != null && i < unloaded.Count; i++) { _resources.Remove(unloaded[i]); } }