Exemplo n.º 1
0
        /// <summary>
        /// 获取资源
        /// </summary>
        public T GetAsset <T>(string abPath, string assetName) where T : UnityEngine.Object
        {
            T asset = null;

            AssetBundleTask task = GetTask(abPath, false);

            task?.Load((ab) =>
            {
                asset = ab?.LoadAsset <T>(assetName);
            });

            return(asset);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 加载AB包
        /// </summary>
        public AssetBundle LoadAssetBundle(string abPath)
        {
            AssetBundle assetbundle = null;

            AssetBundleTask task = GetTask(abPath, false);

            task?.Load((ab) =>
            {
                assetbundle = ab;
            });

            return(assetbundle);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 卸载
        /// </summary>
        public void Unload(string abPath, bool unloadAllLoadedObjects)
        {
            string abKey = GetAbKey(abPath);

            AssetBundleTask task = this[abKey];

            if (task != null)
            {
                task.Unload(unloadAllLoadedObjects);

                _taskDic?.Remove(abKey);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 获取任务
        /// </summary>
        private AssetBundleTask GetTask(string abPath, bool async)
        {
            string abKey = GetAbKey(abPath);

            AssetBundleTask task = this[abKey];

            if (task == null)
            {
                task = new AssetBundleTask(abPath, async);

                this[abKey] = task;
            }

            return(task);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 异步获取资源
        /// </summary>
        public void GetAssetAsync <T>(string abPath, string assetName, Action <T> callback, Action <float> progressCallback = null) where T : UnityEngine.Object
        {
            AssetBundleTask task = GetTask(abPath, true);

            task?.Load((ab) =>
            {
                Task.CreateTask(GetAssetAsync(ab, assetName, (asset) =>
                {
                    callback?.Invoke(asset as T);
                }, (progress) =>
                {
                    progressCallback?.Invoke(progress * 0.5f + 0.5f);
                }));
            }, (progress) =>
            {
                progressCallback?.Invoke(progress * 0.5f);
            });
        }
Exemplo n.º 6
0
        private AssetBundleTask this[string key]
        {
            get
            {
                AssetBundleTask task = null;

                if (!string.IsNullOrEmpty(key))
                {
                    _taskDic?.TryGetValue(key, out task);
                }

                return(task);
            }
            set
            {
                if (!string.IsNullOrEmpty(key))
                {
                    _taskDic[key] = value;
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// 异步加载AB包
        /// </summary>
        public void LoadAssetBundleAsync(string abPath, Action <AssetBundle> callback, Action <float> progressCallback)
        {
            AssetBundleTask task = GetTask(abPath, true);

            task?.Load(callback, progressCallback);
        }