Beispiel #1
0
        /// <summary>
        /// 下载成功处理
        /// </summary>
        private void DownloadSuccessExecute(HKDownloadTaskItem _item, object _data)
        {
            if (null != _item)
            {
                _item.DownloadResult = DownloadResult.Success;

                updateInfo.CurrentProgress = 100; // 更新一次满进度,主要考虑到UI相关的更新
                if (null != downloadUpateInfoAction)
                {
                    downloadUpateInfoAction(updateInfo);
                }

                if (_item.DownloadResType == DownloadResType.StringContent) // string 类型
                {
                    if (null != _item.CompleteAction)
                    {
                        _item.CompleteAction(_item.Url, _data as string, _item.UserData);
                    }
                }
                else if (_item.DownloadResType == DownloadResType.AssetBundle) // AssetBundle类型
                {
                    if (true == _data is byte[])
                    {
                        // 将数据写入到本地
                        HKRequestTools.WriteAssetBundleToLcoal(_item.Url, (byte[])_data);

                        // 处理回调
                        if (null != _item.CompleteAction)
                        {
                            var assetBundle = AssetBundle.LoadFromMemory((byte[])_data);
                            _item.CompleteAction(_item.Url, assetBundle, _item.UserData);
                        }
                    }
                }
                else if (_item.DownloadResType == DownloadResType.ByteArray)  // 二进制类型
                {
                    if (true == _data is byte[])
                    {
                        // 处理回调
                        if (null != _item.CompleteAction)
                        {
                            _item.CompleteAction(_item.Url, _data, _item.UserData);
                        }
                    }
                }

                // 使用完后,就回收到内存池中
                HKDownloadTaskItem.downloadItemCache.Recover(_item);
            }

            // 检测当前剩余下载对象,并继续下载
            CheckQueueComplete();
        }
Beispiel #2
0
        /// <summary>
        /// 下载过程中进度更新
        /// </summary>
        /// <param name="_item">当前正在下载的对象</param>
        /// <param name="_progresss">当前下载对象的下载进度,百分比形式 0 - 100的整数值</param>
        /// <param name="_currentFrameByesCount">当前帧的流量</param>
        private void DownloadProgressExecute(HKDownloadTaskItem _item, int _progresss, int _currentFrameByesCount)
        {
            if (null == _item)
            {
                return;
            }
            UpdateInfo.CurrentProgress  = _progresss;
            updateInfo.currentFrameSize = _currentFrameByesCount;

            if (null != downloadUpateInfoAction)
            {
                downloadUpateInfoAction(UpdateInfo);
            }
        }
Beispiel #3
0
        /// <summary>
        /// 资源下载失败的处理
        /// 要向资源错误原因中添加一条错误记录
        /// </summary>
        /// <param name="_item"></param>
        /// <param name="_errorCode"></param>
        private void DownloadFailExecute(HKDownloadTaskItem _item, int _errorCode)
        {
            if (null == errorInfoCache)
            {
                errorInfoCache = StringCacheFactory.GetFree();
                errorInfoCache.SetSplit("\n");
            }

            if (_item.CurrentSurplusRetryCount > 0)
            {
                RetryExecute(_item);
                errorInfoCache.Add(_item.Url).Add(" 下载失败,启动第").Add(_item.RetryCount - _item.CurrentSurplusRetryCount)
                .Add("次重试");
            }
            else
            {
                errorInfoCache.Add(_item.Url).Add(" 下载失败 = ").Add("_").Add(_errorCode);
                // 使用完后,就回收到内存池中
                HKDownloadTaskItem.downloadItemCache.Recover(_item);
            }

            // 检测当前剩余下载对象,并继续下载
            CheckQueueComplete();
        }
Beispiel #4
0
 /// <summary>
 /// 重试处理
 /// </summary>
 /// <param name="_item"></param>
 private void RetryExecute(HKDownloadTaskItem _item)
 {
     _item.CurrentSurplusRetryCount--;
     downloadSortSet.Add(_item, _item.downloadPriority); // 重新加入到队列中
 }