Пример #1
0
        /// <summary>
        /// 加载AssetBundle
        /// </summary>
        /// <param name="abPath"></param>
        /// <returns></returns>
        public AssetBundle LoadAssetBundle(string abPath, int offset = 0)
        {
            AssetBundleWapper abw = null;

            if (AssetbundleMap.TryGetValue(abPath, out abw))
            {
                abw.Use();
                return(abw.AssetBundle);
            }
            else
            {
                //寻找加载路径
                var loadPath = FindMultiAddressAsset(abPath);
#if UNITY_EDITOR
                if (!File.Exists(loadPath))
                {
                    return(null);
                }
#endif
                //TODO 这里需要判断Lock列表,异步转同步

                var ab = AssetBundle.LoadFromFile(loadPath, 0u, (ulong)offset);
                //添加
                this.AddAssetBundle(abPath, ab);
                return(ab);
            }

            return(null);
        }
Пример #2
0
        /// <summary>
        /// 加载AssetBundle文件
        /// </summary>
        /// <param name="assetbundleFileName">ab文件名</param>
        /// <returns></returns>
        public void LoadAssetBundle(string assetbundleFileName, int offset = 0)
        {
            AssetBundleWapper abw = GetAssetBundleFromCache(assetbundleFileName);

            if (abw == null)
            {
                //取消加载任务
                this.CancelUnloadTask(assetbundleFileName);
                //寻找加载路径
                var abLocalPath = FindMultiAddressAsset(assetbundleFileName);
#if UNITY_EDITOR
                if (!File.Exists(abLocalPath))
                {
                    return;
                }
#endif

                //这里需要判断task列表,异步转同步
                var loadTask = GetExsitLoadTask(abLocalPath);
                if (loadTask != null)
                {
                    if (loadTask.IsAsyncTask)
                    {
                        loadTask.ToSynchronizationTask();
                        BDebug.Log("【AssetbundleV2】异步转同步:" + loadTask.LocalPath);
                    }
                    else
                    {
                        BDebug.LogError("【AssetbundleV2】同步任务调度错误~");
                    }
                }
                else
                {
                    //同步也要创建任务
                    loadTask = new LoadTask(abLocalPath, 0u, (ulong)offset);
                    AddGlobalLoadTask(loadTask);
                    {
                        //同步加载
                        loadTask.Load();
                    }
                    RemoveGlobalLoadTask(loadTask);
                }


#if UNITY_EDITOR
                if (loadTask.AssetBundle == null)
                {
                    Debug.LogError($"【AssetBundleV2】 ab加载失败{loadTask.LocalPath}");
                }
#endif
                //添加
                abw = this.AddAssetBundleToCache(assetbundleFileName, loadTask.AssetBundle);
            }

            //使用
            abw.Use();
        }
Пример #3
0
        /// <summary>
        /// 加载AssetBundle
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public AssetBundle LoadAssetBundle(string path)
        {
            AssetBundleWapper abw = null;

            if (AssetbundleMap.TryGetValue(path, out abw))
            {
                abw.Use();
                return(abw.AssetBundle);
            }
            else
            {
                var p  = FindMultiAddressAsset(path);
                var ab = AssetBundle.LoadFromFile(p);
                //添加
                this.AddAssetBundle(path, ab);
                return(ab);
            }

            return(null);
        }
Пример #4
0
        /// <summary>
        /// 加载AssetBundle
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        private AssetBundle LoadAssetBundle(string path)
        {
            if (AssetbundleMap.ContainsKey(path))
            {
                AssetBundleWapper abw = null;
                if (AssetbundleMap.TryGetValue(path, out abw))
                {
                    abw.Use();
                    return(abw.AssetBundle);
                }
            }
            else
            {
                var p  = FindAsset(path);
                var ab = AssetBundle.LoadFromFile(p);
                //添加
                AddAssetBundle(path, ab);
                return(ab);
            }

            return(null);
        }