Пример #1
0
        /// <summary>
        /// 卸载
        /// </summary>
        /// <param name="assetName">根据加载路径卸载</param>
        /// <param name="isForceUnload">强制卸载</param>
        public void UnloadAsset(string assetName, bool isForceUnload = false)
        {
            //非hash模式,需要debugRuntime
            // if (!this.AssetConfigLoder.IsHashName)
            // {
            //     assetName = ZString.Format(DEBUG_RUNTIME, assetName);
            // }

            var(assetBundleItem, dependAssetList) = AssetConfigLoder.GetDependAssets(assetName);
            //添加主资源一起卸载
            dependAssetList.Add(assetBundleItem);
            //卸载
            for (int i = 0; i < dependAssetList.Count; i++)
            {
                var assetPath         = dependAssetList[i].AssetBundlePath;
                AssetBundleWapper abw = null;

                if (AssetbundleMap.TryGetValue(assetPath, out abw))
                {
                    if (isForceUnload)
                    {
                        abw.UnLoad();
                    }
                    else
                    {
                        abw.Unuse();
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// 卸载/AssetBundle
        /// </summary>
        /// <param name="assetLoadPath">api传入的加载路径,Runtime下的相对路径</param>
        /// <param name="isForceUnload">强制卸载</param>
        /// <param name="type">为空则卸载所有同名资源,为空则卸载指定类型资源</param>
        public void UnloadAsset(string assetLoadPath, bool isForceUnload = false, Type type = null)
        {
            //1.AB卸载
            var(assetBundleItem, dependAssetList) = AssetConfigLoder.GetDependAssets(assetLoadPath, type);
            //添加主资源一起卸载
            dependAssetList.Add(assetBundleItem);
            //卸载
            for (int i = 0; i < dependAssetList.Count; i++)
            {
                var assetbundleFileName = dependAssetList[i].AssetBundlePath;

                if (AssetbundleCacheMap.TryGetValue(assetbundleFileName, out var abw))
                {
                    //
                    abw.Unuse();
                    //判断是否需要卸载
                    if (isForceUnload || abw.UseCounter == 0)
                    {
                        //卸载回调
                        Action onUnloadEnd = () =>
                        {
                            //移除assetbundle
                            AssetbundleCacheMap.Remove(assetbundleFileName);
                            //移除缓存
                            this.UnloadObjectCache(type, assetLoadPath);
                        };

                        //创建unload任务
                        var unloadTask = new UnLoadTask(abw, onUnloadEnd);
                        //添加卸载任务
                        this.AddUnloadTask(assetbundleFileName, unloadTask);
                    }
                }
            }
        }
Пример #3
0
        /// <summary>
        /// 加载资源
        /// </summary>
        /// <param name="type"></param>
        /// <param name="assetLoadPath">api传入的加载路径,Runtime下的相对路径</param>
        /// <returns></returns>
        public Object Load(Type type, string assetLoadPath)
        {
            var retObj = GetObjectFormCache(type, assetLoadPath);

            if (!retObj)
            {
                //1.依赖路径
                var(mainAssetItem, dependAssetList) = AssetConfigLoder.GetDependAssets(assetLoadPath, type);
                //2.加载
                if (mainAssetItem != null)
                {
                    if (dependAssetList == null)
                    {
                        dependAssetList = new List <AssetBundleItem>();
                    }

                    dependAssetList.Add(mainAssetItem);
                    //加载所有ab
                    foreach (var dependABItem in dependAssetList)
                    {
                        LoadAssetBundle(dependABItem.AssetBundlePath, dependABItem.Mix);
                    }

                    //加载实例
                    retObj = LoadObjectFormAssetBundle(type, assetLoadPath, mainAssetItem);
                }
            }


            return(retObj);
        }
Пример #4
0
        public Object Load(Type type, string path)
        {
            //1.依赖路径
            var(assetBundleItem, dependAssetList) = AssetConfigLoder.GetDependAssets(path, type);
            if (assetBundleItem != null)
            {
                //加载依赖
                foreach (var dependABItem in dependAssetList)
                {
                    LoadAssetBundle(dependABItem.AssetBundlePath, dependABItem.Mix);
                }

                //加载主资源
                LoadAssetBundle(assetBundleItem.AssetBundlePath, assetBundleItem.Mix);
                //
                return(LoadFormAssetBundle(type, path, assetBundleItem));
            }

            return(null);
        }