com.alicizax.unity.tuyoogam.../Runtime/FileSystem/DefaultBuildinFileSystem/Operation/internal/LoadBuildinCatalogFileOperation.cs

91 lines
3.2 KiB
C#
Raw Normal View History

2025-04-01 21:12:28 +08:00
using System;
2025-01-09 11:31:04 +08:00
namespace YooAsset
{
internal sealed class LoadBuildinCatalogFileOperation : AsyncOperationBase
{
private enum ESteps
{
None,
2025-04-01 21:12:28 +08:00
RequestData,
2025-01-09 11:31:04 +08:00
LoadCatalog,
Done,
}
private readonly DefaultBuildinFileSystem _fileSystem;
2025-04-01 21:12:28 +08:00
private UnityWebDataRequestOperation _webDataRequestOp;
2025-01-09 11:31:04 +08:00
private ESteps _steps = ESteps.None;
internal LoadBuildinCatalogFileOperation(DefaultBuildinFileSystem fileSystem)
{
_fileSystem = fileSystem;
}
2025-02-28 16:11:01 +08:00
internal override void InternalStart()
2025-01-09 11:31:04 +08:00
{
2025-04-01 21:12:28 +08:00
_steps = ESteps.RequestData;
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-04-01 21:12:28 +08:00
if (_steps == ESteps.RequestData)
2025-01-09 11:31:04 +08:00
{
2025-04-01 21:12:28 +08:00
if (_webDataRequestOp == null)
2025-01-09 11:31:04 +08:00
{
2025-04-01 21:12:28 +08:00
string filePath = _fileSystem.GetCatalogBinaryFileLoadPath();
string url = DownloadSystemHelper.ConvertToWWWPath(filePath);
2025-09-02 19:21:49 +08:00
_webDataRequestOp = new UnityWebDataRequestOperation(url, 60);
2025-04-01 21:12:28 +08:00
_webDataRequestOp.StartOperation();
AddChildOperation(_webDataRequestOp);
2025-01-09 11:31:04 +08:00
}
2025-04-01 21:12:28 +08:00
_webDataRequestOp.UpdateOperation();
if (_webDataRequestOp.IsDone == false)
return;
if (_webDataRequestOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.LoadCatalog;
}
else
2025-01-09 11:31:04 +08:00
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
2025-04-01 21:12:28 +08:00
Error = _webDataRequestOp.Error;
2025-01-09 11:31:04 +08:00
}
2025-04-01 21:12:28 +08:00
}
2025-01-09 11:31:04 +08:00
2025-04-01 21:12:28 +08:00
if (_steps == ESteps.LoadCatalog)
{
try
2025-01-09 11:31:04 +08:00
{
2025-04-01 21:12:28 +08:00
var catalog = CatalogTools.DeserializeFromBinary(_webDataRequestOp.Result);
if (catalog.PackageName != _fileSystem.PackageName)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"Catalog file package name {catalog.PackageName} cannot match the file system package name {_fileSystem.PackageName}";
return;
}
2025-01-09 11:31:04 +08:00
2025-04-01 21:12:28 +08:00
foreach (var wrapper in catalog.Wrappers)
{
var fileWrapper = new DefaultBuildinFileSystem.FileWrapper(wrapper.FileName);
_fileSystem.RecordCatalogFile(wrapper.BundleGUID, fileWrapper);
}
YooLogger.Log($"Package '{_fileSystem.PackageName}' buildin catalog files count : {catalog.Wrappers.Count}");
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
catch (Exception e)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"Failed to load catalog file : {e.Message}";
}
2025-01-09 11:31:04 +08:00
}
}
}
}