Esempio n. 1
0
        /// <summary>
        /// 加载AB包
        /// </summary>
        /// <param name="abName">AB包包名</param>
        public IEnumerator LoadAB(string abName, LoadAssetFromWhere where = LoadAssetFromWhere.OnLine)
        {
            ABRelation rela;

            //建立AB包关系
            if (!_abRelation.ContainsKey(abName))
            {
                rela = new ABRelation(abName);
                _abRelation.Add(abName, rela);
            }
            rela = _abRelation[abName];

            //获取AB包的所有依赖关系
            string[] dependeceArr = ABManifestLoader.Instance.GetDependce(abName);
            foreach (var cell in dependeceArr)
            {
                //添加依赖项
                rela.AddDependence(cell);
                //加载引用项
                yield return(LoadReference(cell, abName, where));
            }

            //加载AB包
            if (_singleABLoaderCache.ContainsKey(abName))
            {
                yield return(_singleABLoaderCache[abName].LoadAB());
            }
            else
            {
                _currentSingleABLoader = new SingleAssetBundleLoader(abName, CompleteLoadAB, where);
                _singleABLoaderCache.Add(abName, _currentSingleABLoader);
                yield return(_currentSingleABLoader.LoadAB());
            }
            yield return(null);
        }
Esempio n. 2
0
        /// <summary>
        /// 加载Mainfest清单文件
        /// </summary>
        public IEnumerator LoadManifestFile(LoadAssetFromWhere where = LoadAssetFromWhere.OnLine)
        {
            using (UnityWebRequest req = UnityWebRequestAssetBundle.GetAssetBundle(where == LoadAssetFromWhere.OnLine ? _manifestPath : PathTools.LocalAB_OutPath + "/AssetBundle"))
            {
                var operation = req.SendWebRequest();

                //yield return req.SendWebRequest();

                while (!operation.isDone)
                {
                    yield return(null);
                }

                if (req.downloadProgress >= 1)
                {
                    AssetBundle ab = DownloadHandlerAssetBundle.GetContent(req);
                    if (ab != null)
                    {
                        _abReadManifest = ab;
                        _manifest       = ab.LoadAsset(ABDefine.AB_MANIFEST) as AssetBundleManifest;
                        IsLoadFinish    = true;
                    }
                    else
                    {
                        Debug.LogError($"ABManifestLoader/LoadManifestFile Error : can't down the asset ,the manifset path is {_manifestPath}");
                    }
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 加载引用AB包
        /// </summary>
        IEnumerator LoadReference(string abName, string refName, LoadAssetFromWhere where)
        {
            ABRelation tmpABRelation;

            if (_abRelation.ContainsKey(abName))
            {
                tmpABRelation = _abRelation[abName];
                //添加AB包引用关系(被依赖)
                tmpABRelation.AddReference(refName);
            }
            else
            {
                tmpABRelation = new ABRelation(abName);
                tmpABRelation.AddReference(refName);
                _abRelation.Add(abName, tmpABRelation);

                //开始加载依赖包(递归)
                yield return(LoadAB(abName, where));
            }

            yield return(null);
        }
Esempio n. 4
0
        /// <summary>
        /// 加载AB包
        /// </summary>
        /// <param name="abName">AB包名</param>
        /// <param name="loadAllCompletedCallback">全部资源加载完成后的回调事件</param>
        public IEnumerator LoadAB(string abName, DelLoadCompleteHandle loadAllCompletedCallback = null, LoadAssetFromWhere where = LoadAssetFromWhere.OnLine)
        {
            if (string.IsNullOrEmpty(abName))
            {
                Debug.LogError("LAssets/LoadAB Error : abName is null or empty");
            }

            //如果已经存在,说明已经加载过了,无需再次加载
            if (_allAssetsBundlePackages.ContainsKey(abName))
            {
                Debug.LogWarning($"LAssets/LoadAB Warning : the assetbundle file is already loaded the name is {abName}");
                yield break;
            }
            else
            {
                //从依赖包中查找信息,如果已经加载则停止
                foreach (var item in _allAssetsBundlePackages.Values)
                {
                    if (item.ContainsDependentAB(abName))
                    {
                        Debug.LogWarning($"LAssets/LoadAB Warning : the assetbundle file is already loaded the name is {abName}");
                        yield break;
                    }
                }
            }

            if (ABManifestLoader.Instance.ManifestIsNull)
            {
                StartCoroutine(ABManifestLoader.Instance.LoadManifestFile(where));
            }

            //等待Manifest清单文件的加载完成
            while (!ABManifestLoader.Instance.IsLoadFinish)
            {
                yield return(null);
            }
            _manifest = ABManifestLoader.Instance.GetABManifest();//获取清单文件
            if (_manifest == null)
            {
                Debug.LogError($"LAssets/LoadAB Error: the manifest is null");
                yield break;
            }

            MultABManager multABMgr = null;

            //把当前的包添加进集合中
            if (!_allAssetsBundlePackages.ContainsKey(abName))
            {
                multABMgr = new MultABManager(abName, loadAllCompletedCallback);
                _allAssetsBundlePackages.Add(abName, multABMgr);
            }
            else
            {
                multABMgr = _allAssetsBundlePackages[abName];
            }

            if (multABMgr == null)
            {
                Debug.LogError("LAssets/LoadAB Error : multAbMgr is null");
                yield break;
            }
            yield return(multABMgr.LoadAB(abName, where));
        }
 public SingleAssetBundleLoader(string abName, DelLoadCompleteHandle loadComplete = null, LoadAssetFromWhere where = LoadAssetFromWhere.OnLine)
 {
     _loadComplete = loadComplete;
     _abName       = abName;
     if (where == LoadAssetFromWhere.OnLine)
     {
         _abDownLoadPath = PathTools.GetWWWPath() + "/" + _abName;
     }
     else
     {
         _abDownLoadPath = PathTools.LocalAB_OutPath + "/" + _abName;
     }
 }