Esempio n. 1
0
        /// <summary>
        /// 释放ab包的接口,所以AB包释放都调用这个方法
        /// </summary>
        /// <param name="abName"></param>
        public void DisposeAssetBundle(string abName)
        {
            AssetBundleItem bundleItem = null;

            _AssetBundleDic.TryGetValue(abName, out bundleItem);
            // 加载完的AB包才能卸载
            if (bundleItem != null && bundleItem.BundleLoadStatus == BundleLoadStatus.LOADED)
            {
                //不在常驻内存列表的AB包才能卸载
                if (abPermanentAsset == null || !abPermanentAsset.BundleNameHS.Contains(abName))
                {
                    ABRelation abRelation = bundleItem.abRelation;
                    // 没有被别的包依赖才可以进行卸载
                    if (abRelation.GetAllReference().Count == 0)
                    {
                        bundleItem.Dispose();                                                   // 卸载目标ab包
                        _AssetBundleDic.Remove(abName);
                        List <string> dependenceList = abRelation.GetAllDependence();           // 获取目标包所有依赖的包列表
                        foreach (string DependAbName in dependenceList)
                        {
                            bool isClear = _AssetBundleDic[DependAbName].abRelation.RemoveReference(abName); // 去掉目标包所依赖的包的被依赖关系

                            // 如果目标包所依赖的包已经没有被其他包依赖了,则把目标包所依赖的包也卸载掉(递归)
                            if (isClear)
                            {
                                DisposeAssetBundle(DependAbName);
                            }
                        }
                    }
                }
            }
        }// function_end