//void Start() {
        //	_LoadObj = new SingleBundleLoader(_ABName,LoadComplete);
        //	//加载AB包
        //	StartCoroutine(_LoadObj.LoadAssetBundle());
        //}


        ///// <summary>
        ///// 回调函数(一定条件下自动执行)
        ///// </summary>
        ///// <param name="abName"></param>
        //private void LoadComplete(string abName){
        //	//加载AB包中资源
        //	UnityEngine.Object tempObj =  _LoadObj.LoadAsset(_AssetName1,false);
        //	//克隆对象
        //	Instantiate(tempObj);
        //}

        #endregion


                #region[有依赖包加载]

        private void Start()
        {
            SingleBundleLoader _LoadDependObj1 = new SingleBundleLoader(_ABDependName1, LoadDependComplete1);

            //加载AB依赖包
            StartCoroutine(_LoadDependObj1.LoadAssetBundle());
        }
Пример #2
0
//		/// <summary>完成指定包的调用</summary>
//		/// <param name="bundleName">指定的包名</param>
//		private void LoadComplete(string bundleName) {
////			if(string.IsNullOrEmpty(bundleName))
////				throw new ArgumentException(FrameConst.PREFIX + nameof(bundleName));
//
//			if(bundleName.Equals(curBundleName))
//				loadAllCompleteHandler?.Invoke();
//		}


		/// <summary>加载依赖的AB包</summary>
		/// <param name="bundleName">指定的包名</param>
		private IEnumerator LoadDependence(string bundleName) {
			//AssetBundle包关系的建立
			if(!bundleRelationDict.ContainsKey(bundleName))
				bundleRelationDict.Add(bundleName, new BundleRelation(bundleName));
			BundleRelation tempBundleRelation = bundleRelationDict[bundleName];

			//得到指定AssetBundle包所有的依赖关系(查询相应的清单文件)
			string[] dependenceArray = ManifestMgr.Instance.RetrieveDependencies(bundleName);
			foreach(var dependenceItem in dependenceArray) {
				//添加依赖项
				tempBundleRelation.AddABDependence(dependenceItem);
				//添加引用项(通过协程方法,递归调用)
				yield return LoadReference(dependenceItem, bundleName);
			}
			//真正加载AssetBundle包,并等待加载完成
			if(singleBundleLoaderDict.ContainsKey(bundleName)) {
				yield return singleBundleLoaderDict[bundleName].LoadAssetBundle();
			}
			else {
				//当前的SingleBundleLoader变成了下一个
				curSingleBundleLoader = new SingleBundleLoader(bundleName,loadCompleteHandler);
				singleBundleLoaderDict.Add(bundleName, curSingleBundleLoader);
				yield return curSingleBundleLoader.LoadAssetBundle();
			}
		}
 /// <summary>依赖回调函数1</summary>
 private void LoadDependComplete1(string abName)
 {
     _LoadObj = new SingleBundleLoader(_ABName, LoadComplete);
     //加载AB依赖包
     StartCoroutine(_LoadObj.LoadAssetBundle());
 }