refactor : 重构网络下载模块

新增通用下载接口,扩展了默认的Unity引擎下载器
This commit is contained in:
何冠峰
2026-01-05 19:44:10 +08:00
parent 1884fab0c2
commit c87efdb509
89 changed files with 2597 additions and 1641 deletions

View File

@@ -21,14 +21,16 @@ public class CopyBuildinManifestOperation : GameAsyncOperation
private readonly string _packageName;
private readonly string _packageVersion;
private readonly IDownloadBackend _backend;
private IDownloadFileRequest _hashFileRequestOp;
private IDownloadFileRequest _manifestFileRequestOp;
private ESteps _steps = ESteps.None;
private UnityWebFileRequestOperation _hashFileRequestOp;
private UnityWebFileRequestOperation _manifestFileRequestOp;
public CopyBuildinManifestOperation(string packageName, string packageVersion)
{
_packageName = packageName;
_packageVersion = packageVersion;
_backend = new UnityWebRequestBackend();
}
protected override void OnStart()
{
@@ -58,14 +60,15 @@ public class CopyBuildinManifestOperation : GameAsyncOperation
string sourcePath = GetBuildinHashFilePath();
string destPath = GetCacheHashFilePath();
string url = DownloadSystemHelper.ConvertToWWWPath(sourcePath);
_hashFileRequestOp = new UnityWebFileRequestOperation(url, destPath, 60);
OperationSystem.StartOperation(_packageName, _hashFileRequestOp);
var args = new DownloadFileRequestArgs(url, destPath, 60, 0);
_hashFileRequestOp = _backend.CreateFileRequest(args);
_hashFileRequestOp.SendRequest();
}
if (_hashFileRequestOp.IsDone == false)
return;
if (_hashFileRequestOp.Status == EOperationStatus.Succeed)
if (_hashFileRequestOp.Status == EDownloadRequestStatus.Succeed)
{
_steps = ESteps.CheckManifestFile;
}
@@ -97,14 +100,15 @@ public class CopyBuildinManifestOperation : GameAsyncOperation
string sourcePath = GetBuildinManifestFilePath();
string destPath = GetCacheManifestFilePath();
string url = DownloadSystemHelper.ConvertToWWWPath(sourcePath);
_manifestFileRequestOp = new UnityWebFileRequestOperation(url, destPath, 60);
OperationSystem.StartOperation(_packageName, _manifestFileRequestOp);
var args = new DownloadFileRequestArgs(url, destPath, 60, 0);
_manifestFileRequestOp = _backend.CreateFileRequest(args);
_manifestFileRequestOp.SendRequest();
}
if (_manifestFileRequestOp.IsDone == false)
return;
if (_manifestFileRequestOp.Status == EOperationStatus.Succeed)
if (_manifestFileRequestOp.Status == EDownloadRequestStatus.Succeed)
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;

View File

@@ -17,7 +17,8 @@ public class GetBuildinPackageVersionOperation : GameAsyncOperation
}
private readonly string _packageName;
private UnityWebTextRequestOperation _versionFileRequestOp;
private readonly IDownloadBackend _backend;
private IDownloadTextRequest _versionFileRequestOp;
private ESteps _steps = ESteps.None;
/// <summary>
@@ -28,6 +29,7 @@ public class GetBuildinPackageVersionOperation : GameAsyncOperation
public GetBuildinPackageVersionOperation(string packageName)
{
_packageName = packageName;
_backend = new UnityWebRequestBackend();
}
protected override void OnStart()
{
@@ -44,14 +46,15 @@ public class GetBuildinPackageVersionOperation : GameAsyncOperation
{
string filePath = GetBuildinPackageVersionFilePath();
string url = DownloadSystemHelper.ConvertToWWWPath(filePath);
_versionFileRequestOp = new UnityWebTextRequestOperation(url, 60);
OperationSystem.StartOperation(_packageName, _versionFileRequestOp);
var args = new DownloadDataRequestArgs(url, 60, 0);
_versionFileRequestOp = _backend.CreateTextRequest(args);
_versionFileRequestOp.SendRequest();
}
if (_versionFileRequestOp.IsDone == false)
return;
if (_versionFileRequestOp.Status == EOperationStatus.Succeed)
if (_versionFileRequestOp.Status == EDownloadRequestStatus.Succeed)
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;