/// <summary> /// 加载资源包 /// </summary> /// <param name="dpName"></param> /// <param name="mainName">主资源名称</param> /// <returns></returns> IEnumerator WWWLoadAssets(string name, bool dp) { if (mAssetsABDic.ContainsKey(name)) { AssetsBundleData abd = mAssetsABDic[name]; abd.depIndex += 1; } else { if (mNameMD5Dic.ContainsKey(name)) { VersionAssetData vad = mNameMD5Dic[name]; /* * string url = GetAssetsWWWPath(vad.path, vad.md5); * WWW abWWW = new WWW(url); * yield return abWWW; */ string url = GetAssetsFilePath(vad.path, vad.md5); byte[] bytes = ComTool.ReadFile(url); if (bytes != null) { AssetBundle ab = null; if (!dp) { //作为主资源加载的 ab = AssetBundle.LoadFromMemory(bytes); string[] dpAbs = mMainManifest.GetAllDependencies(name); //取这个资源的所有依赖资源 if (dpAbs.Length == 0) //没有依赖 { #region AssetsBundleData abd = new AssetsBundleData(); abd.name = name; abd.depIndex = 1; abd.ab = ab; mAssetsABDic.Add(name, abd); #endregion } else { //存在依赖资源 #region for (int i = 0; i < dpAbs.Length; i++) { if (mAssetsABDic.ContainsKey(dpAbs[i])) { //依赖计数器中已经存在了 计数器+1 AssetsBundleData abd = mAssetsABDic[dpAbs[i]]; abd.depIndex += 1; } else { yield return(StartCoroutine(WWWLoadAssets(dpAbs[i], true))); } } #endregion //依赖都加载完毕了 再看主资源 #region if (!mAssetsABDic.ContainsKey(name)) { AssetsBundleData abd = new AssetsBundleData(); abd.name = name; abd.depIndex = 1; abd.ab = ab; mAssetsABDic.Add(name, abd); } else { AssetsBundleData abd = mAssetsABDic[name]; abd.depIndex += 1; } #endregion } } else {//作为被依赖资源下载 AssetsBundleData abd = null; if (mAssetsABDic.ContainsKey(name)) { abd = mAssetsABDic[name]; abd.depIndex += 1; } else { ab = AssetBundle.LoadFromMemory(bytes); abd = new AssetsBundleData(); abd.name = name; abd.depIndex = 1; abd.ab = ab; mAssetsABDic.Add(name, abd); } } if (!dp) { //资源包加载完成计数+1 mLoadedNum += 1; //Debug.LogError("module loaded num:" + mLoadedNum); } } else { Debug.LogError("cannot find:" + url); } } } }