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

98 lines
3.7 KiB
C#
Raw Permalink Normal View History

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

namespace YooAsset
{
internal class DWRFSLoadAssetBundleOperation : FSLoadBundleOperation
{
private enum ESteps
{
None,
2025-09-02 19:21:49 +08:00
LoadWebAssetBundle,
2025-01-09 11:31:04 +08:00
Done,
}
private readonly DefaultWebRemoteFileSystem _fileSystem;
private readonly PackageBundle _bundle;
2025-09-02 19:21:49 +08:00
private LoadWebAssetBundleOperation _loadWebAssetBundleOp;
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-09-02 19:21:49 +08:00
_steps = ESteps.LoadWebAssetBundle;
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-09-02 19:21:49 +08:00
if (_steps == ESteps.LoadWebAssetBundle)
2025-01-09 11:31:04 +08:00
{
2025-09-02 19:21:49 +08:00
if (_loadWebAssetBundleOp == null)
2025-01-09 11:31:04 +08:00
{
2025-09-02 19:21:49 +08:00
string mainURL = _fileSystem.RemoteServices.GetRemoteMainURL(_bundle.FileName);
string fallbackURL = _fileSystem.RemoteServices.GetRemoteFallbackURL(_bundle.FileName);
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue);
options.SetURL(mainURL, fallbackURL);
2025-02-28 16:11:01 +08:00
if (_bundle.Encrypted)
{
2025-09-02 19:21:49 +08:00
_loadWebAssetBundleOp = new LoadWebEncryptAssetBundleOperation(_bundle, options, _fileSystem.DecryptionServices);
_loadWebAssetBundleOp.StartOperation();
AddChildOperation(_loadWebAssetBundleOp);
2025-02-28 16:11:01 +08:00
}
else
{
2025-09-02 19:21:49 +08:00
_loadWebAssetBundleOp = new LoadWebNormalAssetBundleOperation(_bundle, options, _fileSystem.DisableUnityWebCache);
_loadWebAssetBundleOp.StartOperation();
AddChildOperation(_loadWebAssetBundleOp);
2025-02-28 16:11:01 +08:00
}
2025-01-09 11:31:04 +08:00
}
2025-09-02 19:21:49 +08:00
_loadWebAssetBundleOp.UpdateOperation();
DownloadProgress = _loadWebAssetBundleOp.DownloadProgress;
DownloadedBytes = _loadWebAssetBundleOp.DownloadedBytes;
Progress = _loadWebAssetBundleOp.Progress;
if (_loadWebAssetBundleOp.IsDone == false)
2025-01-09 11:31:04 +08:00
return;
2025-09-02 19:21:49 +08:00
if (_loadWebAssetBundleOp.Status == EOperationStatus.Succeed)
2025-01-09 11:31:04 +08:00
{
2025-09-02 19:21:49 +08:00
var assetBundle = _loadWebAssetBundleOp.Result;
2025-02-28 16:11:01 +08:00
if (assetBundle == null)
2025-01-09 11:31:04 +08:00
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
2025-09-02 19:21:49 +08:00
Error = $"{nameof(DWRFSLoadAssetBundleOperation)} 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-09-02 19:21:49 +08:00
Error = _loadWebAssetBundleOp.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);
}
}
}
}