update download system

This commit is contained in:
何冠峰
2025-07-17 21:00:12 +08:00
parent b3622167da
commit 53db012fc8
2 changed files with 42 additions and 42 deletions

View File

@@ -6,13 +6,13 @@ namespace YooAsset
private enum ESteps private enum ESteps
{ {
None, None,
DownloadAssetBundle, LoadWebAssetBundle,
Done, Done,
} }
private readonly DefaultWebRemoteFileSystem _fileSystem; private readonly DefaultWebRemoteFileSystem _fileSystem;
private readonly PackageBundle _bundle; private readonly PackageBundle _bundle;
private DownloadAssetBundleOperation _downloadAssetBundleOp; private LoadWebAssetBundleOperation _loadWebAssetBundleOp;
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
@@ -23,51 +23,51 @@ namespace YooAsset
} }
internal override void InternalStart() internal override void InternalStart()
{ {
_steps = ESteps.DownloadAssetBundle; _steps = ESteps.LoadWebAssetBundle;
} }
internal override void InternalUpdate() internal override void InternalUpdate()
{ {
if (_steps == ESteps.None || _steps == ESteps.Done) if (_steps == ESteps.None || _steps == ESteps.Done)
return; return;
if (_steps == ESteps.DownloadAssetBundle) if (_steps == ESteps.LoadWebAssetBundle)
{ {
if (_downloadAssetBundleOp == null) if (_loadWebAssetBundleOp == null)
{ {
string mainURL = _fileSystem.RemoteServices.GetRemoteMainURL(_bundle.FileName); string mainURL = _fileSystem.RemoteServices.GetRemoteMainURL(_bundle.FileName);
string fallbackURL = _fileSystem.RemoteServices.GetRemoteFallbackURL(_bundle.FileName); string fallbackURL = _fileSystem.RemoteServices.GetRemoteFallbackURL(_bundle.FileName);
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue, 60); DownloadFileOptions options = new DownloadFileOptions(int.MaxValue);
options.SetURL(mainURL, fallbackURL); options.SetURL(mainURL, fallbackURL);
if (_bundle.Encrypted) if (_bundle.Encrypted)
{ {
_downloadAssetBundleOp = new DownloadEncryptAssetBundleOperation(_bundle, options, true, _fileSystem.DecryptionServices); _loadWebAssetBundleOp = new LoadWebEncryptAssetBundleOperation(_bundle, options, _fileSystem.DecryptionServices);
_downloadAssetBundleOp.StartOperation(); _loadWebAssetBundleOp.StartOperation();
AddChildOperation(_downloadAssetBundleOp); AddChildOperation(_loadWebAssetBundleOp);
} }
else else
{ {
_downloadAssetBundleOp = new DownloadNormalAssetBundleOperation(_bundle, options, _fileSystem.DisableUnityWebCache); _loadWebAssetBundleOp = new LoadWebNormalAssetBundleOperation(_bundle, options, _fileSystem.DisableUnityWebCache);
_downloadAssetBundleOp.StartOperation(); _loadWebAssetBundleOp.StartOperation();
AddChildOperation(_downloadAssetBundleOp); AddChildOperation(_loadWebAssetBundleOp);
} }
} }
_downloadAssetBundleOp.UpdateOperation(); _loadWebAssetBundleOp.UpdateOperation();
DownloadProgress = _downloadAssetBundleOp.DownloadProgress; DownloadProgress = _loadWebAssetBundleOp.DownloadProgress;
DownloadedBytes = _downloadAssetBundleOp.DownloadedBytes; DownloadedBytes = _loadWebAssetBundleOp.DownloadedBytes;
Progress = _downloadAssetBundleOp.Progress; Progress = _loadWebAssetBundleOp.Progress;
if (_downloadAssetBundleOp.IsDone == false) if (_loadWebAssetBundleOp.IsDone == false)
return; return;
if (_downloadAssetBundleOp.Status == EOperationStatus.Succeed) if (_loadWebAssetBundleOp.Status == EOperationStatus.Succeed)
{ {
var assetBundle = _downloadAssetBundleOp.Result; var assetBundle = _loadWebAssetBundleOp.Result;
if (assetBundle == null) if (assetBundle == null)
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = $"{nameof(DownloadAssetBundleOperation)} loaded asset bundle is null !"; Error = $"{nameof(LoadWebAssetBundleOperation)} loaded asset bundle is null !";
} }
else else
{ {
@@ -80,7 +80,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = _downloadAssetBundleOp.Error; Error = _loadWebAssetBundleOp.Error;
} }
} }
} }

View File

@@ -6,13 +6,13 @@ namespace YooAsset
private enum ESteps private enum ESteps
{ {
None, None,
DownloadAssetBundle, LoadWebAssetBundle,
Done, Done,
} }
private readonly DefaultWebServerFileSystem _fileSystem; private readonly DefaultWebServerFileSystem _fileSystem;
private readonly PackageBundle _bundle; private readonly PackageBundle _bundle;
private DownloadAssetBundleOperation _downloadAssetBundleOp; private LoadWebAssetBundleOperation _loadWebAssetBundleOp;
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
@@ -23,51 +23,51 @@ namespace YooAsset
} }
internal override void InternalStart() internal override void InternalStart()
{ {
_steps = ESteps.DownloadAssetBundle; _steps = ESteps.LoadWebAssetBundle;
} }
internal override void InternalUpdate() internal override void InternalUpdate()
{ {
if (_steps == ESteps.None || _steps == ESteps.Done) if (_steps == ESteps.None || _steps == ESteps.Done)
return; return;
if (_steps == ESteps.DownloadAssetBundle) if (_steps == ESteps.LoadWebAssetBundle)
{ {
if (_downloadAssetBundleOp == null) if (_loadWebAssetBundleOp == null)
{ {
string fileLoadPath = _fileSystem.GetWebFileLoadPath(_bundle); string fileLoadPath = _fileSystem.GetWebFileLoadPath(_bundle);
string mainURL = DownloadSystemHelper.ConvertToWWWPath(fileLoadPath); string mainURL = DownloadSystemHelper.ConvertToWWWPath(fileLoadPath);
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue, 60); DownloadFileOptions options = new DownloadFileOptions(int.MaxValue);
options.SetURL(mainURL, mainURL); options.SetURL(mainURL, mainURL);
if (_bundle.Encrypted) if (_bundle.Encrypted)
{ {
_downloadAssetBundleOp = new DownloadEncryptAssetBundleOperation(_bundle, options, true, _fileSystem.DecryptionServices); _loadWebAssetBundleOp = new LoadWebEncryptAssetBundleOperation(_bundle, options, _fileSystem.DecryptionServices);
_downloadAssetBundleOp.StartOperation(); _loadWebAssetBundleOp.StartOperation();
AddChildOperation(_downloadAssetBundleOp); AddChildOperation(_loadWebAssetBundleOp);
} }
else else
{ {
_downloadAssetBundleOp = new DownloadNormalAssetBundleOperation(_bundle, options, _fileSystem.DisableUnityWebCache); _loadWebAssetBundleOp = new LoadWebNormalAssetBundleOperation(_bundle, options, _fileSystem.DisableUnityWebCache);
_downloadAssetBundleOp.StartOperation(); _loadWebAssetBundleOp.StartOperation();
AddChildOperation(_downloadAssetBundleOp); AddChildOperation(_loadWebAssetBundleOp);
} }
} }
_downloadAssetBundleOp.UpdateOperation(); _loadWebAssetBundleOp.UpdateOperation();
DownloadProgress = _downloadAssetBundleOp.DownloadProgress; DownloadProgress = _loadWebAssetBundleOp.DownloadProgress;
DownloadedBytes = _downloadAssetBundleOp.DownloadedBytes; DownloadedBytes = _loadWebAssetBundleOp.DownloadedBytes;
Progress = _downloadAssetBundleOp.Progress; Progress = _loadWebAssetBundleOp.Progress;
if (_downloadAssetBundleOp.IsDone == false) if (_loadWebAssetBundleOp.IsDone == false)
return; return;
if (_downloadAssetBundleOp.Status == EOperationStatus.Succeed) if (_loadWebAssetBundleOp.Status == EOperationStatus.Succeed)
{ {
var assetBundle = _downloadAssetBundleOp.Result; var assetBundle = _loadWebAssetBundleOp.Result;
if (assetBundle == null) if (assetBundle == null)
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = $"{nameof(DownloadAssetBundleOperation)} loaded asset bundle is null !"; Error = $"{nameof(LoadWebAssetBundleOperation)} loaded asset bundle is null !";
} }
else else
{ {
@@ -80,7 +80,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = _downloadAssetBundleOp.Error; Error = _loadWebAssetBundleOp.Error;
} }
} }
} }