refactor : 代码重构

This commit is contained in:
何冠峰
2026-02-05 16:14:50 +08:00
parent 0ec07033f7
commit d839146bd5
152 changed files with 2095 additions and 1877 deletions

View File

@@ -0,0 +1,125 @@
using System;
using System.IO;
namespace YooAsset
{
/// <summary>
/// 从本地加载 RawBundle 操作
/// </summary>
internal class LoadLocalRawBundleOperation : FCLoadBundleOperation
{
private enum ESteps
{
None,
LoadBundle,
CheckResult,
Done,
}
protected readonly LoadLocalRawBundleOptions _options;
private RawBundle _rawBundle;
private ESteps _steps = ESteps.None;
public LoadLocalRawBundleOperation(LoadLocalRawBundleOptions options)
{
_options = options;
}
internal override void InternalStart()
{
_steps = ESteps.LoadBundle;
}
internal override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.LoadBundle)
{
if (_options.Bundle.IsEncrypted == false)
{
if (SupportsFileIO(_options.FilePath) == false)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"FileIO not supported for builtin path : {_options.FilePath}";
return;
}
LoadFromFile();
}
else
{
var decryptor = _options.RawBundleDecryptor;
if (decryptor == null)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"{_options.CacheName} decryptor is null.";
return;
}
LoadResult result;
if (decryptor is IBundleMemoryDecryptor memoryDecryptor)
{
result = LoadFromMemory(memoryDecryptor);
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"{_options.CacheName} not support {decryptor.GetType().Name}";
return;
}
if (result.Succeeded == false)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = result.Error;
return;
}
}
_steps = ESteps.CheckResult;
}
if (_steps == ESteps.CheckResult)
{
if (_rawBundle == null)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"Loaded raw bundle is null.";
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeeded;
BundleResult = new RawBundleResult(_options.FilePath, _options.Bundle, _rawBundle);
}
}
}
internal override void InternalWaitForCompletion()
{
ExecuteBatch();
}
private void LoadFromFile()
{
byte[] data = File.ReadAllBytes(_options.FilePath);
_rawBundle = new RawBundle(data);
}
private LoadResult LoadFromMemory(IBundleMemoryDecryptor decryptor)
{
var args = new BundleDecryptArgs();
args.Bundle = _options.Bundle;
args.FilePath = _options.FilePath;
var binaryData = decryptor.GetDecryptData(args);
if (binaryData == null)
return LoadResult.Failure($"{_options.CacheName} decryptor returned null data.");
_rawBundle = new RawBundle(binaryData);
return LoadResult.Default();
}
}
}