Beispiel #1
0
        /////////////////////////////////////
        private AssetDownloadTask GetOrCreateTask()
        {
            var task = new AssetDownloadTask(this);

            task.id = m_taskId++;
            return(task);
        }
Beispiel #2
0
        private void DownloadFiles(int packageIndex, string[] urlPaths, string[] savePaths)
        {
            if (urlPaths == null)
            {
                return;
            }

            if (urlPaths.Length <= 0)
            {
                return;
            }

            if (_downloadRetryTimes >= maxRetryTimes)   //重试次数大于n次,判断为更新失败
            {
                return;
            }

            var downloader = AssetDownloadManager.GetInstance().GetForegroundCentral();

            _downloadTask             = downloader.NewTask(urlPaths, savePaths);
            _downloadTask.onCompleted = (task) =>
            {
                onDownloadCompleted?.Invoke(task);
                var package = _updateList.GetPackage(packageIndex);
                OnDownloadCompleted(package);
            };
        }
Beispiel #3
0
        private void DestroyTask(AssetDownloadTask task)
        {
            if (task == null)
            {
                return;
            }

            task.StopByManager(this);
        }
Beispiel #4
0
        ///

        //激活任务,正式开始下载
        private void ActiveTask(AssetDownloadTask task)
        {
            if (task == null)
            {
                return;
            }

            task.StartByManager(this);
        }
Beispiel #5
0
 public void ResumeTask(AssetDownloadTask task)
 {
     if ((m_pauseMap != null && m_pauseMap.Contains(task)))
     {
         EnabledTask(task, true);
         GetPauseMap().Remove(task);
         GetQueueMap().Remove(task);
         GetProcressMap().Add(task);
     }
 }
Beispiel #6
0
 public void PauseTask(AssetDownloadTask task)
 {
     if ((m_progressMap != null && m_progressMap.Contains(task)) || (m_queueMap != null && m_queueMap.Contains(task)))
     {
         EnabledTask(task, false);
         GetProcressMap().Remove(task);
         GetQueueMap().Remove(task);
         GetPauseMap().Add(task);
     }
 }
Beispiel #7
0
        //失活任务,停止下载
        private void EnabledTask(AssetDownloadTask task, bool isEnabled)
        {
            if (task == null)
            {
                return;
            }

            if (isEnabled)
            {
                task.ResumeByManager(this);
            }
            else
            {
                task.PauseByManager(this);
            }
        }
Beispiel #8
0
 public void StartTask(AssetDownloadTask task)
 {
     if (m_queueMap != null && m_queueMap.Contains(task))
     {
         //如果本来就在排队,提高优先级
         m_queueMap.Remove(task);
         task.priority++;
         m_queueMap.Add(task);
     }
     else if (m_pauseMap != null && m_pauseMap.Contains(task))
     {
         //从暂停队列移到排队队列
         GetPauseMap().Remove(task);
         GetQueueMap().Add(task);
         task.status = AssetDownloadStatus.DOWNLOAD_QUEUE;
     }
 }
Beispiel #9
0
        /////////////////////////////////////
        private void UpdateWait()
        {
            while (WaitingCount > 0 && (maxCount > 0 && DownloadingCount < maxCount))
            {
                AssetDownloadTask task = null;
                foreach (var item in m_queueMap)
                {
                    task = item;
                    break;
                }
                m_queueMap.Remove(task);

                ActiveTask(task);

                GetProcressMap().Add(task);
                task.status = AssetDownloadStatus.DOWNLOAD_DOWNLOADING;
            }
        }
Beispiel #10
0
        public void StopTask(AssetDownloadTask task)
        {
            if (m_queueMap != null)
            {
                m_queueMap.Remove(task);
            }
            if (m_pauseMap != null)
            {
                m_pauseMap.Remove(task);
            }
            if (m_progressMap != null)
            {
                m_progressMap.Remove(task);
            }

            if (m_tasksMap != null)
            {
                var taskKey = GetTaskKey(task.urlPaths);
                if (GetTaskMap().ContainsKey(taskKey))
                {
                    GetReleaseList().AddLast(task);
                }
            }
        }
Beispiel #11
0
 protected void OnDownloadFailed(AssetDownloadTask task)
 {
     //移除无效的临时文件
 }
Beispiel #12
0
 //Android目录下,下载中的存放路径必须在Application.dataPath,下载完成在拷贝到Application.persistentDataPath
 protected void OnDownloadSuccess(AssetDownloadTask task)
 {
     //将临时文件移动到持久目录
 }
Beispiel #13
0
 public bool HadTask(AssetDownloadTask task)
 {
     return(HadTask(task.urlPaths));
 }