示例#1
0
        private void StartLoad(LoadItem item)
        {
            // 设置加载项开始加载
            item.isLoading = true;

            // 创建加载器
            //string urlAbsolute;
            //// 判断是否从Persistent目录加载
            //if (App.fileManager.FileExistsPersistent(item.url))
            //    urlAbsolute = new StringBuilder(App.pathManager.persistentDataPathWWW).Append(item.url).ToString();
            //else
            //    urlAbsolute = new StringBuilder(App.pathManager.externalPath).Append(item.url).ToString();

            ILoader loader = LoaderFactory.CreateLoader(item.url, null, item.type);

            item.loader = loader;

            // 加入当前加载器字典
            _currentLoaders[item.url] = loader;

            // 设置加载回调
            loader.completeCallback = LoadComplete;
            loader.progressCallback = LoadProgress;
            loader.errorCallback    = LoadError;

            // 开始加载
            loader.Start();

            // 派发事件
            DispatchEvent(ResourceManagerEventArgs.ITEM_START, item);
        }
示例#2
0
        /// <summary>
        /// 立即加载资源
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public LoadItem LoadImmediately(LoadItem item)
        {
            if (item == null)
            {
                return(null);
            }

            // 判断内存中是否存在该资源
            IAsset asset = App.assetManager.GetAsset(item.id);

            if (asset != null)
            {
                item.asset = asset;
                if (item.completeCallback != null)
                {
                    item.completeCallback.Invoke(item);
                }
                return(item);
            }

            // 判断是否为ab包
            if (item.loadImmediately && item.isAssetBundle && item.type != LoadType.AUDIO_ASSET_BUNDLE)
            {
                asset = LoadAssetFromAssetBundle(item.url, item.id, item.type, item.cache);
                if (asset != null)
                {
                    item.asset = asset;
                    // 执行加载完成回调
                    if (item.completeCallback != null)
                    {
                        item.completeCallback.Invoke(item);
                    }
                    return(item);
                }
            }

            // 内存中不存在则开始加载资源
            LoadItem loadItem;

            if (_immediateDict.TryGetValue(item.url, out loadItem) == false)
            {
                // 加载队列中未存在该加载项
                _immediateDict[item.url] = item;
                // 设置加载项开始加载
                item.isLoading = true;
                // 创建加载器
                //string urlAbsolute;
                //// 判断是否从Persistent目录加载
                //if (App.fileManager.FileExistsPersistent(item.url))
                //    urlAbsolute = new StringBuilder(App.pathManager.persistentDataPathWWW).Append(item.url).ToString();
                //else
                //    urlAbsolute = new StringBuilder(App.pathManager.externalPath).Append(item.url).ToString();

                ILoader loader = LoaderFactory.CreateLoader(item.url, null, item.type);
                item.loader = loader;

                // 设置加载回调
                loader.completeCallback = LoadCompleteImmediately;
                loader.progressCallback = LoadProgressImmediately;
                loader.errorCallback    = LoadErrorImmediately;

                // 开始加载
                loader.Start();
            }
            else
            {
                // 加载队列中已存在该加载项
                loadItem.completeCallback += item.completeCallback;
                loadItem.errorCallback    += item.errorCallback;
                loadItem.progressCallback += item.progressCallback;
            }

            return(loadItem);
        }