/// <summary> /// 加载指定AB包 /// </summary> public IEnumerator LoadAssetBundle(string firstDirName, string abName, UnityAction <string> loadAllCompleteHandle) { //参数检查 if (string.IsNullOrEmpty(firstDirName) || string.IsNullOrEmpty(abName)) { Debug.LogError("一级目录名或AB包名为空,加载AB包失败"); } //等待清单文件加载完成 while (!FrameworkEntry.ABManifestLoader.IsLoadFinish) { yield return(null); } //获取清单文件 //_manifest = ABManifestLoader.Instance.Manifest; //字典里是否已有对应的多包加载器 if (!_allFirstDirDict.ContainsKey(firstDirName)) { //为当前一级目录创建多包管理器类的对象 MultiABLoader_3 multiABLoader = new MultiABLoader_3(firstDirName, abName, loadAllCompleteHandle); //把当前场景和对应多包管理器类对象放入字典 _allFirstDirDict.Add(firstDirName, multiABLoader); } //调用下一级,加载AB包 MultiABLoader_3 tempMultiMgr = _allFirstDirDict[firstDirName]; yield return(tempMultiMgr.LoadAssetBundle(abName)); }
/// <summary> /// 加载资源 /// </summary> public T LoadAsset <T>(string path, bool isCache = false) where T : Object { //从路径里切割出一级目录,包名和资源的名字 string firstDirName = path.Split(',')[0]; string abName = path.Split(',')[1]; string assetName = path.Split(',')[2]; if (_allFirstDirDict.ContainsKey(firstDirName)) { MultiABLoader_3 multi = _allFirstDirDict[firstDirName]; return(multi.LoadAsset <T>(abName, assetName, isCache)); } else { Debug.LogError("要加载的资源:" + assetName + "不在指定包:" + abName); return(null); } }