예제 #1
0
        /// <summary>
        /// 释放所有的ab包资源
        /// </summary>
        public void DisposeAllAssets()
        {
            try
            {
                //逐一释放加载过多的AB包中的资源
                foreach (var item in _singleABLoaderCache.Values)
                {
                    item.DisposeAll();
                }
            }
            finally
            {
                _singleABLoaderCache.Clear();
                _singleABLoaderCache = null;

                //释放其他对象占用资源
                _abRelation.Clear();
                _abRelation    = null;
                _currentABName = null;
                LoadAllABPackageCompleteCallback = null;

                //卸载没有用到的资源
                Resources.UnloadUnusedAssets();
                //强制GC回收
                System.GC.Collect();
            }
        }
 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;
     }
 }
예제 #3
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));
        }
예제 #4
0
 public MultABManager(string abName, DelLoadCompleteHandle cb = null)
 {
     _currentABName = abName;
     LoadAllABPackageCompleteCallback = cb;
 }