refactor : 重构网络下载模块

This commit is contained in:
何冠峰
2026-01-07 15:52:32 +08:00
parent 9b83dcf723
commit f0563cce0b
4 changed files with 9 additions and 7 deletions

View File

@@ -75,6 +75,9 @@ namespace YooAsset
} }
else else
{ {
if (string.IsNullOrEmpty(_args.FileHash))
throw new YooInternalException("File hash is null or empty !");
// 使用 Unity 缓存 // 使用 Unity 缓存
// 说明The file hash defining the version of the asset bundle. // 说明The file hash defining the version of the asset bundle.
Hash128 fileHash = Hash128.Parse(_args.FileHash); Hash128 fileHash = Hash128.Parse(_args.FileHash);

View File

@@ -57,7 +57,7 @@ namespace YooAsset
#elif UNITY_STANDALONE_LINUX #elif UNITY_STANDALONE_LINUX
url = StringUtility.Format("file:///root/{0}", path); url = StringUtility.Format("file:///root/{0}", path);
#else #else
throw new System.NotImplementedException(); throw new System.NotSupportedException($"[{nameof(DownloadSystemHelper.ConvertToWWWPath)}] not implemented platform: {UnityEngine.Application.platform}");
#endif #endif
// For some special cases when users have special characters in their devices, url paths can not be identified correctly. // For some special cases when users have special characters in their devices, url paths can not be identified correctly.
@@ -82,4 +82,4 @@ namespace YooAsset
return false; return false;
} }
} }
} }

View File

@@ -530,9 +530,8 @@ VirtualFileDownloader (独立实现) ──► IDownloadFileRequest
提供跨平台的工具函数: 提供跨平台的工具函数:
| 成员 | 说明 | | 方法 | 说明 |
|------|------| |------|------|
| `UnityWebRequestCreater` | 兼容保留的全局 UnityWebRequest 创建委托(默认文件系统不再读取,推荐改为 FileSystemParameters 注入) |
| `ConvertToWWWPath()` | 转换本地路径为 WWW 协议 URL | | `ConvertToWWWPath()` | 转换本地路径为 WWW 协议 URL |
| `IsRequestLocalFile()` | 判断是否本地文件请求 | | `IsRequestLocalFile()` | 判断是否本地文件请求 |

View File

@@ -41,9 +41,9 @@ namespace YooAsset
public static int GetRequestFailedCount(string packageName, string eventName) public static int GetRequestFailedCount(string packageName, string eventName)
{ {
string key = $"{packageName}_{eventName}"; string key = $"{packageName}_{eventName}";
if (_requestFailedRecorder.ContainsKey(key) == false) if (_requestFailedRecorder.TryGetValue(key, out int count))
_requestFailedRecorder.Add(key, 0); return count;
return _requestFailedRecorder[key]; return 0;
} }
} }
} }