From 4bff0ef895bb3b95fc23cc622f72ad2ce8055d06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=E5=86=A0=E5=B3=B0?= Date: Tue, 20 Jan 2026 17:39:19 +0800 Subject: [PATCH] =?UTF-8?q?refactor=20:=20=E9=87=8D=E6=9E=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DiagnosticOperationInfo.cs | 20 +-- .../DiagnosticSystem/DiagnosticPackageData.cs | 2 +- .../DiagnosticProviderInfo.cs | 2 +- .../DiagnosticSystem/DiagnosticReport.cs | 4 +- .../DiagnosticSystemDefine.cs | 2 +- .../DiagnosticSystem/MockEditorConnection.cs | 29 +++++ .../DiagnosticSystem/MockPlayerConnection.cs | 29 +++++ .../DownloadSystem/DownloadFailureCounter.cs | 8 +- .../Interface/IDownloadBackend.cs | 4 - .../Interface/IDownloadRequest.cs | 3 - .../YooAsset/Runtime/DownloadSystem/README.md | 118 ++++++++---------- .../UnityWebRequest/UnityWebRequestBase.cs | 2 +- .../Provider/ProviderOperation.cs | 4 +- .../ResourceManager/ResourceManager.cs | 2 +- 14 files changed, 132 insertions(+), 97 deletions(-) diff --git a/Assets/YooAsset/Runtime/DiagnosticSystem/DiagnosticOperationInfo.cs b/Assets/YooAsset/Runtime/DiagnosticSystem/DiagnosticOperationInfo.cs index 1aa15caf..9bdd66df 100644 --- a/Assets/YooAsset/Runtime/DiagnosticSystem/DiagnosticOperationInfo.cs +++ b/Assets/YooAsset/Runtime/DiagnosticSystem/DiagnosticOperationInfo.cs @@ -11,27 +11,22 @@ namespace YooAsset internal struct DiagnosticOperationInfo : IComparer, IComparable { /// - /// 任务名称 + /// 异步操作的名称 /// public string OperationName; /// - /// 任务说明 + /// 异步操作的说明 /// public string OperationDesc; /// - /// 优先级 + ///异步操作的优先级 /// public uint Priority; /// - /// 任务进度 - /// - public float Progress; - - /// - /// 任务开始的时间 + /// 开始的时间 /// public string StartTime; @@ -41,7 +36,12 @@ namespace YooAsset public long ElapsedMS; /// - /// 任务状态 + /// 当前进度 + /// + public float Progress; + + /// + /// 当前状态 /// public string Status; diff --git a/Assets/YooAsset/Runtime/DiagnosticSystem/DiagnosticPackageData.cs b/Assets/YooAsset/Runtime/DiagnosticSystem/DiagnosticPackageData.cs index 762fc06d..f617628e 100644 --- a/Assets/YooAsset/Runtime/DiagnosticSystem/DiagnosticPackageData.cs +++ b/Assets/YooAsset/Runtime/DiagnosticSystem/DiagnosticPackageData.cs @@ -34,7 +34,7 @@ namespace YooAsset private bool _isParsed = false; /// - /// 获取调试资源包信息类 + /// 获取资源包的诊断信息 /// public DiagnosticBundleInfo GetBundleInfo(string bundleName) { diff --git a/Assets/YooAsset/Runtime/DiagnosticSystem/DiagnosticProviderInfo.cs b/Assets/YooAsset/Runtime/DiagnosticSystem/DiagnosticProviderInfo.cs index 9c70c990..44999439 100644 --- a/Assets/YooAsset/Runtime/DiagnosticSystem/DiagnosticProviderInfo.cs +++ b/Assets/YooAsset/Runtime/DiagnosticSystem/DiagnosticProviderInfo.cs @@ -36,7 +36,7 @@ namespace YooAsset public int ReferenceCount; /// - /// 加载状态 + /// 当前状态 /// public string Status; diff --git a/Assets/YooAsset/Runtime/DiagnosticSystem/DiagnosticReport.cs b/Assets/YooAsset/Runtime/DiagnosticSystem/DiagnosticReport.cs index 6a7f3466..811a1e00 100644 --- a/Assets/YooAsset/Runtime/DiagnosticSystem/DiagnosticReport.cs +++ b/Assets/YooAsset/Runtime/DiagnosticSystem/DiagnosticReport.cs @@ -18,12 +18,12 @@ namespace YooAsset public string DebuggerVersion = DiagnosticSystemDefine.DebuggerVersion; /// - /// 游戏帧 + /// 报告发生的游戏帧 /// public int FrameCount; /// - /// 调试的包裹数据列表 + /// 包裹数据列表 /// public List PackageDataList = new List(10); diff --git a/Assets/YooAsset/Runtime/DiagnosticSystem/DiagnosticSystemDefine.cs b/Assets/YooAsset/Runtime/DiagnosticSystem/DiagnosticSystemDefine.cs index 7d084bdd..a09b39c9 100644 --- a/Assets/YooAsset/Runtime/DiagnosticSystem/DiagnosticSystemDefine.cs +++ b/Assets/YooAsset/Runtime/DiagnosticSystem/DiagnosticSystemDefine.cs @@ -10,7 +10,7 @@ namespace YooAsset /// /// 调试器版本号 /// - public const string DebuggerVersion = "2026.1.20"; + public const string DebuggerVersion = "1.0"; /// /// Player 向 Editor 发送消息的标识符 diff --git a/Assets/YooAsset/Runtime/DiagnosticSystem/MockEditorConnection.cs b/Assets/YooAsset/Runtime/DiagnosticSystem/MockEditorConnection.cs index c3b9ce1c..e7ae9dc9 100644 --- a/Assets/YooAsset/Runtime/DiagnosticSystem/MockEditorConnection.cs +++ b/Assets/YooAsset/Runtime/DiagnosticSystem/MockEditorConnection.cs @@ -21,6 +21,10 @@ namespace YooAsset #endif private static MockEditorConnection _instance; + + /// + /// 获取单例实例 + /// public static MockEditorConnection Instance { get @@ -33,10 +37,19 @@ namespace YooAsset private readonly Dictionary> _messageHandlers = new Dictionary>(); + /// + /// 初始化连接,清空所有已注册的消息处理器 + /// public void Initialize() { _messageHandlers.Clear(); } + + /// + /// 注册消息处理回调 + /// + /// 消息标识符 + /// 收到消息时的回调函数 public void Register(Guid messageID, UnityAction callback) { if (messageID == Guid.Empty) @@ -45,11 +58,22 @@ namespace YooAsset if (_messageHandlers.ContainsKey(messageID) == false) _messageHandlers.Add(messageID, callback); } + + /// + /// 注销消息处理回调 + /// + /// 消息标识符 public void Unregister(Guid messageID) { if (_messageHandlers.ContainsKey(messageID)) _messageHandlers.Remove(messageID); } + + /// + /// 向 Player 端发送消息 + /// + /// 消息标识符 + /// 消息数据 public void Send(Guid messageID, byte[] data) { if (messageID == Guid.Empty) @@ -59,6 +83,11 @@ namespace YooAsset MockPlayerConnection.Instance.HandleEditorMessage(messageID, data); } + /// + /// 处理来自 Player 端的消息 + /// + /// 消息标识符 + /// 消息数据 internal void HandlePlayerMessage(Guid messageID, byte[] data) { if (_messageHandlers.TryGetValue(messageID, out UnityAction value)) diff --git a/Assets/YooAsset/Runtime/DiagnosticSystem/MockPlayerConnection.cs b/Assets/YooAsset/Runtime/DiagnosticSystem/MockPlayerConnection.cs index 99767695..d2c18bbc 100644 --- a/Assets/YooAsset/Runtime/DiagnosticSystem/MockPlayerConnection.cs +++ b/Assets/YooAsset/Runtime/DiagnosticSystem/MockPlayerConnection.cs @@ -21,6 +21,10 @@ namespace YooAsset #endif private static MockPlayerConnection _instance; + + /// + /// 获取单例实例 + /// public static MockPlayerConnection Instance { get @@ -33,10 +37,19 @@ namespace YooAsset private readonly Dictionary> _messageHandlers = new Dictionary>(); + /// + /// 初始化连接,清空所有已注册的消息处理器 + /// public void Initialize() { _messageHandlers.Clear(); } + + /// + /// 注册消息处理回调 + /// + /// 消息标识符 + /// 收到消息时的回调函数 public void Register(Guid messageID, UnityAction callback) { if (messageID == Guid.Empty) @@ -45,11 +58,22 @@ namespace YooAsset if (_messageHandlers.ContainsKey(messageID) == false) _messageHandlers.Add(messageID, callback); } + + /// + /// 注销消息处理回调 + /// + /// 消息标识符 public void Unregister(Guid messageID) { if (_messageHandlers.ContainsKey(messageID)) _messageHandlers.Remove(messageID); } + + /// + /// 向 Editor 端发送消息 + /// + /// 消息标识符 + /// 消息数据 public void Send(Guid messageID, byte[] data) { if (messageID == Guid.Empty) @@ -59,6 +83,11 @@ namespace YooAsset MockEditorConnection.Instance.HandlePlayerMessage(messageID, data); } + /// + /// 处理来自 Editor 端的消息 + /// + /// 消息标识符 + /// 消息数据 internal void HandleEditorMessage(Guid messageID, byte[] data) { if (_messageHandlers.TryGetValue(messageID, out UnityAction value)) diff --git a/Assets/YooAsset/Runtime/DownloadSystem/DownloadFailureCounter.cs b/Assets/YooAsset/Runtime/DownloadSystem/DownloadFailureCounter.cs index 23b1ca76..968d5c99 100644 --- a/Assets/YooAsset/Runtime/DownloadSystem/DownloadFailureCounter.cs +++ b/Assets/YooAsset/Runtime/DownloadSystem/DownloadFailureCounter.cs @@ -3,12 +3,8 @@ using System.Collections.Generic; namespace YooAsset { /// - /// 网络请求失败计数器(诊断用) + /// 网络请求失败计数器 /// - /// - /// 线程安全:内部使用 Dictionary 且未加锁,约定只在 Unity 主线程调用。 - /// 如需在多线程/回调线程调用,请在外层加锁或改为并发容器实现。 - /// internal class DownloadFailureCounter { #if UNITY_EDITOR @@ -20,7 +16,7 @@ namespace YooAsset #endif /// - /// 失败计数记录表(key = $"{packageName}_{eventName}") + /// 失败计数记录表 /// private static readonly Dictionary _failureRecords = new Dictionary(1000); diff --git a/Assets/YooAsset/Runtime/DownloadSystem/Interface/IDownloadBackend.cs b/Assets/YooAsset/Runtime/DownloadSystem/Interface/IDownloadBackend.cs index 09bd7138..ae056bc6 100644 --- a/Assets/YooAsset/Runtime/DownloadSystem/Interface/IDownloadBackend.cs +++ b/Assets/YooAsset/Runtime/DownloadSystem/Interface/IDownloadBackend.cs @@ -5,10 +5,6 @@ namespace YooAsset /// /// 下载后台接口 /// - /// - /// 不同网络库(UnityWebRequest / BestHTTP / 自研)实现该接口,用于创建具体下载请求。 - /// 每个后台实例是独立的,不共享全局状态。 - /// internal interface IDownloadBackend : IDisposable { /// diff --git a/Assets/YooAsset/Runtime/DownloadSystem/Interface/IDownloadRequest.cs b/Assets/YooAsset/Runtime/DownloadSystem/Interface/IDownloadRequest.cs index 4feac65b..73b1af31 100644 --- a/Assets/YooAsset/Runtime/DownloadSystem/Interface/IDownloadRequest.cs +++ b/Assets/YooAsset/Runtime/DownloadSystem/Interface/IDownloadRequest.cs @@ -5,9 +5,6 @@ namespace YooAsset /// /// 可轮询的下载请求接口 /// - /// - /// 上层通常会在每帧轮询 Status IsDone,并在完成后读取结果。 - /// internal interface IDownloadRequest : IDisposable { /// diff --git a/Assets/YooAsset/Runtime/DownloadSystem/README.md b/Assets/YooAsset/Runtime/DownloadSystem/README.md index 3735624e..0ec5c20f 100644 --- a/Assets/YooAsset/Runtime/DownloadSystem/README.md +++ b/Assets/YooAsset/Runtime/DownloadSystem/README.md @@ -6,7 +6,7 @@ DownloadSystem 是 YooAsset 资源管理系统的**底层网络下载层**,负 ### 可见性说明 -DownloadSystem 属于 YooAsset Runtime 的内部基础模块,目录内大多数类型为 `internal`(仅供 YooAsset Runtime 内部程序集使用)。本文示例以“模块内部调用方式”展示;业务层建议优先通过 `ResourcePackage / FileSystem / ResourceManager` 等上层接口使用下载能力,避免直接依赖本模块的内部类型。 +DownloadSystem 属于 YooAsset Runtime 的内部基础模块,目录内大多数类型为 `internal`(仅供 YooAsset Runtime 内部程序集使用)。本文示例以"模块内部调用方式"展示;业务层建议优先通过 `ResourcePackage / FileSystem / ResourceManager` 等上层接口使用下载能力,避免直接依赖本模块的内部类型。 ### 核心职责 @@ -20,7 +20,7 @@ DownloadSystem 属于 YooAsset Runtime 的内部基础模块,目录内大多 ## 边界与上层协作 -DownloadSystem 的职责是提供“可替换后端 + 统一请求接口 + 轮询式生命周期”的基础能力: +DownloadSystem 的职责是提供"可替换后端 + 统一请求接口 + 轮询式生命周期"的基础能力: - **本模块不负责并发队列/限流调度**:并发通常由上层同时创建多个 request 并自行控制并发数。 - **本模块不负责重试/回退策略**:失败后的重试、切换 CDN、降级等策略通常由上层系统实现。 @@ -83,22 +83,23 @@ DownloadSystem/ │ ├── IDownloadBackend.cs # 后端接口(工厂模式) │ └── IDownloadRequest.cs # 请求接口层次结构 │ -├── DefaultDownloadBackend/ # 默认后端实现 +├── UnityWebBackend/ # 默认后端实现 │ ├── UnityWebRequestBackend.cs # UnityWebRequest 后端 │ └── UnityWebRequestCreator.cs # UnityWebRequest 创建委托 │ -├── DefaultDownloadRequest/ # 默认请求实现 -│ ├── UnityWebRequestDownloaderBase.cs # 基础下载器(抽象类) -│ ├── UnityWebRequestFileDownloader.cs # 文件下载器 -│ ├── UnityWebRequestHeadDownloader.cs # HEAD 请求器 -│ ├── UnityWebRequestBytesDownloader.cs # 字节下载器 -│ ├── UnityWebRequestTextDownloader.cs # 文本下载器 -│ ├── UnityWebRequestAssetBundleDownloader.cs # AssetBundle 下载器 -│ └── VirtualFileDownloader.cs # 模拟下载器(编辑器用) +├── UnityWebRequest/ # 默认请求实现 +│ ├── UnityWebRequestBase.cs # 基础下载器(抽象类) +│ ├── UnityWebRequestFile.cs # 文件下载器 +│ ├── UnityWebRequestHead.cs # HEAD 请求器 +│ ├── UnityWebRequestBytes.cs # 字节下载器 +│ ├── UnityWebRequestText.cs # 文本下载器 +│ ├── UnityWebRequestAssetBundle.cs # AssetBundle 下载器 +│ └── SimulateRequestFile.cs # 模拟下载器(编辑器用) │ -├── DownloadSystemDefine.cs # 枚举、结构体定义 -├── DownloadSystemHelper.cs # 工具函数 -└── WebRequestCounter.cs # 请求失败计数器 +├── EDownloadRequestStatus.cs # 下载请求状态枚举 +├── DownloadRequestArgs.cs # 请求参数结构体定义 +├── DownloadSystemTools.cs # 工具函数 +└── DownloadFailureCounter.cs # 请求失败计数器 ``` --- @@ -197,12 +198,12 @@ internal struct DownloadFileRequestArgs { public readonly string URL; // 请求地址 public readonly int Timeout; // 响应超时(秒),0=不应用超时 - public readonly int WatchdogTime; // 看门狗超时(秒),0=禁用 + public readonly int WatchdogTimeout; // 看门狗超时(秒),0=禁用 public readonly string SavePath; // 文件保存路径 public readonly bool AppendToFile; // 追加写入(断点续传) public readonly bool RemoveFileOnAbort; // 中止时删除文件 - public readonly long ResumeFromBytes; // 断点续传起始位置(>0 时推荐由后端设置 Range 头) + public readonly long ResumeOffset; // 断点续传起始位置(>0 时推荐由后端设置 Range 头) public Dictionary Headers; // 自定义请求头(可选) @@ -210,10 +211,10 @@ internal struct DownloadFileRequestArgs string url, string savePath, int timeout, - int watchdogTime, + int watchdogTimeout, bool appendToFile = false, bool removeFileOnAbort = true, - long resumeFromBytes = 0); + long resumeOffset = 0); /// /// 添加请求头(注意:相同 key 重复添加会抛异常) @@ -229,10 +230,10 @@ internal struct DownloadDataRequestArgs { public readonly string URL; // 请求地址 public readonly int Timeout; // 响应超时(秒),0=不应用超时 - public readonly int WatchdogTime; // 看门狗超时(秒),0=禁用 + public readonly int WatchdogTimeout; // 看门狗超时(秒),0=禁用 public Dictionary Headers; // 自定义请求头(可选) - public DownloadDataRequestArgs(string url, int timeout, int watchdogTime); + public DownloadDataRequestArgs(string url, int timeout, int watchdogTimeout); /// /// 添加请求头(注意:相同 key 重复添加会抛异常) @@ -248,7 +249,7 @@ internal struct DownloadAssetBundleRequestArgs { public readonly string URL; // 请求地址 public readonly int Timeout; // 响应超时(秒),0=不应用超时 - public readonly int WatchdogTime; // 看门狗超时(秒),0=禁用 + public readonly int WatchdogTimeout; // 看门狗超时(秒),0=禁用 public readonly bool DisableUnityWebCache; // 禁用 Unity 缓存(默认 true) public readonly string FileHash; // 文件哈希(缓存启用时需要,且不能为空) @@ -259,7 +260,7 @@ internal struct DownloadAssetBundleRequestArgs public DownloadAssetBundleRequestArgs( string url, int timeout, - int watchdogTime, + int watchdogTimeout, bool disableUnityWebCache = true, string fileHash = null, uint unityCrc = 0); @@ -284,19 +285,6 @@ internal struct DownloadSimulateRequestArgs } ``` -#### ImportBundleInfo(导入资源包信息) - -> 说明:该结构体位于 `DownloadSystemDefine.cs`,主要用于资源包导入(离线文件导入)相关流程,并不参与具体的网络请求参数配置。 - -```csharp -public struct ImportBundleInfo -{ - public string FilePath; // 本地文件路径 - public string BundleName; // 资源包名称 - public string BundleGUID; // 资源包GUID -} -``` - --- ## 核心类说明 @@ -321,7 +309,7 @@ UnityWebRequestCreator creator = (url, method) => IDownloadBackend backend = new UnityWebRequestBackend(creator); ``` -### UnityWebRequestDownloaderBase +### UnityWebRequestBase 抽象基类,封装所有下载器的通用逻辑。 @@ -343,12 +331,12 @@ None ──► SendRequest() ──► Running ──► PollingRequest() ── | 下载器 | 实现接口 | 使用场景 | |--------|----------|----------| -| `UnityWebRequestFileDownloader` | `IDownloadFileRequest` | 大文件下载到本地 | -| `UnityWebRequestHeadDownloader` | `IDownloadHeadRequest` | 检查资源信息 | -| `UnityWebRequestBytesDownloader` | `IDownloadBytesRequest` | 小文件内存加载 | -| `UnityWebRequestTextDownloader` | `IDownloadTextRequest` | 文本文件下载 | -| `UnityWebRequestAssetBundleDownloader` | `IDownloadAssetBundleRequest` | AB 包下载加载 | -| `VirtualFileDownloader` | `IDownloadFileRequest` | 编辑器模拟下载 | +| `UnityWebRequestFile` | `IDownloadFileRequest` | 大文件下载到本地 | +| `UnityWebRequestHead` | `IDownloadHeadRequest` | 检查资源信息 | +| `UnityWebRequestBytes` | `IDownloadBytesRequest` | 小文件内存加载 | +| `UnityWebRequestText` | `IDownloadTextRequest` | 文本文件下载 | +| `UnityWebRequestAssetBundle` | `IDownloadAssetBundleRequest` | AB 包下载加载 | +| `SimulateRequestFile` | `IDownloadFileRequest` | 编辑器模拟下载 | --- @@ -366,7 +354,7 @@ try url: "https://example.com/file.zip", savePath: "/path/to/save/file.zip", timeout: 30, - watchdogTime: 0); + watchdogTimeout: 0); request = backend.CreateFileRequest(args); // 2. 发起并轮询 @@ -401,10 +389,10 @@ var args = new DownloadFileRequestArgs( url: url, savePath: savePath, timeout: 30, - watchdogTime: 0, - appendToFile: true, // 追加写入 - removeFileOnAbort: false, // 中止时保留文件 - resumeFromBytes: existingFileSize); // 断点位置 + watchdogTimeout: 0, + appendToFile: true, // 追加写入 + removeFileOnAbort: false, // 中止时保留文件 + resumeOffset: existingFileSize); // 断点位置 IDownloadFileRequest request = backend.CreateFileRequest(args); request.SendRequest(); @@ -418,7 +406,7 @@ var args = new DownloadFileRequestArgs( url: url, savePath: path, timeout: 30, - watchdogTime: 30); // 30秒无数据自动中止 + watchdogTimeout: 30); // 30秒无数据自动中止 IDownloadFileRequest request = backend.CreateFileRequest(args); request.SendRequest(); @@ -441,7 +429,7 @@ if (request.Status == EDownloadRequestStatus.Aborted) var args = new DownloadDataRequestArgs( url: "https://example.com/file.zip", timeout: 30, - watchdogTime: 0); + watchdogTimeout: 0); IDownloadHeadRequest request = backend.CreateHeadRequest(args); request.SendRequest(); @@ -467,7 +455,7 @@ if (request.Status == EDownloadRequestStatus.Succeed) var args = new DownloadDataRequestArgs( url: "https://example.com/data.json", timeout: 30, - watchdogTime: 0); + watchdogTimeout: 0); IDownloadBytesRequest request = backend.CreateBytesRequest(args); request.SendRequest(); @@ -540,7 +528,7 @@ IDownloadBackend (接口) │ └── 未收到数据 ──► 计时器累加 │ - └── 超过 WatchdogTime ──► AbortRequest() + └── 超过 WatchdogTimeout ──► AbortRequest() ``` --- @@ -556,31 +544,31 @@ IDownloadRequest (基础接口) ├── IDownloadTextRequest (文本下载) └── IDownloadAssetBundleRequest (AssetBundle 下载) -UnityWebRequestDownloaderBase (抽象基类) +UnityWebRequestBase (抽象基类) │ - ├── UnityWebRequestFileDownloader ──► IDownloadFileRequest - ├── UnityWebRequestHeadDownloader ──► IDownloadHeadRequest - ├── UnityWebRequestBytesDownloader ──► IDownloadBytesRequest - ├── UnityWebRequestTextDownloader ──► IDownloadTextRequest - └── UnityWebRequestAssetBundleDownloader ──► IDownloadAssetBundleRequest + ├── UnityWebRequestFile ──► IDownloadFileRequest + ├── UnityWebRequestHead ──► IDownloadHeadRequest + ├── UnityWebRequestBytes ──► IDownloadBytesRequest + ├── UnityWebRequestText ──► IDownloadTextRequest + └── UnityWebRequestAssetBundle ──► IDownloadAssetBundleRequest -VirtualFileDownloader (独立实现) ──► IDownloadFileRequest +SimulateRequestFile (独立实现) ──► IDownloadFileRequest ``` --- ## 工具类 -### DownloadSystemHelper +### DownloadSystemTools 提供跨平台的工具函数: | 方法 | 说明 | |------|------| -| `ConvertToWWWPath()` | 转换本地路径为 WWW 协议 URL | -| `IsRequestLocalFile()` | 判断是否本地文件请求 | +| `ToLocalURL()` | 转换本地路径为文件协议 URL | +| `IsLocalFileURL()` | 判断是否本地文件 URL | -### WebRequestCounter +### DownloadFailureCounter 请求失败计数器,用于诊断统计: @@ -590,10 +578,10 @@ VirtualFileDownloader (独立实现) ──► IDownloadFileRequest ```csharp // 记录失败 -WebRequestCounter.RecordRequestFailed(packageName, eventName); +DownloadFailureCounter.RecordFailure(packageName, eventName); // 查询失败次数 -int count = WebRequestCounter.GetRequestFailedCount(packageName, eventName); +int count = DownloadFailureCounter.GetFailureCount(packageName, eventName); ``` --- @@ -611,4 +599,4 @@ int count = WebRequestCounter.GetRequestFailedCount(packageName, eventName); 5. **驱动更新**:部分第三方网络库实现的 backend 可能需要每帧调用 `IDownloadBackend.Update()` 进行驱动 6. **中止语义**:`Aborted` 可能来自用户主动 `AbortRequest()` 或看门狗超时;中止场景下 `HttpCode/Error` 可能为默认值(例如 0/空) 7. **线程安全**:所有下载请求的创建和轮询应在主线程进行 -8. **模拟下载器**:`VirtualFileDownloader` 仅用于模拟进度,不会落盘,且 `SavePath` 始终为 `null`;成功时 `HttpCode` 固定为 `200` +8. **模拟下载器**:`SimulateRequestFile` 仅用于模拟进度,不会落盘,且 `SavePath` 始终为 `null`;成功时 `HttpCode` 固定为 `200` diff --git a/Assets/YooAsset/Runtime/DownloadSystem/UnityWebRequest/UnityWebRequestBase.cs b/Assets/YooAsset/Runtime/DownloadSystem/UnityWebRequest/UnityWebRequestBase.cs index bab47ebb..18136bd6 100644 --- a/Assets/YooAsset/Runtime/DownloadSystem/UnityWebRequest/UnityWebRequestBase.cs +++ b/Assets/YooAsset/Runtime/DownloadSystem/UnityWebRequest/UnityWebRequestBase.cs @@ -221,7 +221,7 @@ namespace YooAsset } /// - /// 应用通用请求参数 + /// 配置通用请求参数 /// protected void ConfigureRequest(int timeout, int watchdogTimeout, Dictionary headers) { diff --git a/Assets/YooAsset/Runtime/ResourceManager/Provider/ProviderOperation.cs b/Assets/YooAsset/Runtime/ResourceManager/Provider/ProviderOperation.cs index b5374536..f69cf721 100644 --- a/Assets/YooAsset/Runtime/ResourceManager/Provider/ProviderOperation.cs +++ b/Assets/YooAsset/Runtime/ResourceManager/Provider/ProviderOperation.cs @@ -327,12 +327,12 @@ namespace YooAsset /// /// 出生的场景 /// - public string SpawnScene = string.Empty; + public string OriginScene = string.Empty; [Conditional("DEBUG")] public void InitProviderDebugInfo() { - SpawnScene = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name; + OriginScene = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name; } /// diff --git a/Assets/YooAsset/Runtime/ResourceManager/ResourceManager.cs b/Assets/YooAsset/Runtime/ResourceManager/ResourceManager.cs index 17851011..5c947ff7 100644 --- a/Assets/YooAsset/Runtime/ResourceManager/ResourceManager.cs +++ b/Assets/YooAsset/Runtime/ResourceManager/ResourceManager.cs @@ -425,7 +425,7 @@ namespace YooAsset { DiagnosticProviderInfo providerInfo = new DiagnosticProviderInfo(); providerInfo.AssetPath = provider.MainAssetInfo.AssetPath; - providerInfo.OriginScene = provider.SpawnScene; + providerInfo.OriginScene = provider.OriginScene; providerInfo.StartTime = provider.BeginTime; providerInfo.ElapsedMS = provider.ProcessTime; providerInfo.ReferenceCount = provider.RefCount;