/// <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]); } }