2024-07-04 20:36:26 +08:00
|
|
|
|
|
|
|
|
|
|
namespace YooAsset
|
|
|
|
|
|
{
|
2024-12-11 18:19:09 +08:00
|
|
|
|
internal class DWRFSLoadAssetBundleOperation : FSLoadBundleOperation
|
2024-07-04 20:36:26 +08:00
|
|
|
|
{
|
|
|
|
|
|
private enum ESteps
|
|
|
|
|
|
{
|
|
|
|
|
|
None,
|
2025-02-12 16:27:30 +08:00
|
|
|
|
DownloadAssetBundle,
|
2024-07-04 20:36:26 +08:00
|
|
|
|
Done,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-12-11 18:19:09 +08:00
|
|
|
|
private readonly DefaultWebRemoteFileSystem _fileSystem;
|
2024-07-04 20:36:26 +08:00
|
|
|
|
private readonly PackageBundle _bundle;
|
2025-02-12 16:27:30 +08:00
|
|
|
|
private DownloadAssetBundleOperation _downloadAssetBundleOp;
|
2024-07-04 20:36:26 +08:00
|
|
|
|
private ESteps _steps = ESteps.None;
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-12-11 18:19:09 +08:00
|
|
|
|
internal DWRFSLoadAssetBundleOperation(DefaultWebRemoteFileSystem fileSystem, PackageBundle bundle)
|
2024-07-04 20:36:26 +08:00
|
|
|
|
{
|
|
|
|
|
|
_fileSystem = fileSystem;
|
|
|
|
|
|
_bundle = bundle;
|
|
|
|
|
|
}
|
2025-02-22 16:29:25 +08:00
|
|
|
|
internal override void InternalStart()
|
2024-07-04 20:36:26 +08:00
|
|
|
|
{
|
2025-02-12 16:27:30 +08:00
|
|
|
|
_steps = ESteps.DownloadAssetBundle;
|
2024-07-04 20:36:26 +08:00
|
|
|
|
}
|
2025-02-22 16:29:25 +08:00
|
|
|
|
internal override void InternalUpdate()
|
2024-07-04 20:36:26 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2025-02-12 16:27:30 +08:00
|
|
|
|
if (_steps == ESteps.DownloadAssetBundle)
|
2024-07-04 20:36:26 +08:00
|
|
|
|
{
|
2025-02-12 16:27:30 +08:00
|
|
|
|
if (_downloadAssetBundleOp == null)
|
2024-07-04 20:36:26 +08:00
|
|
|
|
{
|
2025-07-10 10:58:14 +08:00
|
|
|
|
string mainURL = _fileSystem.RemoteServices.GetRemoteMainURL(_bundle.FileName);
|
|
|
|
|
|
string fallbackURL = _fileSystem.RemoteServices.GetRemoteFallbackURL(_bundle.FileName);
|
2025-04-08 11:48:32 +08:00
|
|
|
|
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue, 60);
|
2025-07-10 10:58:14 +08:00
|
|
|
|
options.SetURL(mainURL, fallbackURL);
|
|
|
|
|
|
|
2025-02-12 16:27:30 +08:00
|
|
|
|
if (_bundle.Encrypted)
|
|
|
|
|
|
{
|
2025-07-10 10:58:14 +08:00
|
|
|
|
_downloadAssetBundleOp = new DownloadEncryptAssetBundleOperation(_bundle, options, true, _fileSystem.DecryptionServices);
|
2025-02-25 12:18:16 +08:00
|
|
|
|
_downloadAssetBundleOp.StartOperation();
|
|
|
|
|
|
AddChildOperation(_downloadAssetBundleOp);
|
2025-02-12 16:27:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2025-07-10 10:58:14 +08:00
|
|
|
|
_downloadAssetBundleOp = new DownloadNormalAssetBundleOperation(_bundle, options, _fileSystem.DisableUnityWebCache);
|
2025-02-25 12:18:16 +08:00
|
|
|
|
_downloadAssetBundleOp.StartOperation();
|
|
|
|
|
|
AddChildOperation(_downloadAssetBundleOp);
|
2025-02-12 16:27:30 +08:00
|
|
|
|
}
|
2024-07-04 20:36:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-02-25 12:18:16 +08:00
|
|
|
|
_downloadAssetBundleOp.UpdateOperation();
|
2025-02-12 16:27:30 +08:00
|
|
|
|
DownloadProgress = _downloadAssetBundleOp.DownloadProgress;
|
|
|
|
|
|
DownloadedBytes = _downloadAssetBundleOp.DownloadedBytes;
|
|
|
|
|
|
Progress = _downloadAssetBundleOp.Progress;
|
|
|
|
|
|
if (_downloadAssetBundleOp.IsDone == false)
|
2024-07-04 20:36:26 +08:00
|
|
|
|
return;
|
|
|
|
|
|
|
2025-02-12 16:27:30 +08:00
|
|
|
|
if (_downloadAssetBundleOp.Status == EOperationStatus.Succeed)
|
2024-07-04 20:36:26 +08:00
|
|
|
|
{
|
2025-02-12 16:27:30 +08:00
|
|
|
|
var assetBundle = _downloadAssetBundleOp.Result;
|
2025-02-13 18:56:24 +08:00
|
|
|
|
if (assetBundle == null)
|
2024-12-24 18:23:19 +08:00
|
|
|
|
{
|
|
|
|
|
|
_steps = ESteps.Done;
|
|
|
|
|
|
Status = EOperationStatus.Failed;
|
2025-02-12 16:27:30 +08:00
|
|
|
|
Error = $"{nameof(DownloadAssetBundleOperation)} loaded asset bundle is null !";
|
2024-12-24 18:23:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
_steps = ESteps.Done;
|
|
|
|
|
|
Result = new AssetBundleResult(_fileSystem, _bundle, assetBundle, null);
|
|
|
|
|
|
Status = EOperationStatus.Succeed;
|
|
|
|
|
|
}
|
2024-07-04 20:36:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
_steps = ESteps.Done;
|
|
|
|
|
|
Status = EOperationStatus.Failed;
|
2025-02-12 16:27:30 +08:00
|
|
|
|
Error = _downloadAssetBundleOp.Error;
|
2024-07-04 20:36:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-07-07 16:01:55 +08:00
|
|
|
|
internal override void InternalWaitForAsyncComplete()
|
2024-07-04 20:36:26 +08:00
|
|
|
|
{
|
2024-07-07 16:01:55 +08:00
|
|
|
|
if (_steps != ESteps.Done)
|
2024-07-04 20:36:26 +08:00
|
|
|
|
{
|
|
|
|
|
|
_steps = ESteps.Done;
|
|
|
|
|
|
Status = EOperationStatus.Failed;
|
|
|
|
|
|
Error = "WebGL platform not support sync load method !";
|
|
|
|
|
|
UnityEngine.Debug.LogError(Error);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|