/// <summary> /// 加载资源相关bundle /// </summary> /// <param name="resourcesPath">资源路径列表</param> /// <param name="loaded">单个资源加载完成</param> /// <returns></returns> public void LoadBundle(JWObjList <string> resourcesPath, BundleLoadedOneDelegate loaded = null) { StartCoroutine(LoadBundle(resourcesPath, null, null, loaded, false)); }
/// <summary> /// 加载状态相关bundle /// </summary> /// <param name="resourceList">资源路径列表</param> /// <param name="complete">加载完成回调</param> /// <param name="progress">加载进度回调</param> /// <param name="loaded">单个bundle加载完成回调</param> /// <param name="singleSync">true:当只有一个bundle时,使用同步加载;否则使用并发异步加载</param> /// <returns></returns> public IEnumerator LoadBundle(JWObjList <string> resourceList, Action complete = null, BundleBatchLoadingDelegate progress = null, BundleLoadedOneDelegate loaded = null, bool singleSync = true) { bool record = loaded != null; // 剔除已有资源 for (int i = 0; i < resourceList.Count;) { string path = resourceList[i]; if (ResService.GetInstance().Exists(path)) { if (record) { _unbundledResources.Add(path); } resourceList.RemoveAt(i); continue; } i++; } // bundle list JWObjList <BundlePackInfo> bundleList = GetBundlePackInfoListForResources(resourceList, record); // 异步返回,在处理完源数据之后避免resourceList被reset yield return(null); // 未打包资源 if (_unbundledResources.Count > 0) { if (loaded != null) { loaded(_unbundledResources, true); } _unbundledResources.Clear(); } // load if (bundleList != null && bundleList.Count > 0) { if (singleSync && bundleList.Count == 1) { // 只有一个bundle,使用同步加载方式 BundleService.GetInstance().LoadSync(bundleList[0]); if (progress != null) { progress(1f); } if (loaded != null) { AssetBundle bundle = BundleService.GetInstance().GetBundle(bundleList[0].Path); JWObjList <string> relatedResources = GetLoadedBundleResources(bundleList[0].Path); if (relatedResources != null && relatedResources.Count > 0) { loaded(relatedResources, bundle != null); relatedResources.Clear(); } BundleService.GetInstance().Unload(bundleList[0]); } if (complete != null) { complete(); } } else { // 多个bundle,使用并发加载 yield return(StartCoroutine(BundleService.GetInstance().BatchLoadAsync(bundleList, delegate() { if (complete != null) { complete(); } }, progress, delegate(BundleRef bundle) { if (bundle != null) { if (loaded != null) { JWObjList <string> relatedResources = GetLoadedBundleResources(bundle.Path); if (relatedResources != null && relatedResources.Count > 0) { loaded(relatedResources, true); relatedResources.Clear(); } BundleService.GetInstance().Unload(bundle.PackInfo); } } }, delegate(BundlePackInfo pi, string error) { if (loaded != null) { JWObjList <string> relatedResources = GetLoadedBundleResources(pi.Path); if (relatedResources != null && relatedResources.Count > 0) { //bool succ = (pi.IsNoBundle()); //loaded(relatedResources, succ); //relatedResources.Clear(); } } }))); } } else { if (complete != null) { complete(); } } }