Files
YooAsset/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/DWRFSLoadBundleOperation.cs

83 lines
3.1 KiB
C#
Raw Normal View History


namespace YooAsset
{
internal class DWRFSLoadAssetBundleOperation : FSLoadBundleOperation
{
private enum ESteps
{
None,
DownloadFile,
Done,
}
private readonly DefaultWebRemoteFileSystem _fileSystem;
private readonly PackageBundle _bundle;
2024-07-05 19:29:34 +08:00
private DownloadHandlerAssetBundleOperation _downloadhanlderAssetBundleOp;
private ESteps _steps = ESteps.None;
internal DWRFSLoadAssetBundleOperation(DefaultWebRemoteFileSystem fileSystem, PackageBundle bundle)
{
_fileSystem = fileSystem;
_bundle = bundle;
}
internal override void InternalOnStart()
{
_steps = ESteps.DownloadFile;
}
internal override void InternalOnUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.DownloadFile)
{
2024-07-05 19:29:34 +08:00
if (_downloadhanlderAssetBundleOp == null)
{
2024-07-07 00:52:17 +08:00
DownloadParam downloadParam = new DownloadParam(int.MaxValue, 60);
downloadParam.MainURL = _fileSystem.RemoteServices.GetRemoteMainURL(_bundle.FileName);
downloadParam.FallbackURL = _fileSystem.RemoteServices.GetRemoteFallbackURL(_bundle.FileName);
_downloadhanlderAssetBundleOp = new DownloadHandlerAssetBundleOperation(_fileSystem.DisableUnityWebCache, _bundle, downloadParam);
2024-07-05 20:20:27 +08:00
OperationSystem.StartOperation(_fileSystem.PackageName, _downloadhanlderAssetBundleOp);
}
2024-07-05 19:29:34 +08:00
DownloadProgress = _downloadhanlderAssetBundleOp.DownloadProgress;
DownloadedBytes = _downloadhanlderAssetBundleOp.DownloadedBytes;
Progress = _downloadhanlderAssetBundleOp.Progress;
if (_downloadhanlderAssetBundleOp.IsDone == false)
return;
2024-07-05 19:29:34 +08:00
if (_downloadhanlderAssetBundleOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.Done;
2024-07-05 19:29:34 +08:00
Result = _downloadhanlderAssetBundleOp.Result;
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
2024-07-05 19:29:34 +08:00
Error = _downloadhanlderAssetBundleOp.Error;
}
}
}
2024-07-07 16:01:55 +08:00
internal override void InternalWaitForAsyncComplete()
{
2024-07-07 16:01:55 +08:00
if (_steps != ESteps.Done)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "WebGL platform not support sync load method !";
UnityEngine.Debug.LogError(Error);
}
}
public override void AbortDownloadOperation()
{
if (_steps == ESteps.DownloadFile)
{
2024-07-05 19:29:34 +08:00
if (_downloadhanlderAssetBundleOp != null)
_downloadhanlderAssetBundleOp.SetAbort();
}
}
}
}