using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AutoConfig { using Cysharp.Threading.Tasks; using System.IO; using System.Net; using UnityEditor; using UnityEngine; using UnityEngine.Networking; public class DownloadConfig { public static string SAVE_PATH = ""; private static int _totalDownloadCount; private static int _DownloadCount; public static async UniTask AutoProcessConfig(List m_Configs, string cookie) { var dir = new DirectoryInfo(ConfigTools.CONFIG_DIR); SAVE_PATH = dir.FullName + "Datas/"; try { _totalDownloadCount = 0; _DownloadCount = 0; for (int i = 0; i < m_Configs.Count; i++) { if (m_Configs[i].Check) { StartDownload(m_Configs[i], cookie); _totalDownloadCount++; } } EditorUtility.DisplayProgressBar("配置工具", $"正在下载 0/{_totalDownloadCount}", 0); while (_DownloadCount < _totalDownloadCount) { _DownloadCount = 0; for (int i = 0; i < m_Configs.Count; i++) { if (m_Configs[i].Check) { if (m_Configs[i].IsError || m_Configs[i].IsDownloadOK) { _DownloadCount++; } } } await UniTask.Delay(100); var remainCount = _totalDownloadCount - _DownloadCount; EditorUtility.DisplayCancelableProgressBar("配置工具", $"正在下载 {remainCount}/{_totalDownloadCount}", _DownloadCount / (float)_totalDownloadCount); } EditorUtility.ClearProgressBar(); bool hasError = false; for (int i = 0; i < m_Configs.Count; i++) { if (m_Configs[i].Check && m_Configs[i].IsError) { hasError = true; Debug.LogError("文件下载失败,name=" + m_Configs[i].Name); } } if (!hasError) { Debug.Log("所有文件下载成功"); } } catch (Exception e) { Debug.LogError("出现异常,message=" + e.Message + "\n,trace=" + e.StackTrace); EditorUtility.ClearProgressBar(); } } public static async void StartDownload(ConfigInfo ci, string cookie) { var downloader = new WPExcelDownloader(ci.Name, ci.DocID, cookie); var result = await downloader.StartDownload(); if (result) { ci.IsDownloadOK = true; } else { ci.IsError = true; } } } }