// 当前任务数, 总任务数, 当前任务进度 public static IEnumerator DownloadBundlesCo( string localPathRoot, Manifest.BundleInfo[] bundles, IList <string> urls, Action <int, int, ITask> onProgress, Action onComplete) { for (int i = 0, size = bundles.Length; i < size; i++) { var bundleInfo = bundles[i]; var task = DownloadTask.Create(bundleInfo, urls, localPathRoot, -1, 10, null); var progress = -1.0f; task.SetDebugMode(true).Run(); while (!task.isDone) { if (progress != task.progress) { progress = task.progress; onProgress(i, size, task); } yield return(null); } } onComplete(); }
// 当前任务数, 总任务数, 当前任务进度 public static IEnumerator DownloadBundlesCo( string localPathRoot, Manifest.BundleInfo[] bundles, IList <string> urls, StreamingAssetsLoader streamingAssets, Action <int, int, ITask> onProgress, Action onComplete) { for (int i = 0, size = bundles.Length; i < size; i++) { var bundleInfo = bundles[i]; if (streamingAssets != null && streamingAssets.Contains(bundleInfo.name, bundleInfo.checksum, bundleInfo.size)) { // Debug.LogWarning($"skipping embedded bundle {bundleInfo.name}"); continue; } var task = DownloadTask.Create(bundleInfo, urls, localPathRoot, -1, 10, null).SetDebugMode(true); var progress = -1.0f; task.Run(); while (!task.isDone) { if (progress != task.progress) { progress = task.progress; onProgress(i, size, task); } yield return(null); } } onComplete(); }
/// <summary> /// 增加下载任务。 /// </summary> /// <param name="downloadPath">下载后存放路径。</param> /// <param name="downloadUri">原始下载地址。</param> /// <param name="priority">下载任务的优先级。</param> /// <param name="userData">用户自定义数据。</param> /// <returns>新增下载任务的序列编号。</returns> public int AddDownload(string downloadPath, string downloadUri, int priority, object userData) { if (string.IsNullOrEmpty(downloadPath)) { throw new GXException("Download path is invalid."); } if (string.IsNullOrEmpty(downloadUri)) { throw new GXException("Download uri is invalid."); } if (TotalAgentCount <= 0) { throw new GXException("You must add download agent first."); } DownloadTask downloadTask = DownloadTask.Create(downloadPath, downloadUri, priority, m_FlushSize, m_Timeout, userData); m_TaskPool.AddTask(downloadTask); return(downloadTask.SerialId); }