com.alicizax.unity.tuyoogam.../Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/DWRFSLoadBundleOperation.cs

97 lines
3.7 KiB
C#
Raw Normal View History

2025-01-09 11:31:04 +08:00

namespace YooAsset
{
internal class DWRFSLoadAssetBundleOperation : FSLoadBundleOperation
{
private enum ESteps
{
None,
2025-02-28 16:11:01 +08:00
DownloadAssetBundle,
2025-01-09 11:31:04 +08:00
Done,
}
private readonly DefaultWebRemoteFileSystem _fileSystem;
private readonly PackageBundle _bundle;
2025-02-28 16:11:01 +08:00
private DownloadAssetBundleOperation _downloadAssetBundleOp;
2025-01-09 11:31:04 +08:00
private ESteps _steps = ESteps.None;
internal DWRFSLoadAssetBundleOperation(DefaultWebRemoteFileSystem fileSystem, PackageBundle bundle)
{
_fileSystem = fileSystem;
_bundle = bundle;
}
2025-02-28 16:11:01 +08:00
internal override void InternalStart()
2025-01-09 11:31:04 +08:00
{
2025-02-28 16:11:01 +08:00
_steps = ESteps.DownloadAssetBundle;
2025-01-09 11:31:04 +08:00
}
2025-02-28 16:11:01 +08:00
internal override void InternalUpdate()
2025-01-09 11:31:04 +08:00
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
2025-02-28 16:11:01 +08:00
if (_steps == ESteps.DownloadAssetBundle)
2025-01-09 11:31:04 +08:00
{
2025-02-28 16:11:01 +08:00
if (_downloadAssetBundleOp == null)
2025-01-09 11:31:04 +08:00
{
2025-05-13 10:40:30 +08:00
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue, 60);
options.MainURL = _fileSystem.RemoteServices.GetRemoteMainURL(_bundle.FileName);
options.FallbackURL = _fileSystem.RemoteServices.GetRemoteFallbackURL(_bundle.FileName);
2025-02-28 16:11:01 +08:00
if (_bundle.Encrypted)
{
2025-05-13 10:40:30 +08:00
_downloadAssetBundleOp = new DownloadWebEncryptAssetBundleOperation(true, _fileSystem.DecryptionServices, _bundle, options);
2025-02-28 16:11:01 +08:00
_downloadAssetBundleOp.StartOperation();
AddChildOperation(_downloadAssetBundleOp);
}
else
{
2025-05-13 10:40:30 +08:00
_downloadAssetBundleOp = new DownloadWebNormalAssetBundleOperation(_fileSystem.DisableUnityWebCache, _bundle, options);
2025-02-28 16:11:01 +08:00
_downloadAssetBundleOp.StartOperation();
AddChildOperation(_downloadAssetBundleOp);
}
2025-01-09 11:31:04 +08:00
}
2025-02-28 16:11:01 +08:00
_downloadAssetBundleOp.UpdateOperation();
DownloadProgress = _downloadAssetBundleOp.DownloadProgress;
DownloadedBytes = _downloadAssetBundleOp.DownloadedBytes;
Progress = _downloadAssetBundleOp.Progress;
if (_downloadAssetBundleOp.IsDone == false)
2025-01-09 11:31:04 +08:00
return;
2025-02-28 16:11:01 +08:00
if (_downloadAssetBundleOp.Status == EOperationStatus.Succeed)
2025-01-09 11:31:04 +08:00
{
2025-02-28 16:11:01 +08:00
var assetBundle = _downloadAssetBundleOp.Result;
if (assetBundle == null)
2025-01-09 11:31:04 +08:00
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
2025-02-28 16:11:01 +08:00
Error = $"{nameof(DownloadAssetBundleOperation)} loaded asset bundle is null !";
2025-01-09 11:31:04 +08:00
}
else
{
_steps = ESteps.Done;
Result = new AssetBundleResult(_fileSystem, _bundle, assetBundle, null);
Status = EOperationStatus.Succeed;
}
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
2025-02-28 16:11:01 +08:00
Error = _downloadAssetBundleOp.Error;
2025-01-09 11:31:04 +08:00
}
}
}
internal override void InternalWaitForAsyncComplete()
{
if (_steps != ESteps.Done)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "WebGL platform not support sync load method !";
UnityEngine.Debug.LogError(Error);
}
}
}
}