diff --git a/.gitignore b/.gitignore
index 65247de6..d4f02de3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -70,6 +70,7 @@ sysinfo.txt
# Builds
*.apk
*.unitypackage
+*.zip
# Crashlytics generated file
crashlytics-build.properties
diff --git a/Assets/YooAsset/Editor/AssetArtReporter/ScanReport.cs b/Assets/YooAsset/Editor/AssetArtReporter/ScanReport.cs
index db7d615f..140ab044 100644
--- a/Assets/YooAsset/Editor/AssetArtReporter/ScanReport.cs
+++ b/Assets/YooAsset/Editor/AssetArtReporter/ScanReport.cs
@@ -10,7 +10,7 @@ namespace YooAsset.Editor
///
/// 文件签名(自动填写)
///
- public string FileSign;
+ public string FileSignature;
///
/// 文件版本(自动填写)
diff --git a/Assets/YooAsset/Editor/AssetArtReporter/ScanReportConfig.cs b/Assets/YooAsset/Editor/AssetArtReporter/ScanReportConfig.cs
index 2103631e..eaebe3ec 100644
--- a/Assets/YooAsset/Editor/AssetArtReporter/ScanReportConfig.cs
+++ b/Assets/YooAsset/Editor/AssetArtReporter/ScanReportConfig.cs
@@ -20,7 +20,7 @@ namespace YooAsset.Editor
ScanReport report = JsonUtility.FromJson(jsonData);
// 检测配置文件的签名
- if (report.FileSign != ScannerDefine.ReportFileSign)
+ if (report.FileSignature != ScannerDefine.ReportFileSign)
throw new Exception($"导入的报告文件无法识别 : {filePath}");
// 检测报告文件的版本
diff --git a/Assets/YooAsset/Editor/AssetArtScanner/AssetArtScanner.cs b/Assets/YooAsset/Editor/AssetArtScanner/AssetArtScanner.cs
index 05618ab2..28581780 100644
--- a/Assets/YooAsset/Editor/AssetArtScanner/AssetArtScanner.cs
+++ b/Assets/YooAsset/Editor/AssetArtScanner/AssetArtScanner.cs
@@ -122,7 +122,7 @@ namespace YooAsset.Editor
throw new Exception($"Failed to load schema : {ScannerSchema}");
var report = schema.RunScanner(this);
- report.FileSign = ScannerDefine.ReportFileSign;
+ report.FileSignature = ScannerDefine.ReportFileSign;
report.FileVersion = ScannerDefine.ReportFileVersion;
report.SchemaType = schema.GetType().FullName;
report.ScannerGUID = ScannerGUID;
diff --git a/Assets/YooAsset/Editor/AssetArtScanner/AssetArtScannerConfig.cs b/Assets/YooAsset/Editor/AssetArtScanner/AssetArtScannerConfig.cs
index 2c1a9e76..550f0b09 100644
--- a/Assets/YooAsset/Editor/AssetArtScanner/AssetArtScannerConfig.cs
+++ b/Assets/YooAsset/Editor/AssetArtScanner/AssetArtScannerConfig.cs
@@ -15,7 +15,7 @@ namespace YooAsset.Editor
///
/// 文件签名
///
- public string FileSign;
+ public string FileSignature;
///
/// 文件版本
@@ -40,7 +40,7 @@ namespace YooAsset.Editor
ConfigWrapper setting = JsonUtility.FromJson(json);
// 检测配置文件的签名
- if (setting.FileSign != ScannerDefine.SettingFileSign)
+ if (setting.FileSignature != ScannerDefine.SettingFileSign)
throw new Exception($"导入的配置文件无法识别 : {filePath}");
// 检测配置文件的版本
@@ -74,7 +74,7 @@ namespace YooAsset.Editor
File.Delete(savePath);
ConfigWrapper wrapper = new ConfigWrapper();
- wrapper.FileSign = ScannerDefine.SettingFileSign;
+ wrapper.FileSignature = ScannerDefine.SettingFileSign;
wrapper.FileVersion = ScannerDefine.SettingFileVersion;
wrapper.Scanners = AssetArtScannerSettingData.Setting.Scanners;
diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskCreateCatalog.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskCreateCatalog.cs
index 910a625a..67fff461 100644
--- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskCreateCatalog.cs
+++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskCreateCatalog.cs
@@ -15,7 +15,7 @@ namespace YooAsset.Editor
string buildinRootDirectory = buildParametersContext.GetBuildinRootDirectory();
string buildPackageName = buildParametersContext.Parameters.PackageName;
var manifestServices = buildParametersContext.Parameters.ManifestDecryptor;
- BuiltinFileCatalogTools.CreateFile(manifestServices, buildPackageName, buildinRootDirectory);
+ BuiltinCatalogTools.CreateFile(manifestServices, buildPackageName, buildinRootDirectory);
// 刷新目录
AssetDatabase.Refresh();
diff --git a/Assets/YooAsset/Runtime/AsyncOperation/AsyncOperationBase.cs b/Assets/YooAsset/Runtime/AsyncOperation/AsyncOperationBase.cs
index 1e9dad77..0eaad370 100644
--- a/Assets/YooAsset/Runtime/AsyncOperation/AsyncOperationBase.cs
+++ b/Assets/YooAsset/Runtime/AsyncOperation/AsyncOperationBase.cs
@@ -157,12 +157,10 @@ namespace YooAsset
}
///
- /// 内部同步等待方法(子类可选实现)
- /// 默认抛出异常,如果异步操作需要支持,子类应重写以支持同步等待
+ /// 内部释放方法(子类可选实现)
///
- internal virtual void InternalWaitForCompletion()
+ internal virtual void InternalDispose()
{
- throw new YooInternalException($"InternalWaitForCompletion() is not implemented: {this.GetType().Name}");
}
///
@@ -173,6 +171,15 @@ namespace YooAsset
return string.Empty;
}
+ ///
+ /// 内部同步等待方法(子类可选实现)
+ /// 默认抛出异常,如果异步操作需要支持,子类应重写以支持同步等待
+ ///
+ internal virtual void InternalWaitForCompletion()
+ {
+ throw new YooInternalException($"InternalWaitForCompletion() is not implemented: {this.GetType().Name}");
+ }
+
///
/// 添加子任务
///
@@ -321,27 +328,40 @@ namespace YooAsset
// 结束记录
DebugEndRecording();
- if (_onCompleted != null)
+ try
{
- var invocationList = _onCompleted.GetInvocationList();
- foreach (var handler in invocationList)
- {
- try
- {
- ((Action)handler).Invoke(this);
- }
- catch (Exception ex)
- {
- YooLogger.Error($"Exception in completion callback: {ex}");
- }
- }
+ InternalDispose();
+ }
+ catch (Exception ex)
+ {
+ YooLogger.Error($"Exception in {this.GetType().Name}.InternalDispose: {ex}");
+ }
+
+ if (_onCompleted != null)
+ {
+ var invocations = _onCompleted.GetInvocationList();
+ InvokeSafely(invocations);
+ _onCompleted = null;
}
- _onCompleted = null;
if (_taskCompletionSource != null)
_taskCompletionSource.TrySetResult(null);
}
}
+ private void InvokeSafely(Delegate[] invocations)
+ {
+ foreach (var handler in invocations)
+ {
+ try
+ {
+ ((Action)handler).Invoke(this);
+ }
+ catch (Exception ex)
+ {
+ YooLogger.Error($"Exception in inoke callback: {ex}");
+ }
+ }
+ }
///
/// 执行一次更新逻辑
diff --git a/Assets/YooAsset/Runtime/DownloadSystem/Interfaces/IDownloadRequest.cs b/Assets/YooAsset/Runtime/DownloadSystem/Interfaces/IDownloadRequest.cs
index 527f4fdc..0e13b847 100644
--- a/Assets/YooAsset/Runtime/DownloadSystem/Interfaces/IDownloadRequest.cs
+++ b/Assets/YooAsset/Runtime/DownloadSystem/Interfaces/IDownloadRequest.cs
@@ -3,7 +3,7 @@ using System;
namespace YooAsset
{
///
- /// 可轮询的下载请求接口
+ /// 下载请求接口
///
internal interface IDownloadRequest : IDisposable
{
diff --git a/Assets/YooAsset/Runtime/FileCache/Interfaces/ICacheEntry.cs b/Assets/YooAsset/Runtime/FileCache/Interfaces/ICacheEntry.cs
index a5f80587..d16606af 100644
--- a/Assets/YooAsset/Runtime/FileCache/Interfaces/ICacheEntry.cs
+++ b/Assets/YooAsset/Runtime/FileCache/Interfaces/ICacheEntry.cs
@@ -2,7 +2,7 @@
namespace YooAsset
{
///
- /// 缓存记录接口
+ /// 缓存条目接口
///
internal interface ICacheEntry
{
diff --git a/Assets/YooAsset/Runtime/FileCache/Interfaces/IFileCache.cs b/Assets/YooAsset/Runtime/FileCache/Interfaces/IFileCache.cs
index db0a9ba1..607ef613 100644
--- a/Assets/YooAsset/Runtime/FileCache/Interfaces/IFileCache.cs
+++ b/Assets/YooAsset/Runtime/FileCache/Interfaces/IFileCache.cs
@@ -42,7 +42,7 @@ namespace YooAsset
///
/// 写入缓存文件
///
- FCWriteCacheOperation WriteCacheAsync(WriteCacheOptions options);
+ FCWriteCacheOperation WriteCacheAsync(FCWriteCacheOptions options);
///
/// 清理缓存文件
@@ -52,12 +52,12 @@ namespace YooAsset
///
/// 验证缓存文件
///
- FCVerifyCacheOperation VerifyCacheAsync(VerifyCacheOptions options);
+ FCVerifyCacheOperation VerifyCacheAsync(FCVerifyCacheOptions options);
///
/// 加载资源包
///
- FCLoadBundleOperation LoadBundleAsync(LoadBundleOptions options);
+ FCLoadBundleOperation LoadBundleAsync(FCLoadBundleOptions options);
///
/// 是否已缓存指定 Bundle
diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/Internal.meta b/Assets/YooAsset/Runtime/FileCache/Operations/Common.meta
similarity index 100%
rename from Assets/YooAsset/Runtime/FileCache/Operations/Internal.meta
rename to Assets/YooAsset/Runtime/FileCache/Operations/Common.meta
diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadBuiltinCatalogOperation.cs b/Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadBuiltinCatalogOperation.cs
new file mode 100644
index 00000000..6c75f9a3
--- /dev/null
+++ b/Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadBuiltinCatalogOperation.cs
@@ -0,0 +1,133 @@
+using System;
+using System.IO;
+
+namespace YooAsset
+{
+ ///
+ /// 加载内置资源目录操作
+ ///
+ internal sealed class LoadBuiltinCatalogOperation : AsyncOperationBase
+ {
+ private enum ESteps
+ {
+ None,
+ TryLoadFileData,
+ RequestFileData,
+ LoadCatalog,
+ CheckResult,
+ Done,
+ }
+
+ private readonly LoadBuiltinCatalogOptions _options;
+ private IDownloadBytesRequest _downloadBytesRequest;
+ private byte[] _fileData;
+ private ESteps _steps = ESteps.None;
+
+ ///
+ /// 加载完成的内置资源目录
+ ///
+ public BuiltinCatalog Catalog;
+
+ internal LoadBuiltinCatalogOperation(LoadBuiltinCatalogOptions options)
+ {
+ _options = options;
+ }
+ internal override void InternalStart()
+ {
+ _steps = ESteps.TryLoadFileData;
+ }
+ internal override void InternalUpdate()
+ {
+ if (_steps == ESteps.None || _steps == ESteps.Done)
+ return;
+
+ if (_steps == ESteps.TryLoadFileData)
+ {
+ if (File.Exists(_options.FilePath))
+ {
+ try
+ {
+ _fileData = File.ReadAllBytes(_options.FilePath);
+ _steps = ESteps.LoadCatalog;
+ }
+ catch (Exception ex)
+ {
+ _steps = ESteps.Done;
+ Status = EOperationStatus.Failed;
+ Error = $"Failed to read file: {ex.Message}";
+ }
+ }
+ else
+ {
+ _steps = ESteps.RequestFileData;
+ }
+ }
+
+ if (_steps == ESteps.RequestFileData)
+ {
+ // 注意:从安装包体里解压数据
+ // 注意:从Web服务器下载数据
+ if (_downloadBytesRequest == null)
+ {
+ string url = DownloadSystemTools.ToLocalUrl(_options.FilePath);
+ var args = new DownloadDataRequestArgs(url, 60, 0);
+ _downloadBytesRequest = _options.DownloadBackend.CreateBytesRequest(args);
+ _downloadBytesRequest.SendRequest();
+ }
+
+ if (_downloadBytesRequest.IsDone == false)
+ return;
+
+ if (_downloadBytesRequest.Status == EDownloadRequestStatus.Succeeded)
+ {
+ _fileData = _downloadBytesRequest.Result;
+ _steps = ESteps.LoadCatalog;
+ }
+ else
+ {
+ _steps = ESteps.Done;
+ Status = EOperationStatus.Failed;
+ Error = _downloadBytesRequest.Error;
+ }
+ }
+
+ if (_steps == ESteps.LoadCatalog)
+ {
+ try
+ {
+ Catalog = BuiltinCatalogTools.DeserializeFromBinary(_fileData);
+ _steps = ESteps.CheckResult;
+ }
+ catch (Exception ex)
+ {
+ _steps = ESteps.Done;
+ Status = EOperationStatus.Failed;
+ Error = $"Failed to load catalog: {ex.Message}";
+ }
+ }
+
+ if (_steps == ESteps.CheckResult)
+ {
+ if (Catalog.PackageName == _options.PackageName)
+ {
+ _steps = ESteps.Done;
+ Status = EOperationStatus.Succeeded;
+ }
+ else
+ {
+ _steps = ESteps.Done;
+ Status = EOperationStatus.Failed;
+ Error = $"Catalog package name {Catalog.PackageName} cannot match the file cache package name {_options.PackageName}";
+ }
+ }
+ }
+ internal override void InternalDispose()
+ {
+ if (_downloadBytesRequest != null)
+ {
+ _downloadBytesRequest.Dispose();
+ _downloadBytesRequest = null;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/Operations/Internal/LoadBuiltinCatalogFileOperation.cs.meta b/Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadBuiltinCatalogOperation.cs.meta
similarity index 100%
rename from Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/Operations/Internal/LoadBuiltinCatalogFileOperation.cs.meta
rename to Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadBuiltinCatalogOperation.cs.meta
diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadBuiltinCatalogOptions.cs b/Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadBuiltinCatalogOptions.cs
new file mode 100644
index 00000000..b6c71680
--- /dev/null
+++ b/Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadBuiltinCatalogOptions.cs
@@ -0,0 +1,24 @@
+
+namespace YooAsset
+{
+ ///
+ /// 加载内置资源目录操作选项
+ ///
+ internal struct LoadBuiltinCatalogOptions
+ {
+ ///
+ /// 包裹名称
+ ///
+ public string PackageName { get; set; }
+
+ ///
+ /// 文件路径
+ ///
+ public string FilePath { get; set; }
+
+ ///
+ /// 下载后台
+ ///
+ public IDownloadBackend DownloadBackend { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/Operations/Internal/LoadWebServerCatalogOperation.cs.meta b/Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadBuiltinCatalogOptions.cs.meta
similarity index 83%
rename from Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/Operations/Internal/LoadWebServerCatalogOperation.cs.meta
rename to Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadBuiltinCatalogOptions.cs.meta
index bc7c85d1..2ce77e82 100644
--- a/Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/Operations/Internal/LoadWebServerCatalogOperation.cs.meta
+++ b/Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadBuiltinCatalogOptions.cs.meta
@@ -1,5 +1,5 @@
fileFormatVersion: 2
-guid: 236fcfdca8d96624087432269508ccee
+guid: 23227e3feab43ab4693cc17ad519f364
MonoImporter:
externalObjects: {}
serializedVersion: 2
diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadLocalAssetBundleOperation.cs b/Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadLocalAssetBundleOperation.cs
similarity index 68%
rename from Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadLocalAssetBundleOperation.cs
rename to Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadLocalAssetBundleOperation.cs
index b0f503be..3760568d 100644
--- a/Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadLocalAssetBundleOperation.cs
+++ b/Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadLocalAssetBundleOperation.cs
@@ -1,8 +1,11 @@
-using System.IO;
+using System.IO;
using UnityEngine;
namespace YooAsset
{
+ ///
+ /// 从本地文件加载 AssetBundle 操作
+ ///
internal class LoadLocalAssetBundleOperation : FCLoadBundleOperation
{
private enum ESteps
@@ -13,14 +16,16 @@ namespace YooAsset
Done,
}
- private readonly PackageBundle _bundle;
private readonly LoadLocalAssetBundleOptions _options;
private AssetBundleCreateRequest _createRequest;
private AssetBundle _assetBundle;
private Stream _loadStream;
private ESteps _steps = ESteps.None;
- public bool UnityEngineLoadFailed = false;
+ ///
+ /// Unity引擎加载是否失败
+ ///
+ public bool UnityEngineLoadFailed { get; private set; } = false;
public LoadLocalAssetBundleOperation(LoadLocalAssetBundleOptions options)
{
@@ -37,13 +42,13 @@ namespace YooAsset
if (_steps == ESteps.LoadBundle)
{
- if (_bundle.IsEncrypted == false)
+ if (_options.Bundle.IsEncrypted == false)
{
LoadFromFile();
}
else
{
- var decryptor = _options.Decryptor;
+ var decryptor = _options.AssetBundleDecryptor;
if (decryptor == null)
{
_steps = ESteps.Done;
@@ -52,17 +57,18 @@ namespace YooAsset
return;
}
+ LoadResult result;
if (decryptor is IBundleOffsetDecryptor offsetDecryptor)
{
- LoadFromFileWithOffset(offsetDecryptor);
+ result = LoadFromFileWithOffset(offsetDecryptor);
}
else if (decryptor is IBundleMemoryDecryptor memoryDecryptor)
{
- LoadFromMemory(memoryDecryptor);
+ result = LoadFromMemory(memoryDecryptor);
}
else if (decryptor is IBundleStreamDecryptor streamDecryptor)
{
- LoadFromStream(streamDecryptor);
+ result = LoadFromStream(streamDecryptor);
}
else
{
@@ -71,6 +77,14 @@ namespace YooAsset
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;
@@ -82,8 +96,8 @@ namespace YooAsset
{
if (IsWaitForCompletion)
{
- // ǿƹ̣߳ע⣺òܺʱ
- YooLogger.Warning("Suspend the main thread to load unity bundle.");
+ // 强制挂起主线程(注意:该操作会很耗时)
+ YooLogger.Warning("Suspending the main thread to load Unity bundle.");
_assetBundle = _createRequest.assetBundle;
}
else
@@ -100,6 +114,7 @@ namespace YooAsset
Status = EOperationStatus.Failed;
Error = "Unity engine load failed.";
UnityEngineLoadFailed = true;
+ CleanupStream();
}
else
{
@@ -121,10 +136,10 @@ namespace YooAsset
else
_createRequest = AssetBundle.LoadFromFileAsync(_options.FilePath);
}
- private void LoadFromFileWithOffset(IBundleOffsetDecryptor decryptor)
+ private LoadResult LoadFromFileWithOffset(IBundleOffsetDecryptor decryptor)
{
var args = new BundleDecryptArgs();
- args.Bundle = _bundle;
+ args.Bundle = _options.Bundle;
args.FilePath = _options.FilePath;
uint offset = decryptor.GetFileOffset(args);
@@ -132,31 +147,51 @@ namespace YooAsset
_assetBundle = AssetBundle.LoadFromFile(_options.FilePath, 0, offset);
else
_createRequest = AssetBundle.LoadFromFileAsync(_options.FilePath, 0, offset);
+
+ return LoadResult.Default();
}
- private void LoadFromMemory(IBundleMemoryDecryptor decryptor)
+ private LoadResult LoadFromMemory(IBundleMemoryDecryptor decryptor)
{
var args = new BundleDecryptArgs();
- args.Bundle = _bundle;
+ 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.");
if (IsWaitForCompletion)
_assetBundle = AssetBundle.LoadFromMemory(binaryData);
else
_createRequest = AssetBundle.LoadFromMemoryAsync(binaryData);
+
+ return LoadResult.Default();
}
- private void LoadFromStream(IBundleStreamDecryptor decryptor)
+ private LoadResult LoadFromStream(IBundleStreamDecryptor decryptor)
{
var args = new BundleDecryptArgs();
- args.Bundle = _bundle;
+ args.Bundle = _options.Bundle;
args.FilePath = _options.FilePath;
uint bufferSize = decryptor.GetReadBufferSize(args);
_loadStream = decryptor.GetDecryptStream(args);
+ if (_loadStream == null)
+ return LoadResult.Failure($"{_options.CacheName} decryptor returned null stream.");
+ uint unityCRC = 0;
if (IsWaitForCompletion)
- _assetBundle = AssetBundle.LoadFromStream(_loadStream, 0, bufferSize);
+ _assetBundle = AssetBundle.LoadFromStream(_loadStream, unityCRC, bufferSize);
else
- _createRequest = AssetBundle.LoadFromStreamAsync(_loadStream, 0, bufferSize);
+ _createRequest = AssetBundle.LoadFromStreamAsync(_loadStream, unityCRC, bufferSize);
+
+ return LoadResult.Default();
+ }
+ private void CleanupStream()
+ {
+ if (_loadStream != null)
+ {
+ _loadStream.Close();
+ _loadStream.Dispose();
+ _loadStream = null;
+ }
}
}
}
diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadLocalAssetBundleOperation.cs.meta b/Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadLocalAssetBundleOperation.cs.meta
similarity index 100%
rename from Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadLocalAssetBundleOperation.cs.meta
rename to Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadLocalAssetBundleOperation.cs.meta
diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadLocalAssetBundleOptions.cs b/Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadLocalAssetBundleOptions.cs
similarity index 85%
rename from Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadLocalAssetBundleOptions.cs
rename to Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadLocalAssetBundleOptions.cs
index 0d5df967..3f889601 100644
--- a/Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadLocalAssetBundleOptions.cs
+++ b/Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadLocalAssetBundleOptions.cs
@@ -22,9 +22,9 @@ namespace YooAsset
public string FilePath { get; set; }
///
- /// 解密接口
+ /// AssetBundle 解密器
///
- public IBundleDecryptor Decryptor { get; set; }
+ public IBundleDecryptor AssetBundleDecryptor { get; set; }
}
}
diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadLocalAssetBundleOptions.cs.meta b/Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadLocalAssetBundleOptions.cs.meta
similarity index 100%
rename from Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadLocalAssetBundleOptions.cs.meta
rename to Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadLocalAssetBundleOptions.cs.meta
diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadLocalRawBundleOperation.cs b/Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadLocalRawBundleOperation.cs
similarity index 76%
rename from Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadLocalRawBundleOperation.cs
rename to Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadLocalRawBundleOperation.cs
index 0c7f8077..956b5485 100644
--- a/Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadLocalRawBundleOperation.cs
+++ b/Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadLocalRawBundleOperation.cs
@@ -3,6 +3,9 @@ using System.IO;
namespace YooAsset
{
+ ///
+ /// 从本地加载 RawBundle 操作
+ ///
internal class LoadLocalRawBundleOperation : FCLoadBundleOperation
{
private enum ESteps
@@ -34,7 +37,7 @@ namespace YooAsset
{
if (_options.Bundle.IsEncrypted == false)
{
- if (IsSupportFileIO(_options.FilePath) == false)
+ if (SupportsFileIO(_options.FilePath) == false)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
@@ -46,7 +49,7 @@ namespace YooAsset
}
else
{
- var decryptor = _options.Decryptor;
+ var decryptor = _options.RawBundleDecryptor;
if (decryptor == null)
{
_steps = ESteps.Done;
@@ -55,9 +58,10 @@ namespace YooAsset
return;
}
+ LoadResult result;
if (decryptor is IBundleMemoryDecryptor memoryDecryptor)
{
- LoadFromMemory(memoryDecryptor);
+ result = LoadFromMemory(memoryDecryptor);
}
else
{
@@ -66,6 +70,14 @@ namespace YooAsset
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;
@@ -95,17 +107,19 @@ namespace YooAsset
private void LoadFromFile()
{
byte[] data = File.ReadAllBytes(_options.FilePath);
- if (data != null)
- _rawBundle = new RawBundle(data);
+ _rawBundle = new RawBundle(data);
}
- private void LoadFromMemory(IBundleMemoryDecryptor decryptor)
+ 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)
- _rawBundle = new RawBundle(binaryData);
+ if (binaryData == null)
+ return LoadResult.Failure($"{_options.CacheName} decryptor returned null data.");
+
+ _rawBundle = new RawBundle(binaryData);
+ return LoadResult.Default();
}
}
}
diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadLocalRawBundleOperation.cs.meta b/Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadLocalRawBundleOperation.cs.meta
similarity index 100%
rename from Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadLocalRawBundleOperation.cs.meta
rename to Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadLocalRawBundleOperation.cs.meta
diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadLocalRawBundleOptions.cs b/Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadLocalRawBundleOptions.cs
similarity index 85%
rename from Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadLocalRawBundleOptions.cs
rename to Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadLocalRawBundleOptions.cs
index 28cbc77c..f7524714 100644
--- a/Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadLocalRawBundleOptions.cs
+++ b/Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadLocalRawBundleOptions.cs
@@ -22,8 +22,8 @@ namespace YooAsset
public string FilePath { get; set; }
///
- /// 解密接口
+ /// RawBundle 解密器
///
- public IBundleDecryptor Decryptor { get; set; }
+ public IBundleDecryptor RawBundleDecryptor { get; set; }
}
}
diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadLocalRawBundleOptions.cs.meta b/Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadLocalRawBundleOptions.cs.meta
similarity index 100%
rename from Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadLocalRawBundleOptions.cs.meta
rename to Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadLocalRawBundleOptions.cs.meta
diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadWebAssetBundleOperation.cs b/Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadWebAssetBundleOperation.cs
similarity index 57%
rename from Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadWebAssetBundleOperation.cs
rename to Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadWebAssetBundleOperation.cs
index b94c55ff..9590b26c 100644
--- a/Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadWebAssetBundleOperation.cs
+++ b/Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadWebAssetBundleOperation.cs
@@ -1,18 +1,24 @@
-using UnityEngine;
+using UnityEngine;
namespace YooAsset
{
+ ///
+ /// 从网络加载 AssetBundle 操作的抽象基类
+ ///
internal abstract class LoadWebAssetBundleOperation : FCLoadBundleOperation
{
}
+ ///
+ /// 从网络加载未加密 AssetBundle 操作
+ ///
internal class LoadWebNormalAssetBundleOperation : LoadWebAssetBundleOperation
{
private enum ESteps
{
None,
- DownloadBundle,
- CheckResult,
+ BundleRequest,
+ CheckRequest,
TryAgain,
Done,
}
@@ -21,7 +27,7 @@ namespace YooAsset
private IDownloadAssetBundleRequest _downloadAssetBundleRequest;
private ESteps _steps = ESteps.None;
- // ʧ
+ // 失败重试
private int _requestCount = 0;
private float _tryAgainTimer = 0;
private int _failedTryAgain;
@@ -29,27 +35,27 @@ namespace YooAsset
public LoadWebNormalAssetBundleOperation(LoadWebAssetBundleOptions options)
{
_options = options;
- _failedTryAgain = int.MaxValue; //ע⣺ԭʧܺ³ֱɹ
+ _failedTryAgain = int.MaxValue; //注意:网络原因失败后,重新尝试直到成功
}
internal override void InternalStart()
{
- _steps = ESteps.DownloadBundle;
+ _steps = ESteps.BundleRequest;
}
internal override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
- if (_steps == ESteps.DownloadBundle)
+ if (_steps == ESteps.BundleRequest)
{
string url = GetRequestURL();
var args = new DownloadAssetBundleRequestArgs(url, 0, _options.WatchdogTimeout, _options.DisableUnityWebCache, _options.Bundle.FileHash, _options.Bundle.UnityCRC);
_downloadAssetBundleRequest = _options.DownloadBackend.CreateAssetBundleRequest(args);
_downloadAssetBundleRequest.SendRequest();
- _steps = ESteps.CheckResult;
+ _steps = ESteps.CheckRequest;
}
- if (_steps == ESteps.CheckResult)
+ if (_steps == ESteps.CheckRequest)
{
Progress = _downloadAssetBundleRequest.DownloadProgress;
if (_downloadAssetBundleRequest.IsDone == false)
@@ -62,7 +68,7 @@ namespace YooAsset
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
- Error = $"Fatal error: dwonload asset bundle is null.";
+ Error = $"Fatal error: downloaded asset bundle is null.";
}
else
{
@@ -73,7 +79,7 @@ namespace YooAsset
}
else
{
- if (_failedTryAgain > 0)
+ if (_failedTryAgain > 0 && IsRetryableError(_downloadAssetBundleRequest.HttpCode))
{
_steps = ESteps.TryAgain;
}
@@ -84,27 +90,39 @@ namespace YooAsset
Error = _downloadAssetBundleRequest.Error;
}
}
-
- // ͷ
- _downloadAssetBundleRequest.Dispose();
}
if (_steps == ESteps.TryAgain)
{
+ // 注意:失败后释放网络请求
+ if (_downloadAssetBundleRequest != null)
+ {
+ _downloadAssetBundleRequest.Dispose();
+ _downloadAssetBundleRequest = null;
+ }
+
_tryAgainTimer += UnityEngine.Time.unscaledDeltaTime;
if (_tryAgainTimer > 1f)
{
_tryAgainTimer = 0f;
_failedTryAgain--;
Progress = 0f;
- _steps = ESteps.DownloadBundle;
+ _steps = ESteps.BundleRequest;
}
}
}
+ internal override void InternalDispose()
+ {
+ if (_downloadAssetBundleRequest != null)
+ {
+ _downloadAssetBundleRequest.Dispose();
+ _downloadAssetBundleRequest = null;
+ }
+ }
private string GetRequestURL()
{
- // ַ
+ // 轮流返回请求地址
_requestCount++;
if (_requestCount % 2 == 0)
return _options.FallbackURL;
@@ -113,12 +131,18 @@ namespace YooAsset
}
}
+ ///
+ /// 从网络加载加密的 AssetBundle 操作
+ ///
internal class LoadWebEncryptedAssetBundleOperation : LoadWebAssetBundleOperation
{
private enum ESteps
{
None,
- DownloadData,
+ DataRequest,
+ CheckRequest,
+ VerifyData,
+ LoadBundle,
CheckResult,
TryAgain,
Done,
@@ -127,9 +151,10 @@ namespace YooAsset
protected readonly LoadWebAssetBundleOptions _options;
private IDownloadBytesRequest _downloadBytesRequest;
private IBundleMemoryDecryptor _decryptor;
+ private AssetBundleCreateRequest _createRequest;
private ESteps _steps = ESteps.None;
- // ʧ
+ // 失败重试
private int _requestCount = 0;
private float _tryAgainTimer = 0;
private int _failedTryAgain;
@@ -137,20 +162,20 @@ namespace YooAsset
public LoadWebEncryptedAssetBundleOperation(LoadWebAssetBundleOptions options)
{
_options = options;
- _failedTryAgain = int.MaxValue; //ע⣺ԭʧܺ³ֱɹ
+ _failedTryAgain = int.MaxValue; //注意:网络原因失败后,重新尝试直到成功
}
internal override void InternalStart()
{
- _steps = ESteps.DownloadData;
+ _steps = ESteps.DataRequest;
}
internal override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
- if (_steps == ESteps.DownloadData)
+ if (_steps == ESteps.DataRequest)
{
- var decryptor = _options.Decryptor;
+ var decryptor = _options.AssetBundleDecryptor;
if (decryptor == null)
{
_steps = ESteps.Done;
@@ -161,12 +186,12 @@ namespace YooAsset
if (decryptor is IBundleMemoryDecryptor)
{
- string url = GetRequestURL();
_decryptor = decryptor as IBundleMemoryDecryptor;
+ string url = GetRequestURL();
var args = new DownloadDataRequestArgs(url, 0, _options.WatchdogTimeout);
_downloadBytesRequest = _options.DownloadBackend.CreateBytesRequest(args);
_downloadBytesRequest.SendRequest();
- _steps = ESteps.CheckResult;
+ _steps = ESteps.CheckRequest;
}
else
{
@@ -177,32 +202,19 @@ namespace YooAsset
}
}
- if (_steps == ESteps.CheckResult)
+ if (_steps == ESteps.CheckRequest)
{
Progress = _downloadBytesRequest.DownloadProgress;
if (_downloadBytesRequest.IsDone == false)
return;
- //
if (_downloadBytesRequest.Status == EDownloadRequestStatus.Succeeded)
{
- var assetBundle = LoadFromMemory(_decryptor, _downloadBytesRequest.Result);
- if (assetBundle == null)
- {
- _steps = ESteps.Done;
- Status = EOperationStatus.Failed;
- Error = "Unity engine load failed.";
- }
- else
- {
- _steps = ESteps.Done;
- Status = EOperationStatus.Succeeded;
- BundleResult = new AssetBundleResult(_downloadBytesRequest.Url, _options.Bundle, assetBundle, null);
- }
+ _steps = ESteps.VerifyData;
}
else
{
- if (_failedTryAgain > 0)
+ if (_failedTryAgain > 0 && IsRetryableError(_downloadBytesRequest.HttpCode))
{
_steps = ESteps.TryAgain;
}
@@ -213,35 +225,118 @@ namespace YooAsset
Error = _downloadBytesRequest.Error;
}
}
+ }
- // ͷ
- _downloadBytesRequest.Dispose();
+ if (_steps == ESteps.VerifyData)
+ {
+ // 注意:网络/代理/服务器异常导致内容不完整但请求仍成功
+ EFileVerifyResult verifyResult;
+ if (_options.DownloadVerifyLevel == EFileVerifyLevel.Low || _options.DownloadVerifyLevel == EFileVerifyLevel.Middle)
+ verifyResult = FileVerifyTools.FileVerify(_downloadBytesRequest.Result, _options.Bundle.FileSize, 0);
+ else if (_options.DownloadVerifyLevel == EFileVerifyLevel.High)
+ verifyResult = FileVerifyTools.FileVerify(_downloadBytesRequest.Result, _options.Bundle.FileSize, _options.Bundle.FileCRC);
+ else
+ throw new System.NotImplementedException(_options.DownloadVerifyLevel.ToString());
+
+ if (verifyResult == EFileVerifyResult.Succeed)
+ {
+ _steps = ESteps.LoadBundle;
+ }
+ else
+ {
+ string error = $"[WebBundleVerify] Verify failed. Url:{_downloadBytesRequest.Url} Level: {_options.DownloadVerifyLevel} Result: {verifyResult}";
+ YooLogger.Warning(error);
+
+ if (_failedTryAgain > 0)
+ {
+ _steps = ESteps.TryAgain;
+ }
+ else
+ {
+ _steps = ESteps.Done;
+ Status = EOperationStatus.Failed;
+ Error = error;
+ }
+ }
+ }
+
+ if (_steps == ESteps.LoadBundle)
+ {
+ LoadResult result = LoadFromMemory(_decryptor, _downloadBytesRequest.Result);
+ if (result.Succeeded == false)
+ {
+ _steps = ESteps.Done;
+ Status = EOperationStatus.Failed;
+ Error = result.Error;
+ return;
+ }
+
+ _steps = ESteps.CheckResult;
+ }
+
+ if (_steps == ESteps.CheckResult)
+ {
+ if (_createRequest.isDone == false)
+ return;
+
+ var assetBundle = _createRequest.assetBundle;
+ if (assetBundle == null)
+ {
+ _steps = ESteps.Done;
+ Status = EOperationStatus.Failed;
+ Error = "Unity engine load failed.";
+ }
+ else
+ {
+ _steps = ESteps.Done;
+ Status = EOperationStatus.Succeeded;
+ BundleResult = new AssetBundleResult(_downloadBytesRequest.Url, _options.Bundle, assetBundle, null);
+ }
}
if (_steps == ESteps.TryAgain)
{
+ // 注意:失败后释放网络请求
+ if (_downloadBytesRequest != null)
+ {
+ _downloadBytesRequest.Dispose();
+ _downloadBytesRequest = null;
+ }
+
_tryAgainTimer += Time.unscaledDeltaTime;
if (_tryAgainTimer > 1f)
{
_tryAgainTimer = 0f;
_failedTryAgain--;
Progress = 0f;
- _steps = ESteps.DownloadData;
+ _steps = ESteps.DataRequest;
}
}
}
+ internal override void InternalDispose()
+ {
+ if (_downloadBytesRequest != null)
+ {
+ _downloadBytesRequest.Dispose();
+ _downloadBytesRequest = null;
+ }
+ }
- private AssetBundle LoadFromMemory(IBundleMemoryDecryptor decryptor, byte[] fileData)
+ private LoadResult LoadFromMemory(IBundleMemoryDecryptor decryptor, byte[] fileData)
{
var args = new BundleDecryptArgs();
args.Bundle = _options.Bundle;
args.FileData = fileData;
var binaryData = decryptor.GetDecryptData(args);
- return AssetBundle.LoadFromMemory(binaryData);
+ if (binaryData == null)
+ return LoadResult.Failure($"{_options.CacheName} decryptor returned null data.");
+
+ _createRequest = AssetBundle.LoadFromMemoryAsync(binaryData);
+ return LoadResult.Default();
}
private string GetRequestURL()
{
- // ַ
+ // 轮流返回请求地址
_requestCount++;
if (_requestCount % 2 == 0)
return _options.FallbackURL;
diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadWebAssetBundleOperation.cs.meta b/Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadWebAssetBundleOperation.cs.meta
similarity index 100%
rename from Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadWebAssetBundleOperation.cs.meta
rename to Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadWebAssetBundleOperation.cs.meta
diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadWebAssetBundleOptions.cs b/Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadWebAssetBundleOptions.cs
similarity index 79%
rename from Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadWebAssetBundleOptions.cs
rename to Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadWebAssetBundleOptions.cs
index 47805439..b0525dc1 100644
--- a/Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadWebAssetBundleOptions.cs
+++ b/Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadWebAssetBundleOptions.cs
@@ -22,20 +22,25 @@ namespace YooAsset
public string MainURL { get; set; }
///
- /// 请求地址
+ /// 备用请求地址
///
public string FallbackURL { get; set; }
///
- /// 解密接口
+ /// AssetBundle 解密器
///
- public IBundleDecryptor Decryptor { get; set; }
+ public IBundleDecryptor AssetBundleDecryptor { get; set; }
///
/// 下载后台接口
///
public IDownloadBackend DownloadBackend { get; set; }
+ ///
+ /// 下载数据校验级别
+ ///
+ public EFileVerifyLevel DownloadVerifyLevel { get; set; }
+
///
/// 看门狗超时时间
///
diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadWebAssetBundleOptions.cs.meta b/Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadWebAssetBundleOptions.cs.meta
similarity index 100%
rename from Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadWebAssetBundleOptions.cs.meta
rename to Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadWebAssetBundleOptions.cs.meta
diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/FCClearCacheOperation.cs b/Assets/YooAsset/Runtime/FileCache/Operations/FCClearCacheOperation.cs
index 32ef1a50..701baae4 100644
--- a/Assets/YooAsset/Runtime/FileCache/Operations/FCClearCacheOperation.cs
+++ b/Assets/YooAsset/Runtime/FileCache/Operations/FCClearCacheOperation.cs
@@ -1,10 +1,16 @@
namespace YooAsset
{
+ ///
+ /// 清理缓存操作基类
+ ///
internal abstract class FCClearCacheOperation : AsyncOperationBase
{
}
+ ///
+ /// 清理缓存完成操作
+ ///
internal class FCClearCacheCompleteOperation : FCClearCacheOperation
{
private readonly string _error;
diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/FCInitializeOperation.cs b/Assets/YooAsset/Runtime/FileCache/Operations/FCInitializeOperation.cs
index bb57ae32..bfe6a2cd 100644
--- a/Assets/YooAsset/Runtime/FileCache/Operations/FCInitializeOperation.cs
+++ b/Assets/YooAsset/Runtime/FileCache/Operations/FCInitializeOperation.cs
@@ -1,6 +1,9 @@
namespace YooAsset
{
+ ///
+ /// 文件缓存初始化操作基类
+ ///
internal abstract class FCInitializeOperation : AsyncOperationBase
{
}
diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/FCLoadBundleOperation.cs b/Assets/YooAsset/Runtime/FileCache/Operations/FCLoadBundleOperation.cs
index ca1e9a10..b72eed94 100644
--- a/Assets/YooAsset/Runtime/FileCache/Operations/FCLoadBundleOperation.cs
+++ b/Assets/YooAsset/Runtime/FileCache/Operations/FCLoadBundleOperation.cs
@@ -1,27 +1,91 @@
-
+
namespace YooAsset
{
+ ///
+ /// 加载资源包操作基类
+ ///
internal abstract class FCLoadBundleOperation : AsyncOperationBase
{
+ protected struct LoadResult
+ {
+ ///
+ /// 错误信息
+ ///
+ public readonly string Error;
+
+ ///
+ /// 加载成功
+ ///
+ public bool Succeeded
+ {
+ get { return Error == null; }
+ }
+
+ public LoadResult(string error)
+ {
+ Error = error;
+ }
+
+ public static LoadResult Default()
+ {
+ return new LoadResult(null);
+ }
+ public static LoadResult Failure(string error)
+ {
+ return new LoadResult(error);
+ }
+ }
+
+ ///
+ /// 资源包加载结果
+ ///
public IBundleResult BundleResult { get; protected set; }
///
/// 检查文件路径是否支持 FileIO 读取
///
- protected bool IsSupportFileIO(string filePath)
+ protected bool SupportsFileIO(string filePath)
{
if (string.IsNullOrEmpty(filePath))
- return true;
+ return false;
if (filePath.StartsWith("jar:") || filePath.StartsWith("content:"))
return false;
return true;
}
+
+ ///
+ /// 判断是否为可重试的错误
+ ///
+ protected bool IsRetryableError(long httpCode)
+ {
+ // HTTP 状态码
+ // 1xx 信息响应
+ // 2xx 成功响应
+ // 3xx 重定向消息
+ // 4xx 客户端错误响应
+ // 5xx 服务器错误响应
+
+ if (httpCode == 0)
+ return true;
+
+ // 4xx 客户端错误不可重试
+ // 说明:408 Request Timeout
+ // 说明:429 Too Many Requests
+ if (httpCode >= 400 && httpCode < 500)
+ return httpCode == 408 || httpCode == 429;
+
+ // 其它情况可重试
+ return true;
+ }
}
+ ///
+ /// 加载资源包失败操作
+ ///
internal sealed class FCLoadBundleErrorOperation : FCLoadBundleOperation
{
private readonly string _error;
-
+
internal FCLoadBundleErrorOperation(string error)
{
_error = error;
diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/FCLoadBundleOptions.cs b/Assets/YooAsset/Runtime/FileCache/Operations/FCLoadBundleOptions.cs
index ec3dcf0c..dcb614f5 100644
--- a/Assets/YooAsset/Runtime/FileCache/Operations/FCLoadBundleOptions.cs
+++ b/Assets/YooAsset/Runtime/FileCache/Operations/FCLoadBundleOptions.cs
@@ -1,14 +1,17 @@
-
+
namespace YooAsset
{
- internal struct LoadBundleOptions
+ ///
+ /// 加载资源包操作选项
+ ///
+ internal readonly struct FCLoadBundleOptions
{
///
/// 资源包
///
public readonly PackageBundle Bundle;
- public LoadBundleOptions(PackageBundle bundle)
+ public FCLoadBundleOptions(PackageBundle bundle)
{
Bundle = bundle;
}
diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/FCVerifyCacheOperation.cs b/Assets/YooAsset/Runtime/FileCache/Operations/FCVerifyCacheOperation.cs
index f2312a5b..0cfa9319 100644
--- a/Assets/YooAsset/Runtime/FileCache/Operations/FCVerifyCacheOperation.cs
+++ b/Assets/YooAsset/Runtime/FileCache/Operations/FCVerifyCacheOperation.cs
@@ -1,10 +1,16 @@
namespace YooAsset
{
+ ///
+ /// 验证缓存操作基类
+ ///
internal abstract class FCVerifyCacheOperation : AsyncOperationBase
{
}
+ ///
+ /// 验证缓存完成操作
+ ///
internal class FCVerifyCacheCompleteOperation : FCVerifyCacheOperation
{
private readonly string _error;
diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/FCVerifyCacheOptions.cs b/Assets/YooAsset/Runtime/FileCache/Operations/FCVerifyCacheOptions.cs
index e9279bdc..9b14ce2f 100644
--- a/Assets/YooAsset/Runtime/FileCache/Operations/FCVerifyCacheOptions.cs
+++ b/Assets/YooAsset/Runtime/FileCache/Operations/FCVerifyCacheOptions.cs
@@ -1,7 +1,10 @@
namespace YooAsset
{
- internal struct VerifyCacheOptions
+ ///
+ /// 验证缓存操作选项
+ ///
+ internal struct FCVerifyCacheOptions
{
///
/// 要验证的资源包
@@ -9,8 +12,8 @@ namespace YooAsset
public PackageBundle Bundle { get; set; }
///
- /// 失败后直接移除缓存
+ /// 失败后直接移除缓存条目
///
- public bool FailedDeleteCache { get; set; }
+ public bool DeleteCacheEntryOnFailure { get; set; }
}
}
diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/FCWriteCacheOperation.cs b/Assets/YooAsset/Runtime/FileCache/Operations/FCWriteCacheOperation.cs
index 3c817586..d5f5f30e 100644
--- a/Assets/YooAsset/Runtime/FileCache/Operations/FCWriteCacheOperation.cs
+++ b/Assets/YooAsset/Runtime/FileCache/Operations/FCWriteCacheOperation.cs
@@ -1,10 +1,16 @@
namespace YooAsset
{
+ ///
+ /// 写入缓存操作基类
+ ///
internal abstract class FCWriteCacheOperation : AsyncOperationBase
{
}
+ ///
+ /// 写入缓存完成操作
+ ///
internal class FCWriteCacheCompleteOperation : FCWriteCacheOperation
{
private readonly string _error;
diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/FCWriteCacheOptions.cs b/Assets/YooAsset/Runtime/FileCache/Operations/FCWriteCacheOptions.cs
index 71b73c17..787faa7d 100644
--- a/Assets/YooAsset/Runtime/FileCache/Operations/FCWriteCacheOptions.cs
+++ b/Assets/YooAsset/Runtime/FileCache/Operations/FCWriteCacheOptions.cs
@@ -1,7 +1,10 @@
namespace YooAsset
{
- internal struct WriteCacheOptions
+ ///
+ /// 写入缓存操作选项
+ ///
+ internal struct FCWriteCacheOptions
{
///
/// 要缓存的资源包
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinFileCatalog.cs b/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinCatalog.cs
similarity index 57%
rename from Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinFileCatalog.cs
rename to Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinCatalog.cs
index 7ef344c3..26a5ac1f 100644
--- a/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinFileCatalog.cs
+++ b/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinCatalog.cs
@@ -1,19 +1,29 @@
-using System;
+using System;
using System.IO;
using System.Collections.Generic;
namespace YooAsset
{
///
- /// 内置资源清单目录
+ /// 内置资源目录
///
[Serializable]
- internal class BuiltinFileCatalog
+ internal class BuiltinCatalog
{
+ ///
+ /// 内置资源文件条目
+ ///
[Serializable]
- public class FileWrapper
+ public class FileEntry
{
+ ///
+ /// 资源包唯一标识
+ ///
public string BundleGUID;
+
+ ///
+ /// 资源包文件名
+ ///
public string FileName;
}
@@ -33,8 +43,8 @@ namespace YooAsset
public string PackageVersion;
///
- /// 文件列表
+ /// 文件条目列表
///
- public List Wrappers = new List();
+ public List FileEntries = new List();
}
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinFileCatalog.cs.meta b/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinCatalog.cs.meta
similarity index 100%
rename from Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinFileCatalog.cs.meta
rename to Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinCatalog.cs.meta
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinFileCatalogDefine.cs b/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinCatalogDefine.cs
similarity index 73%
rename from Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinFileCatalogDefine.cs
rename to Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinCatalogDefine.cs
index b3e9dc87..d04e9988 100644
--- a/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinFileCatalogDefine.cs
+++ b/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinCatalogDefine.cs
@@ -1,17 +1,20 @@
-
+
namespace YooAsset
{
- internal class BuiltinFileCatalogDefine
+ ///
+ /// 内置资源目录常量定义
+ ///
+ internal class BuiltinCatalogDefine
{
///
/// 文件极限大小(100MB)
///
- public const int FileMaxSize = 104857600;
+ public const int MaxFileSize = 104857600;
///
/// 文件头标记
///
- public const uint FileSign = 0x133C5EE;
+ public const uint FileHeader = 0x133C5EE;
///
/// 文件格式版本
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinFileCatalogDefine.cs.meta b/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinCatalogDefine.cs.meta
similarity index 100%
rename from Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinFileCatalogDefine.cs.meta
rename to Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinCatalogDefine.cs.meta
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinFileCatalogTools.cs b/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinCatalogTools.cs
similarity index 63%
rename from Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinFileCatalogTools.cs
rename to Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinCatalogTools.cs
index 75beb29d..6d573199 100644
--- a/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinFileCatalogTools.cs
+++ b/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinCatalogTools.cs
@@ -1,11 +1,14 @@
-using System;
+using System;
using System.IO;
using System.Collections.Generic;
using UnityEngine;
namespace YooAsset
{
- internal static class BuiltinFileCatalogTools
+ ///
+ /// 内置资源目录工具类
+ ///
+ internal static class BuiltinCatalogTools
{
#if UNITY_EDITOR
///
@@ -21,7 +24,7 @@ namespace YooAsset
string versionFilePath = $"{packageDirectory}/{versionFileName}";
if (File.Exists(versionFilePath) == false)
{
- Debug.LogError($"Can not found package version file : {versionFilePath}");
+ Debug.LogError($"Package version file not found: {versionFilePath}");
return false;
}
@@ -35,7 +38,7 @@ namespace YooAsset
string manifestFilePath = $"{packageDirectory}/{manifestFileName}";
if (File.Exists(manifestFilePath) == false)
{
- Debug.LogError($"Can not found package manifest file : {manifestFilePath}");
+ Debug.LogError($"Package manifest file not found: {manifestFilePath}");
return false;
}
@@ -53,29 +56,29 @@ namespace YooAsset
}
// 创建内置清单实例
- var buildinFileCatalog = new BuiltinFileCatalog();
- buildinFileCatalog.FileVersion = BuiltinFileCatalogDefine.FileVersion;
- buildinFileCatalog.PackageName = packageName;
- buildinFileCatalog.PackageVersion = packageVersion;
+ var buildinCatalog = new BuiltinCatalog();
+ buildinCatalog.FileVersion = BuiltinCatalogDefine.FileVersion;
+ buildinCatalog.PackageName = packageName;
+ buildinCatalog.PackageVersion = packageVersion;
// 创建白名单查询集合
- HashSet whiteFileList = new HashSet
+ HashSet whiteFileNameList = new HashSet
{
"link.xml",
"buildlogtep.json",
- BuiltinFileCatalogDefine.JsonFileName,
- BuiltinFileCatalogDefine.BinaryFileName
+ BuiltinCatalogDefine.JsonFileName,
+ BuiltinCatalogDefine.BinaryFileName
};
string packageVersionFileName = YooAssetSettingsData.GetPackageVersionFileName(packageName);
string packageHashFileName = YooAssetSettingsData.GetPackageHashFileName(packageName, packageVersion);
- string manifestBinaryFIleName = YooAssetSettingsData.GetManifestBinaryFileName(packageName, packageVersion);
- string manifestJsonFIleName = YooAssetSettingsData.GetManifestJsonFileName(packageName, packageVersion);
+ string manifestBinaryFileName = YooAssetSettingsData.GetManifestBinaryFileName(packageName, packageVersion);
+ string manifestJsonFileName = YooAssetSettingsData.GetManifestJsonFileName(packageName, packageVersion);
string reportFileName = YooAssetSettingsData.GetBuildReportFileName(packageName, packageVersion);
- whiteFileList.Add(packageVersionFileName);
- whiteFileList.Add(packageHashFileName);
- whiteFileList.Add(manifestBinaryFIleName);
- whiteFileList.Add(manifestJsonFIleName);
- whiteFileList.Add(reportFileName);
+ whiteFileNameList.Add(packageVersionFileName);
+ whiteFileNameList.Add(packageHashFileName);
+ whiteFileNameList.Add(manifestBinaryFileName);
+ whiteFileNameList.Add(manifestJsonFileName);
+ whiteFileNameList.Add(reportFileName);
// 记录所有内置资源文件
DirectoryInfo rootDirectory = new DirectoryInfo(packageDirectory);
@@ -85,37 +88,37 @@ namespace YooAsset
if (fileInfo.Extension == ".meta")
continue;
- if (whiteFileList.Contains(fileInfo.Name))
+ if (whiteFileNameList.Contains(fileInfo.Name))
continue;
string fileName = fileInfo.Name;
if (fileMapping.TryGetValue(fileName, out string bundleGUID))
{
- var wrapper = new BuiltinFileCatalog.FileWrapper();
- wrapper.BundleGUID = bundleGUID;
- wrapper.FileName = fileName;
- buildinFileCatalog.Wrappers.Add(wrapper);
+ var fileEntry = new BuiltinCatalog.FileEntry();
+ fileEntry.BundleGUID = bundleGUID;
+ fileEntry.FileName = fileName;
+ buildinCatalog.FileEntries.Add(fileEntry);
}
else
{
- Debug.LogWarning($"Failed mapping file : {fileName}");
+ Debug.LogWarning($"Failed to map file: {fileName}");
}
}
// 创建输出文件
- string jsonFilePath = $"{packageDirectory}/{BuiltinFileCatalogDefine.JsonFileName}";
+ string jsonFilePath = $"{packageDirectory}/{BuiltinCatalogDefine.JsonFileName}";
if (File.Exists(jsonFilePath))
File.Delete(jsonFilePath);
- SerializeToJson(jsonFilePath, buildinFileCatalog);
+ SerializeToJson(jsonFilePath, buildinCatalog);
// 创建输出文件
- string binaryFilePath = $"{packageDirectory}/{BuiltinFileCatalogDefine.BinaryFileName}";
+ string binaryFilePath = $"{packageDirectory}/{BuiltinCatalogDefine.BinaryFileName}";
if (File.Exists(binaryFilePath))
File.Delete(binaryFilePath);
- SerializeToBinary(binaryFilePath, buildinFileCatalog);
+ SerializeToBinary(binaryFilePath, buildinCatalog);
UnityEditor.AssetDatabase.Refresh();
- Debug.Log($"Succeed to save catalog file : {binaryFilePath}");
+ Debug.Log($"Successfully saved catalog file: {binaryFilePath}");
return true;
}
@@ -125,71 +128,62 @@ namespace YooAsset
public static bool CreateEmptyFile(string packageName, string packageVersion, string outputPath)
{
// 创建内置清单实例
- var buildinFileCatalog = new BuiltinFileCatalog();
- buildinFileCatalog.FileVersion = BuiltinFileCatalogDefine.FileVersion;
+ var buildinFileCatalog = new BuiltinCatalog();
+ buildinFileCatalog.FileVersion = BuiltinCatalogDefine.FileVersion;
buildinFileCatalog.PackageName = packageName;
buildinFileCatalog.PackageVersion = packageVersion;
// 创建输出文件
- string jsonFilePath = $"{outputPath}/{BuiltinFileCatalogDefine.JsonFileName}";
+ string jsonFilePath = $"{outputPath}/{BuiltinCatalogDefine.JsonFileName}";
if (File.Exists(jsonFilePath))
File.Delete(jsonFilePath);
SerializeToJson(jsonFilePath, buildinFileCatalog);
// 创建输出文件
- string binaryFilePath = $"{outputPath}/{BuiltinFileCatalogDefine.BinaryFileName}";
+ string binaryFilePath = $"{outputPath}/{BuiltinCatalogDefine.BinaryFileName}";
if (File.Exists(binaryFilePath))
File.Delete(binaryFilePath);
SerializeToBinary(binaryFilePath, buildinFileCatalog);
UnityEditor.AssetDatabase.Refresh();
- Debug.Log($"Succeed to save catalog file : {binaryFilePath}");
+ Debug.Log($"Successfully saved catalog file: {binaryFilePath}");
return true;
}
-#endif
///
/// 序列化(JSON文件)
///
- public static void SerializeToJson(string savePath, BuiltinFileCatalog catalog)
+ public static void SerializeToJson(string savePath, BuiltinCatalog catalog)
{
string json = JsonUtility.ToJson(catalog, true);
FileUtility.WriteAllText(savePath, json);
}
- ///
- /// 反序列化(JSON文件)
- ///
- public static BuiltinFileCatalog DeserializeFromJson(string jsonContent)
- {
- return JsonUtility.FromJson(jsonContent);
- }
-
///
/// 序列化(二进制文件)
///
- public static void SerializeToBinary(string savePath, BuiltinFileCatalog catalog)
+ public static void SerializeToBinary(string savePath, BuiltinCatalog catalog)
{
using (FileStream fs = new FileStream(savePath, FileMode.Create))
{
// 创建缓存器
- BufferWriter buffer = new BufferWriter(BuiltinFileCatalogDefine.FileMaxSize);
+ BufferWriter buffer = new BufferWriter(BuiltinCatalogDefine.MaxFileSize);
// 写入文件标记
- buffer.WriteUInt32(BuiltinFileCatalogDefine.FileSign);
+ buffer.WriteUInt32(BuiltinCatalogDefine.FileHeader);
// 写入文件版本
- buffer.WriteUTF8(BuiltinFileCatalogDefine.FileVersion);
+ buffer.WriteUTF8(BuiltinCatalogDefine.FileVersion);
// 写入文件头信息
buffer.WriteUTF8(catalog.PackageName);
buffer.WriteUTF8(catalog.PackageVersion);
// 写入资源包列表
- buffer.WriteInt32(catalog.Wrappers.Count);
- for (int i = 0; i < catalog.Wrappers.Count; i++)
+ buffer.WriteInt32(catalog.FileEntries.Count);
+ for (int i = 0; i < catalog.FileEntries.Count; i++)
{
- var fileWrapper = catalog.Wrappers[i];
+ var fileWrapper = catalog.FileEntries[i];
buffer.WriteUTF8(fileWrapper.BundleGUID);
buffer.WriteUTF8(fileWrapper.FileName);
}
@@ -199,11 +193,20 @@ namespace YooAsset
fs.Flush();
}
}
+#endif
+
+ ///
+ /// 反序列化(JSON文件)
+ ///
+ public static BuiltinCatalog DeserializeFromJson(string jsonContent)
+ {
+ return JsonUtility.FromJson(jsonContent);
+ }
///
/// 反序列化(二进制文件)
///
- public static BuiltinFileCatalog DeserializeFromBinary(byte[] binaryData)
+ public static BuiltinCatalog DeserializeFromBinary(byte[] binaryData)
{
if (binaryData == null || binaryData.Length == 0)
throw new Exception("Catalog file data is null or empty.");
@@ -212,31 +215,31 @@ namespace YooAsset
BufferReader buffer = new BufferReader(binaryData);
// 读取文件标记
- uint fileSign = buffer.ReadUInt32();
- if (fileSign != BuiltinFileCatalogDefine.FileSign)
+ uint fileHeader = buffer.ReadUInt32();
+ if (fileHeader != BuiltinCatalogDefine.FileHeader)
throw new Exception("Invalid catalog file.");
// 读取文件版本
string fileVersion = buffer.ReadUTF8();
- if (fileVersion != BuiltinFileCatalogDefine.FileVersion)
- throw new Exception($"The catalog file version are not compatible : {fileVersion} != {BuiltinFileCatalogDefine.FileVersion}");
+ if (fileVersion != BuiltinCatalogDefine.FileVersion)
+ throw new Exception($"The catalog file version is not compatible: {fileVersion} != {BuiltinCatalogDefine.FileVersion}");
- BuiltinFileCatalog catalog = new BuiltinFileCatalog();
+ BuiltinCatalog catalog = new BuiltinCatalog();
{
// 读取文件头信息
catalog.FileVersion = fileVersion;
catalog.PackageName = buffer.ReadUTF8();
catalog.PackageVersion = buffer.ReadUTF8();
- // 读取资源包列表
+ // 读取文件条目列表
int fileCount = buffer.ReadInt32();
- catalog.Wrappers = new List(fileCount);
+ catalog.FileEntries = new List(fileCount);
for (int i = 0; i < fileCount; i++)
{
- var fileWrapper = new BuiltinFileCatalog.FileWrapper();
- fileWrapper.BundleGUID = buffer.ReadUTF8();
- fileWrapper.FileName = buffer.ReadUTF8();
- catalog.Wrappers.Add(fileWrapper);
+ var fileEntry = new BuiltinCatalog.FileEntry();
+ fileEntry.BundleGUID = buffer.ReadUTF8();
+ fileEntry.FileName = buffer.ReadUTF8();
+ catalog.FileEntries.Add(fileEntry);
}
}
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinFileCatalogTools.cs.meta b/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinCatalogTools.cs.meta
similarity index 100%
rename from Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinFileCatalogTools.cs.meta
rename to Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinCatalogTools.cs.meta
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinFileCache.cs b/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinFileCache.cs
index a7d526c1..2b1ba81d 100644
--- a/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinFileCache.cs
+++ b/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinFileCache.cs
@@ -1,10 +1,16 @@
-using System;
+using System;
using System.Collections.Generic;
namespace YooAsset
{
+ ///
+ /// 内置文件缓存系统,用于管理 StreamingAssets 中的资源包
+ ///
internal class BuiltinFileCache : IFileCache
{
+ ///
+ /// 内置文件缓存配置
+ ///
internal struct CacheConfig
{
///
@@ -18,14 +24,16 @@ namespace YooAsset
public IBundleDecryptor RawBundleDecryptor { get; set; }
///
- /// 下载后台接口
+ /// 下载后台
///
public IDownloadBackend DownloadBackend { get; set; }
}
- private readonly Dictionary _caches = new Dictionary(10000);
+ private readonly Dictionary _cacheEntries = new Dictionary(10000);
- // 缓存配置
+ ///
+ /// 缓存配置
+ ///
internal readonly CacheConfig Config;
#region 接口属性
@@ -51,7 +59,7 @@ namespace YooAsset
{
get
{
- return _caches.Count;
+ return _cacheEntries.Count;
}
}
@@ -62,6 +70,12 @@ namespace YooAsset
public long SpaceOccupied { get; private set; }
#endregion
+ ///
+ /// 创建内置文件缓存系统实例
+ ///
+ /// 包裹名称
+ /// 缓存根目录
+ /// 缓存配置
public BuiltinFileCache(string packageName, string rootPath, CacheConfig config)
{
PackageName = packageName;
@@ -77,7 +91,7 @@ namespace YooAsset
var operation = new BFCInitializeOperation(this);
return operation;
}
- public virtual FCWriteCacheOperation WriteCacheAsync(WriteCacheOptions options)
+ public virtual FCWriteCacheOperation WriteCacheAsync(FCWriteCacheOptions options)
{
var operation = new FCWriteCacheCompleteOperation($"{nameof(BuiltinFileCache)} is readonly.");
return operation;
@@ -87,12 +101,12 @@ namespace YooAsset
var operation = new FCClearCacheCompleteOperation($"{nameof(BuiltinFileCache)} is readonly.");
return operation;
}
- public virtual FCVerifyCacheOperation VerifyCacheAsync(VerifyCacheOptions options)
+ public virtual FCVerifyCacheOperation VerifyCacheAsync(FCVerifyCacheOptions options)
{
var operation = new FCVerifyCacheCompleteOperation();
return operation;
}
- public virtual FCLoadBundleOperation LoadBundleAsync(LoadBundleOptions options)
+ public virtual FCLoadBundleOperation LoadBundleAsync(FCLoadBundleOptions options)
{
if (options.Bundle.BundleType == (int)EBundleType.AssetBundle)
{
@@ -113,16 +127,16 @@ namespace YooAsset
}
public virtual bool IsCached(string bundleGUID)
{
- return _caches.ContainsKey(bundleGUID);
+ return _cacheEntries.ContainsKey(bundleGUID);
}
#region 内部方法
///
/// 获取指定缓存
///
- public BuiltinFileCacheEntry GetEntry(string bundleGUID)
+ internal BuiltinFileCacheEntry GetEntry(string bundleGUID)
{
- if (_caches.TryGetValue(bundleGUID, out BuiltinFileCacheEntry entry))
+ if (_cacheEntries.TryGetValue(bundleGUID, out BuiltinFileCacheEntry entry))
return entry;
else
return null;
@@ -131,12 +145,12 @@ namespace YooAsset
///
/// 添加指定缓存
///
- internal void AddEntry(string bundleGUID, BuiltinFileCacheEntry entry)
+ internal void AddEntry(string bundleGUID, BuiltinFileCacheEntry cacheEntry)
{
- if (_caches.ContainsKey(bundleGUID))
- throw new YooInternalException($"Cache entry already existed: {bundleGUID}");
+ if (_cacheEntries.ContainsKey(bundleGUID))
+ throw new YooInternalException($"Cache entry already exists: {bundleGUID}");
- _caches.Add(bundleGUID, entry);
+ _cacheEntries.Add(bundleGUID, cacheEntry);
}
///
@@ -144,7 +158,7 @@ namespace YooAsset
///
internal string GetCatalogBinaryFileLoadPath()
{
- return PathUtility.Combine(RootPath, BuiltinFileCatalogDefine.BinaryFileName);
+ return PathUtility.Combine(RootPath, BuiltinCatalogDefine.BinaryFileName);
}
#endregion
}
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinFileCacheEntry.cs b/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinFileCacheEntry.cs
index 8f86aefc..acd72b27 100644
--- a/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinFileCacheEntry.cs
+++ b/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinFileCacheEntry.cs
@@ -1,11 +1,26 @@
-
+
namespace YooAsset
{
+ ///
+ /// 内置文件缓存条目
+ ///
internal class BuiltinFileCacheEntry : ICacheEntry
{
+ ///
+ /// 资源包唯一标识
+ ///
public string BundleGUID { get; private set; }
+
+ ///
+ /// 资源包文件路径
+ ///
public string FilePath { get; private set; }
+ ///
+ /// 创建内置文件缓存条目
+ ///
+ /// 资源包唯一标识
+ /// 资源包文件路径
public BuiltinFileCacheEntry(string bundleGUID, string filePath)
{
BundleGUID = bundleGUID;
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/Operations/BFCInitializeOperation.cs b/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/Operations/BFCInitializeOperation.cs
index 7751300b..933db7fa 100644
--- a/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/Operations/BFCInitializeOperation.cs
+++ b/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/Operations/BFCInitializeOperation.cs
@@ -1,67 +1,77 @@
-
+
namespace YooAsset
{
+ ///
+ /// 内置文件缓存初始化操作
+ ///
internal class BFCInitializeOperation : FCInitializeOperation
{
private enum ESteps
{
None,
- LoadCatalogFile,
- RecordFiles,
+ LoadCatalog,
+ RecordEntry,
Done,
}
private readonly BuiltinFileCache _fileCache;
- private LoadBuiltinCatalogFileOperation _loadBuiltinCatalogFileOp;
+ private LoadBuiltinCatalogOperation _loadBuiltinCatalogOp;
private ESteps _steps = ESteps.None;
- public BFCInitializeOperation(BuiltinFileCache cache)
+ public BFCInitializeOperation(BuiltinFileCache fileCache)
{
- _fileCache = cache;
+ _fileCache = fileCache;
}
internal override void InternalStart()
{
- _steps = ESteps.LoadCatalogFile;
+ _steps = ESteps.LoadCatalog;
}
internal override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
- if (_steps == ESteps.LoadCatalogFile)
+ if (_steps == ESteps.LoadCatalog)
{
- if (_loadBuiltinCatalogFileOp == null)
+ if (_loadBuiltinCatalogOp == null)
{
- _loadBuiltinCatalogFileOp = new LoadBuiltinCatalogFileOperation(_fileCache);
- _loadBuiltinCatalogFileOp.StartOperation();
- AddChildOperation(_loadBuiltinCatalogFileOp);
+ var options = new LoadBuiltinCatalogOptions();
+ options.PackageName = _fileCache.PackageName;
+ options.FilePath = _fileCache.GetCatalogBinaryFileLoadPath();
+ options.DownloadBackend = _fileCache.Config.DownloadBackend;
+ _loadBuiltinCatalogOp = new LoadBuiltinCatalogOperation(options);
+ _loadBuiltinCatalogOp.StartOperation();
+ AddChildOperation(_loadBuiltinCatalogOp);
}
- _loadBuiltinCatalogFileOp.UpdateOperation();
- if (_loadBuiltinCatalogFileOp.IsDone == false)
+ _loadBuiltinCatalogOp.UpdateOperation();
+ if (_loadBuiltinCatalogOp.IsDone == false)
return;
- if (_loadBuiltinCatalogFileOp.Status == EOperationStatus.Succeeded)
+ if (_loadBuiltinCatalogOp.Status == EOperationStatus.Succeeded)
{
- _steps = ESteps.RecordFiles;
+ _steps = ESteps.RecordEntry;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
- Error = _loadBuiltinCatalogFileOp.Error;
+ Error = _loadBuiltinCatalogOp.Error;
}
}
- if (_steps == ESteps.RecordFiles)
+ if (_steps == ESteps.RecordEntry)
{
- var catalog = _loadBuiltinCatalogFileOp.Catalog;
- foreach (var wrapper in catalog.Wrappers)
+ var catalog = _loadBuiltinCatalogOp.Catalog;
+ foreach (var fileEntry in catalog.FileEntries)
{
- string filePath = PathUtility.Combine(_fileCache.RootPath, wrapper.FileName);
- var entry = new BuiltinFileCacheEntry(wrapper.BundleGUID, filePath);
- _fileCache.AddEntry(wrapper.BundleGUID, entry);
+ string filePath = PathUtility.Combine(_fileCache.RootPath, fileEntry.FileName);
+ var cacheEntry = new BuiltinFileCacheEntry(fileEntry.BundleGUID, filePath);
+ _fileCache.AddEntry(fileEntry.BundleGUID, cacheEntry);
}
+
+ _steps = ESteps.Done;
+ Status = EOperationStatus.Succeeded;
}
}
}
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/Operations/BFCLoadBundleOperation.cs b/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/Operations/BFCLoadBundleOperation.cs
index bc45ba6f..0a428dae 100644
--- a/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/Operations/BFCLoadBundleOperation.cs
+++ b/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/Operations/BFCLoadBundleOperation.cs
@@ -1,6 +1,9 @@
-
+
namespace YooAsset
{
+ ///
+ /// 内置文件缓存加载 AssetBundle 操作
+ ///
internal class BFCLoadAssetBundleOperation : FCLoadBundleOperation
{
private enum ESteps
@@ -38,7 +41,7 @@ namespace YooAsset
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
- Error = $"Not found file cache entry: {_bundle.BundleGUID}";
+ Error = $"File cache entry not found: {_bundle.BundleGUID}";
}
else
{
@@ -54,7 +57,7 @@ namespace YooAsset
options.CacheName = _fileCache.GetType().Name;
options.Bundle = _bundle;
options.FilePath = _cacheEntry.FilePath;
- options.Decryptor = _fileCache.Config.AssetBundleDecryptor;
+ options.AssetBundleDecryptor = _fileCache.Config.AssetBundleDecryptor;
_loadLocalAssetBundleOp = new LoadLocalAssetBundleOperation(options);
_loadLocalAssetBundleOp.StartOperation();
AddChildOperation(_loadLocalAssetBundleOp);
@@ -70,7 +73,7 @@ namespace YooAsset
if (_loadLocalAssetBundleOp.Status == EOperationStatus.Succeeded)
{
if (_loadLocalAssetBundleOp.BundleResult == null)
- throw new YooInternalException("Loaded asset bundle result is null.");
+ throw new YooInternalException("Loaded bundle result is null.");
_steps = ESteps.Done;
Status = EOperationStatus.Succeeded;
@@ -90,6 +93,9 @@ namespace YooAsset
}
}
+ ///
+ /// 内置文件缓存加载 RawBundle 操作
+ ///
internal class BFCLoadRawBundleOperation : FCLoadBundleOperation
{
private enum ESteps
@@ -127,7 +133,7 @@ namespace YooAsset
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
- Error = $"Not found file cache entry: {_bundle.BundleGUID}";
+ Error = $"File cache entry not found: {_bundle.BundleGUID}";
}
else
{
@@ -143,7 +149,7 @@ namespace YooAsset
options.CacheName = _fileCache.GetType().Name;
options.Bundle = _bundle;
options.FilePath = _cacheEntry.FilePath;
- options.Decryptor = _fileCache.Config.AssetBundleDecryptor;
+ options.RawBundleDecryptor = _fileCache.Config.RawBundleDecryptor;
_loadLocalRawBundleOp = new LoadLocalRawBundleOperation(options);
_loadLocalRawBundleOp.StartOperation();
AddChildOperation(_loadLocalRawBundleOp);
@@ -159,8 +165,10 @@ namespace YooAsset
if(_loadLocalRawBundleOp.Status == EOperationStatus.Succeeded)
{
if (_loadLocalRawBundleOp.BundleResult == null)
- throw new YooInternalException("Loaded raw bundle result is null.");
+ throw new YooInternalException("Loaded bundle result is null.");
+ _steps = ESteps.Done;
+ Status = EOperationStatus.Succeeded;
BundleResult = _loadLocalRawBundleOp.BundleResult;
}
else
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/Operations/Internal/LoadBuiltinCatalogFileOperation.cs b/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/Operations/Internal/LoadBuiltinCatalogFileOperation.cs
deleted file mode 100644
index 91b4e78d..00000000
--- a/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/Operations/Internal/LoadBuiltinCatalogFileOperation.cs
+++ /dev/null
@@ -1,112 +0,0 @@
-using System;
-using System.IO;
-
-namespace YooAsset
-{
- internal sealed class LoadBuiltinCatalogFileOperation : AsyncOperationBase
- {
- private enum ESteps
- {
- None,
- TryLoadFileData,
- RequestFileData,
- LoadCatalog,
- CheckResut,
- Done,
- }
-
- private readonly BuiltinFileCache _fileCache;
- private IDownloadBytesRequest _webDataRequestOp;
- private byte[] _fileData;
- private ESteps _steps = ESteps.None;
-
- ///
- /// 内置资源目录
- ///
- public BuiltinFileCatalog Catalog;
-
- internal LoadBuiltinCatalogFileOperation(BuiltinFileCache fileCache)
- {
- _fileCache = fileCache;
- }
- internal override void InternalStart()
- {
- _steps = ESteps.TryLoadFileData;
- }
- internal override void InternalUpdate()
- {
- if (_steps == ESteps.None || _steps == ESteps.Done)
- return;
-
- if (_steps == ESteps.TryLoadFileData)
- {
- string filePath = _fileCache.GetCatalogBinaryFileLoadPath();
- if (File.Exists(filePath))
- {
- _fileData = File.ReadAllBytes(filePath);
- _steps = ESteps.LoadCatalog;
- }
- else
- {
- _steps = ESteps.RequestFileData;
- }
- }
-
- if (_steps == ESteps.RequestFileData)
- {
- if (_webDataRequestOp == null)
- {
- string filePath = _fileCache.GetCatalogBinaryFileLoadPath();
- string url = DownloadSystemTools.ToLocalUrl(filePath);
- var args = new DownloadDataRequestArgs(url, 60, 0);
- _webDataRequestOp = _fileCache.Config.DownloadBackend.CreateBytesRequest(args);
- _webDataRequestOp.SendRequest();
- }
-
- if (_webDataRequestOp.IsDone == false)
- return;
-
- if (_webDataRequestOp.Status == EDownloadRequestStatus.Succeeded)
- {
- _fileData = _webDataRequestOp.Result;
- _steps = ESteps.LoadCatalog;
- }
- else
- {
- _steps = ESteps.Done;
- Status = EOperationStatus.Failed;
- Error = _webDataRequestOp.Error;
- }
- }
-
- if (_steps == ESteps.LoadCatalog)
- {
- try
- {
- Catalog = BuiltinFileCatalogTools.DeserializeFromBinary(_fileData);
- _steps = ESteps.CheckResut;
- }
- catch (Exception ex)
- {
- _steps = ESteps.Done;
- Status = EOperationStatus.Failed;
- Error = $"Failed to load catalog file : {ex.Message}";
- }
- }
-
- if (_steps == ESteps.CheckResut)
- {
- if (Catalog.PackageName != _fileCache.PackageName)
- {
- _steps = ESteps.Done;
- Status = EOperationStatus.Failed;
- Error = $"Catalog file package name {Catalog.PackageName} cannot match the file cache package name {_fileCache.PackageName}";
- return;
- }
-
- _steps = ESteps.Done;
- Status = EOperationStatus.Succeeded;
- }
- }
- }
-}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/EditorFileCache.cs b/Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/EditorFileCache.cs
index 7897e1d0..49f62d0b 100644
--- a/Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/EditorFileCache.cs
+++ b/Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/EditorFileCache.cs
@@ -1,21 +1,44 @@
-using System;
+using System;
using System.Collections.Generic;
namespace YooAsset
{
+ ///
+ /// 编辑器文件缓存系统,用于编辑器模式下的资源模拟加载
+ ///
internal class EditorFileCache : IFileCache
{
+ ///
+ /// 编辑器文件缓存配置
+ ///
internal struct CacheConfig
{
+ ///
+ /// 虚拟下载模式,模拟资源下载流程
+ ///
public bool VirtualDownloadMode { get; set; }
+
+ ///
+ /// 虚拟WebGL模式
+ ///
public bool VirtualWebGLMode { get; set; }
+
+ ///
+ /// 异步模拟最小帧数
+ ///
public int AsyncSimulateMinFrame { get; set; }
+
+ ///
+ /// 异步模拟最大帧数
+ ///
public int AsyncSimulateMaxFrame { get; set; }
}
- private readonly Dictionary _caches = new Dictionary(10000);
+ private readonly Dictionary _cacheEntries = new Dictionary(10000);
- // 缓存配置
+ ///
+ /// 缓存配置
+ ///
internal readonly CacheConfig Config;
#region 接口属性
@@ -41,7 +64,7 @@ namespace YooAsset
{
get
{
- return _caches.Count;
+ return _cacheEntries.Count;
}
}
@@ -52,6 +75,12 @@ namespace YooAsset
public long SpaceOccupied { get; private set; }
#endregion
+ ///
+ /// 创建编辑器文件缓存系统实例
+ ///
+ /// 包裹名称
+ /// 缓存根目录
+ /// 缓存配置
public EditorFileCache(string packageName, string rootPath, CacheConfig config)
{
PackageName = packageName;
@@ -67,7 +96,7 @@ namespace YooAsset
var operation = new EFCInitializeOperation(this);
return operation;
}
- public virtual FCWriteCacheOperation WriteCacheAsync(WriteCacheOptions options)
+ public virtual FCWriteCacheOperation WriteCacheAsync(FCWriteCacheOptions options)
{
var operation = new EFCWriteCacheOperation(this, options);
return operation;
@@ -77,16 +106,16 @@ namespace YooAsset
var operation = new FCClearCacheCompleteOperation();
return operation;
}
- public virtual FCVerifyCacheOperation VerifyCacheAsync(VerifyCacheOptions options)
+ public virtual FCVerifyCacheOperation VerifyCacheAsync(FCVerifyCacheOptions options)
{
var operation = new FCVerifyCacheCompleteOperation();
return operation;
}
- public virtual FCLoadBundleOperation LoadBundleAsync(LoadBundleOptions options)
+ public virtual FCLoadBundleOperation LoadBundleAsync(FCLoadBundleOptions options)
{
if (options.Bundle.BundleType == (int)EBundleType.VirtualBundle)
{
- var operation = new EFCLoadVirtualBundleOperation(this, options.Bundle);
+ var operation = new EFCLoadBundleOperation(this, options.Bundle);
return operation;
}
else
@@ -99,32 +128,21 @@ namespace YooAsset
public virtual bool IsCached(string bundleGUID)
{
if (Config.VirtualDownloadMode)
- return _caches.ContainsKey(bundleGUID);
+ return _cacheEntries.ContainsKey(bundleGUID);
else
return true;
}
#region 内部方法
- ///
- /// 获取指定缓存
- ///
- public EditorFileCacheEntry GetEntry(string bundleGUID)
- {
- if (_caches.TryGetValue(bundleGUID, out EditorFileCacheEntry entry))
- return entry;
- else
- return null;
- }
-
///
/// 添加指定缓存
///
- internal void AddEntry(string bundleGUID, EditorFileCacheEntry entry)
+ internal void AddEntry(string bundleGUID, EditorFileCacheEntry cacheEntry)
{
- if (_caches.ContainsKey(bundleGUID))
- throw new YooInternalException($"Cache entry already existed: {bundleGUID}");
+ if (_cacheEntries.ContainsKey(bundleGUID))
+ throw new YooInternalException($"Cache entry already exists: {bundleGUID}");
- _caches.Add(bundleGUID, entry);
+ _cacheEntries.Add(bundleGUID, cacheEntry);
}
#endregion
}
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/EditorFileCacheEntry.cs b/Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/EditorFileCacheEntry.cs
index ca55410a..55fcc890 100644
--- a/Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/EditorFileCacheEntry.cs
+++ b/Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/EditorFileCacheEntry.cs
@@ -1,11 +1,26 @@
-
+
namespace YooAsset
{
+ ///
+ /// 编辑器文件缓存条目
+ ///
internal class EditorFileCacheEntry : ICacheEntry
{
+ ///
+ /// 资源包唯一标识
+ ///
public string BundleGUID { get; private set; }
+
+ ///
+ /// 资源包文件路径
+ ///
public string FilePath { get; private set; }
+ ///
+ /// 创建编辑器文件缓存条目
+ ///
+ /// 资源包唯一标识
+ /// 资源包文件路径
public EditorFileCacheEntry(string bundleGUID, string filePath)
{
BundleGUID = bundleGUID;
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/Operations/EFCInitializeOperation.cs b/Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/Operations/EFCInitializeOperation.cs
index 93199391..615e92f9 100644
--- a/Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/Operations/EFCInitializeOperation.cs
+++ b/Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/Operations/EFCInitializeOperation.cs
@@ -1,6 +1,9 @@
-
+
namespace YooAsset
{
+ ///
+ /// 编辑器文件缓存初始化操作
+ ///
internal class EFCInitializeOperation : FCInitializeOperation
{
private readonly EditorFileCache _fileCache;
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/Operations/EFCLoadBundleOperation.cs b/Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/Operations/EFCLoadBundleOperation.cs
index 201a55ad..3852cd46 100644
--- a/Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/Operations/EFCLoadBundleOperation.cs
+++ b/Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/Operations/EFCLoadBundleOperation.cs
@@ -1,13 +1,16 @@
-
+
namespace YooAsset
{
- internal class EFCLoadVirtualBundleOperation : FCLoadBundleOperation
+ ///
+ /// 编辑器文件缓存加载资源包操作
+ ///
+ internal class EFCLoadBundleOperation : FCLoadBundleOperation
{
private enum ESteps
{
None,
- LoadVirtualBundle,
- CheckResult,
+ CheckCache,
+ LoadBundle,
Done,
}
@@ -16,14 +19,14 @@ namespace YooAsset
private int _asyncSimulateFrame;
private ESteps _steps = ESteps.None;
- public EFCLoadVirtualBundleOperation(EditorFileCache fileCache, PackageBundle bundle)
+ public EFCLoadBundleOperation(EditorFileCache fileCache, PackageBundle bundle)
{
_fileCache = fileCache;
_bundle = bundle;
}
internal override void InternalStart()
{
- _steps = ESteps.LoadVirtualBundle;
+ _steps = ESteps.CheckCache;
_asyncSimulateFrame = GetAsyncSimulateFrame();
}
internal override void InternalUpdate()
@@ -31,21 +34,20 @@ namespace YooAsset
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
- if (_steps == ESteps.LoadVirtualBundle)
+ if (_steps == ESteps.CheckCache)
{
- var entry = _fileCache.GetEntry(_bundle.BundleGUID);
- if (entry == null)
+ if (_fileCache.IsCached(_bundle.BundleGUID) == false)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
- Error = $"Not found file cache entry: {_bundle.BundleGUID}";
+ Error = $"File cache entry not found: {_bundle.BundleGUID}";
return;
}
- _steps = ESteps.CheckResult;
+ _steps = ESteps.LoadBundle;
}
- if (_steps == ESteps.CheckResult)
+ if (_steps == ESteps.LoadBundle)
{
if (IsWaitForCompletion)
{
@@ -53,12 +55,15 @@ namespace YooAsset
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
- Error = "WebGL mode only support asyn load method.";
+ Error = "WebGL mode only supports async load method.";
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeeded;
+
+ string editorFilePath = EditorFileSystemTools.GetEditorFilePath(_bundle);
+ BundleResult = new VirtualBundleResult(editorFilePath, _bundle);
}
}
else
@@ -68,6 +73,9 @@ namespace YooAsset
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeeded;
+
+ string editorFilePath = EditorFileSystemTools.GetEditorFilePath(_bundle);
+ BundleResult = new VirtualBundleResult(editorFilePath, _bundle);
}
}
}
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/Operations/EFCWriteCacheOperation.cs b/Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/Operations/EFCWriteCacheOperation.cs
index d5461630..75a2f422 100644
--- a/Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/Operations/EFCWriteCacheOperation.cs
+++ b/Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/Operations/EFCWriteCacheOperation.cs
@@ -1,43 +1,44 @@
-using System;
-using System.IO;
namespace YooAsset
{
+ ///
+ /// 编辑器文件缓存写入操作
+ ///
internal class EFCWriteCacheOperation : FCWriteCacheOperation
{
private enum ESteps
{
None,
- Check,
+ CheckCache,
CacheFile,
Done,
}
- private readonly EditorFileCache _cache;
- private readonly WriteCacheOptions _options;
+ private readonly EditorFileCache _fileCache;
+ private readonly FCWriteCacheOptions _options;
private ESteps _steps = ESteps.None;
- public EFCWriteCacheOperation(EditorFileCache cache, WriteCacheOptions options)
+ public EFCWriteCacheOperation(EditorFileCache cache, FCWriteCacheOptions options)
{
- _cache = cache;
+ _fileCache = cache;
_options = options;
}
internal override void InternalStart()
{
- _steps = ESteps.Check;
+ _steps = ESteps.CheckCache;
}
internal override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
- if (_steps == ESteps.Check)
+ if (_steps == ESteps.CheckCache)
{
- if (_cache.IsCached(_options.Bundle.BundleGUID))
+ if (_fileCache.IsCached(_options.Bundle.BundleGUID))
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
- Error = "The bundle is cached.";
+ Error = "The bundle is already cached.";
}
else
{
@@ -48,7 +49,7 @@ namespace YooAsset
if (_steps == ESteps.CacheFile)
{
var cacheEntry = new EditorFileCacheEntry(_options.Bundle.BundleGUID, _options.FilePath);
- _cache.AddEntry(_options.Bundle.BundleGUID, cacheEntry);
+ _fileCache.AddEntry(_options.Bundle.BundleGUID, cacheEntry);
_steps = ESteps.Done;
Status = EOperationStatus.Succeeded;
}
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/EFileVerifyResult.cs b/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/EFileVerifyResult.cs
index 12b9ad19..1d48c022 100644
--- a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/EFileVerifyResult.cs
+++ b/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/EFileVerifyResult.cs
@@ -9,8 +9,13 @@ namespace YooAsset
///
/// 验证异常
///
- Exception = -7,
+ Exception = -8,
+ ///
+ /// 数据无效
+ ///
+ BytesDataInvalid = -7,
+
///
/// 未找到缓存信息
///
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/FileVerifyTools.cs b/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/FileVerifyTools.cs
index e262573d..fa9bc207 100644
--- a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/FileVerifyTools.cs
+++ b/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/FileVerifyTools.cs
@@ -1,13 +1,20 @@
-using System;
+using System;
using System.IO;
namespace YooAsset
{
+ ///
+ /// 文件校验工具类
+ ///
internal class FileVerifyTools
{
///
- /// 文件校验
+ /// 校验文件完整性
///
+ /// 文件路径
+ /// 期望的文件大小
+ /// 期望的文件CRC值
+ /// 校验结果
public static EFileVerifyResult FileVerify(string filePath, long fileSize, uint fileCRC)
{
try
@@ -15,7 +22,7 @@ namespace YooAsset
if (File.Exists(filePath) == false)
return EFileVerifyResult.DataFileNotExisted;
- // 验证文件大小
+ // 可选条件:验证文件大小
if (fileSize > 0)
{
long size = FileUtility.GetFileSize(filePath);
@@ -25,7 +32,7 @@ namespace YooAsset
return EFileVerifyResult.FileOverflow;
}
- // 验证文件CRC
+ // 可选条件:验证文件CRC
if (fileCRC > 0)
{
uint crc = HashUtility.ComputeFileCRC32AsUInt(filePath);
@@ -41,7 +48,52 @@ namespace YooAsset
}
catch (Exception ex)
{
- YooLogger.Error($"File verify exception : {ex.Message}");
+ YooLogger.Error($"File verification exception: {ex.Message}");
+ return EFileVerifyResult.Exception;
+ }
+ }
+
+ ///
+ /// 校验文件完整性
+ ///
+ /// 文件数据
+ /// 期望的文件大小
+ /// 期望的文件CRC值
+ /// 校验结果
+ public static EFileVerifyResult FileVerify(byte[] fileData, long fileSize, uint fileCRC)
+ {
+ try
+ {
+ if (fileData == null || fileData.Length == 0)
+ return EFileVerifyResult.BytesDataInvalid;
+
+ // 可选条件:验证文件大小
+ if (fileSize > 0)
+ {
+ long size = fileData.Length;
+ if (size < fileSize)
+ return EFileVerifyResult.FileNotComplete;
+ else if (size > fileSize)
+ return EFileVerifyResult.FileOverflow;
+ }
+
+ // 可选条件:验证文件CRC
+ if (fileCRC > 0)
+ {
+ uint crc = HashUtility.ComputeBytesCRC32AsUInt(fileData);
+ if (crc == fileCRC)
+ return EFileVerifyResult.Succeed;
+ else
+ return EFileVerifyResult.FileCrcError;
+ }
+ else
+ {
+ return EFileVerifyResult.Succeed;
+ }
+ }
+ catch (Exception ex)
+ {
+ YooLogger.Error($"File verification exception: {ex.Message}");
return EFileVerifyResult.Exception;
}
}
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/Internal/ClearCacheFilesOperation.cs b/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/Internal/ClearCacheFilesOperation.cs
index 3cf17ccb..9d156836 100644
--- a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/Internal/ClearCacheFilesOperation.cs
+++ b/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/Internal/ClearCacheFilesOperation.cs
@@ -1,9 +1,11 @@
-using System.Collections.Generic;
-using System.Linq;
+using System.Collections.Generic;
namespace YooAsset
{
- internal class ClearCacheFilesOperation : FCClearCacheOperation
+ ///
+ /// 清理缓存文件操作
+ ///
+ internal class ClearCacheFilesOperation : AsyncOperationBase
{
private enum ESteps
{
@@ -13,14 +15,14 @@ namespace YooAsset
Done,
}
- private readonly SandboxFileCache _cache;
+ private readonly SandboxFileCache _fileCache;
private readonly List _bundleGUIDs;
- private int _clearFileTotalCount;
+ private int _fileTotalCount;
private ESteps _steps = ESteps.None;
- public ClearCacheFilesOperation(SandboxFileCache cache, List bundleGUIDs)
+ public ClearCacheFilesOperation(SandboxFileCache fileCache, List bundleGUIDs)
{
- _cache = cache;
+ _fileCache = fileCache;
_bundleGUIDs = bundleGUIDs;
}
internal override void InternalStart()
@@ -41,7 +43,7 @@ namespace YooAsset
return;
}
- _clearFileTotalCount = _bundleGUIDs.Count;
+ _fileTotalCount = _bundleGUIDs.Count;
_steps = ESteps.ClearCache;
}
@@ -50,16 +52,16 @@ namespace YooAsset
for (int i = _bundleGUIDs.Count - 1; i >= 0; i--)
{
string bundleGUID = _bundleGUIDs[i];
- _cache.RemoveEntry(bundleGUID);
+ _fileCache.RemoveEntry(bundleGUID);
_bundleGUIDs.RemoveAt(i);
if (IsBusy)
break;
}
- if (_clearFileTotalCount == 0)
+ if (_fileTotalCount == 0)
Progress = 1.0f;
else
- Progress = 1.0f - ((float)_bundleGUIDs.Count / _clearFileTotalCount);
+ Progress = 1.0f - ((float)_bundleGUIDs.Count / _fileTotalCount);
if (_bundleGUIDs.Count == 0)
{
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/Internal/SearchCacheFilesOperation.cs b/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/Internal/SearchCacheFilesOperation.cs
index 0a83f9c9..4b929dba 100644
--- a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/Internal/SearchCacheFilesOperation.cs
+++ b/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/Internal/SearchCacheFilesOperation.cs
@@ -1,11 +1,13 @@
-using System;
+using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
-using System.Linq;
namespace YooAsset
{
+ ///
+ /// 搜索缓存文件操作,扫描缓存目录中的文件
+ ///
internal sealed class SearchCacheFilesOperation : AsyncOperationBase
{
private enum ESteps
@@ -16,7 +18,7 @@ namespace YooAsset
Done,
}
- private readonly SandboxFileCache _cache;
+ private readonly SandboxFileCache _fileCache;
private IEnumerator _filesEnumerator = null;
private double _verifyStartTime;
private ESteps _steps = ESteps.None;
@@ -24,12 +26,12 @@ namespace YooAsset
///
/// 需要验证的元素
///
- public readonly List Result = new List(5000);
+ public readonly List Result = new List(5000);
- internal SearchCacheFilesOperation(SandboxFileCache cache)
+ internal SearchCacheFilesOperation(SandboxFileCache fileCache)
{
- _cache = cache;
+ _fileCache = fileCache;
}
internal override void InternalStart()
{
@@ -42,9 +44,9 @@ namespace YooAsset
if (_steps == ESteps.Prepare)
{
- if (Directory.Exists(_cache.RootPath))
+ if (Directory.Exists(_fileCache.RootPath))
{
- var directories = Directory.EnumerateDirectories(_cache.RootPath);
+ var directories = Directory.EnumerateDirectories(_fileCache.RootPath);
_filesEnumerator = directories.GetEnumerator();
_verifyStartTime = TimeUtility.RealtimeSinceStartup;
_steps = ESteps.SearchFiles;
@@ -80,19 +82,19 @@ namespace YooAsset
if (isFindItem == false)
break;
- var rootFoder = _filesEnumerator.Current;
- var childDirectories = Directory.EnumerateDirectories(rootFoder);
- foreach (var chidDirectory in childDirectories)
+ var rootFolder = _filesEnumerator.Current;
+ var childDirectories = Directory.EnumerateDirectories(rootFolder);
+ foreach (var childDirectory in childDirectories)
{
- string bundleGUID = Path.GetFileName(chidDirectory);
- if (_cache.IsCached(bundleGUID))
+ string bundleGUID = Path.GetFileName(childDirectory);
+ if (_fileCache.IsCached(bundleGUID))
continue;
// 创建验证元素类
- string fileRootPath = chidDirectory;
+ string fileRootPath = childDirectory;
string dataFilePath = PathUtility.Combine(fileRootPath, SandboxFileCacheDefine.BundleDataFileName);
string infoFilePath = PathUtility.Combine(fileRootPath, SandboxFileCacheDefine.BundleInfoFileName);
- var element = new VerifyFileInfo(bundleGUID, fileRootPath, dataFilePath, infoFilePath);
+ var element = new SearchFileInfo(bundleGUID, fileRootPath, dataFilePath, infoFilePath);
Result.Add(element);
}
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/Internal/VerifyCacheFilesOperation.cs b/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/Internal/VerifyCacheFilesOperation.cs
index 10233ea5..f934c5de 100644
--- a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/Internal/VerifyCacheFilesOperation.cs
+++ b/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/Internal/VerifyCacheFilesOperation.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
@@ -7,7 +7,7 @@ using System.Threading;
namespace YooAsset
{
///
- /// 缓存文件验证(线程版)
+ /// 缓存文件验证(线程版),验证缓存目录中的文件
///
internal sealed class VerifyCacheFilesOperation : AsyncOperationBase
{
@@ -19,25 +19,25 @@ namespace YooAsset
Done,
}
- private readonly SandboxFileCache _cache;
+ private readonly SandboxFileCache _fileCache;
private readonly EFileVerifyLevel _verifyLevel;
private readonly int _fileVerifyMaxConcurrency;
- private readonly List _waitingList;
- private List _verifyingList;
- private int _verifyMaxNum;
+ private readonly List _pendingVerifyList;
+ private List _activeVerifyList;
+ private int _maxConcurrentVerifyCount;
private int _verifyTotalCount;
private double _verifyStartTime;
- private int _succeedCount;
+ private int _successCount;
private int _failedCount;
private ESteps _steps = ESteps.None;
- internal VerifyCacheFilesOperation(SandboxFileCache cache, EFileVerifyLevel verifyLevel, int fileVerifyMaxConcurrency, List elements)
+ internal VerifyCacheFilesOperation(SandboxFileCache fileCache, EFileVerifyLevel verifyLevel, int fileVerifyMaxConcurrency, List elements)
{
- _cache = cache;
+ _fileCache = fileCache;
_verifyLevel = verifyLevel;
_fileVerifyMaxConcurrency = fileVerifyMaxConcurrency;
- _waitingList = elements;
+ _pendingVerifyList = elements;
}
internal override void InternalStart()
{
@@ -52,44 +52,44 @@ namespace YooAsset
{
// 设置同时验证的最大数
int processorCount = Environment.ProcessorCount * 2 + 1;
- _verifyMaxNum = Math.Min(processorCount, _fileVerifyMaxConcurrency);
- if (_verifyMaxNum < 1)
- _verifyMaxNum = 1;
+ _maxConcurrentVerifyCount = Math.Min(processorCount, _fileVerifyMaxConcurrency);
+ if (_maxConcurrentVerifyCount < 1)
+ _maxConcurrentVerifyCount = 1;
- YooLogger.Log($"Verify max concurrency : {_verifyMaxNum}");
- _verifyingList = new List(_verifyMaxNum);
+ YooLogger.Log($"Verify max concurrency : {_maxConcurrentVerifyCount}");
+ _activeVerifyList = new List(_maxConcurrentVerifyCount);
_verifyStartTime = TimeUtility.RealtimeSinceStartup;
- _verifyTotalCount = _waitingList.Count;
+ _verifyTotalCount = _pendingVerifyList.Count;
_steps = ESteps.UpdateVerify;
}
if (_steps == ESteps.UpdateVerify)
{
// 检测校验结果
- for (int i = _verifyingList.Count - 1; i >= 0; i--)
+ for (int i = _activeVerifyList.Count - 1; i >= 0; i--)
{
- var verifyElement = _verifyingList[i];
- int result = verifyElement.Result;
- if (result != 0)
+ var verifyElement = _activeVerifyList[i];
+ int resultCode = verifyElement.VerifyResultCode; //注意: 一次命令取值
+ if (resultCode != 0)
{
- _verifyingList.RemoveAt(i);
- if (verifyElement.Result == (int)EFileVerifyResult.Succeed)
+ _activeVerifyList.RemoveAt(i);
+ if (resultCode == (int)EFileVerifyResult.Succeed)
{
- _succeedCount++;
+ _successCount++;
var cacheEntry = new SandboxFileCacheEntry(verifyElement.BundleGUID, verifyElement.InfoFilePath, verifyElement.DataFilePath);
- _cache.AddEntry(verifyElement.BundleGUID, cacheEntry);
+ _fileCache.AddEntry(verifyElement.BundleGUID, cacheEntry);
}
else
{
_failedCount++;
- YooLogger.Warning($"Failed to verify file {verifyElement.Result} and delete files : {verifyElement.FolderPath}");
- verifyElement.DeleteFiles();
+ YooLogger.Warning($"File verification failed (code: {verifyElement.VerifyResultCode}). Deleting files: {verifyElement.FolderPath}");
+ verifyElement.DeleteCacheFolder();
}
}
}
Progress = GetProgress();
- if (_waitingList.Count == 0 && _verifyingList.Count == 0)
+ if (_pendingVerifyList.Count == 0 && _activeVerifyList.Count == 0)
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeeded;
@@ -97,21 +97,21 @@ namespace YooAsset
YooLogger.Log($"Verify cache files elapsed time {costTime:f1} seconds");
}
- for (int i = _waitingList.Count - 1; i >= 0; i--)
+ for (int i = _pendingVerifyList.Count - 1; i >= 0; i--)
{
if (IsBusy)
break;
- if (_verifyingList.Count >= _verifyMaxNum)
+ if (_activeVerifyList.Count >= _maxConcurrentVerifyCount)
break;
- var element = _waitingList[i];
+ var element = _pendingVerifyList[i];
bool succeed = ThreadPool.QueueUserWorkItem(new WaitCallback(VerifyFileInThread), element);
if (succeed == false)
VerifyFileInThread(element);
- _waitingList.RemoveAt(i);
- _verifyingList.Add(element);
+ _pendingVerifyList.RemoveAt(i);
+ _activeVerifyList.Add(element);
}
}
}
@@ -119,17 +119,17 @@ namespace YooAsset
{
if (_verifyTotalCount == 0)
return 1f;
- return (float)(_succeedCount + _failedCount) / _verifyTotalCount;
+ return (float)(_successCount + _failedCount) / _verifyTotalCount;
}
// 验证缓存文件(子线程内操作)
private void VerifyFileInThread(object obj)
{
- VerifyFileInfo element = (VerifyFileInfo)obj;
- int verifyResult = (int)VerifyFile(element, _verifyLevel);
- element.Result = verifyResult;
+ SearchFileInfo element = (SearchFileInfo)obj;
+ int verifyResultCode = (int)VerifyFile(element, _verifyLevel);
+ element.VerifyResultCode = verifyResultCode; //注意: 一次命令赋值
}
- private EFileVerifyResult VerifyFile(VerifyFileInfo element, EFileVerifyLevel verifyLevel)
+ private EFileVerifyResult VerifyFile(SearchFileInfo element, EFileVerifyLevel verifyLevel)
{
try
{
@@ -145,7 +145,6 @@ namespace YooAsset
else
{
// 解析信息文件填充验证数据
- // 注意:验证数据在后续流程会被使用。
byte[] binaryData = FileUtility.ReadAllBytes(element.InfoFilePath);
BufferReader buffer = new BufferReader(binaryData);
uint dataFileCRC = buffer.ReadUInt32();
@@ -161,7 +160,7 @@ namespace YooAsset
}
catch (Exception ex)
{
- YooLogger.Error($"File verify exception : {ex.Message}");
+ YooLogger.Error($"File verification exception: {ex.Message}");
return EFileVerifyResult.Exception;
}
}
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/Internal/VerifyTempFileOperation.cs b/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/Internal/VerifyTempFileOperation.cs
index 2c5dc358..cfd4c6e0 100644
--- a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/Internal/VerifyTempFileOperation.cs
+++ b/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/Internal/VerifyTempFileOperation.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.Threading;
namespace YooAsset
@@ -49,11 +49,11 @@ namespace YooAsset
if (_steps == ESteps.Waiting)
{
- int result = _element.Result;
- if (result == 0)
+ int resultCode = _element.VerifyResultCode; //注意: 一次命令取值
+ if (resultCode == 0)
return;
- VerifyResult = (EFileVerifyResult)result;
+ VerifyResult = (EFileVerifyResult)resultCode;
if (VerifyResult == EFileVerifyResult.Succeed)
{
_steps = ESteps.Done;
@@ -63,21 +63,21 @@ namespace YooAsset
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
- Error = $"Failed to verify file : {_element.TempFilePath} ErrorCode : {VerifyResult}";
+ Error = $"Failed to verify file: {_element.FilePath} ErrorCode: {VerifyResult}";
}
}
}
internal override void InternalWaitForCompletion()
{
- //TODO 等待子线程验证文件完毕,该操作会挂起主线程!
+ //注意: 等待子线程验证文件完毕,该操作会挂起主线程!
ExecuteUntilComplete();
}
private void VerifyFileInThread(object obj)
{
TempFileInfo element = (TempFileInfo)obj;
- int result = (int)FileVerifyTools.FileVerify(element.TempFilePath, element.TempFileSize, element.TempFileCRC);
- element.Result = result;
+ int resultCode = (int)FileVerifyTools.FileVerify(element.FilePath, element.FileSize, element.FileCRC);
+ element.VerifyResultCode = resultCode; //注意: 一次命令赋值
}
}
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/SFCClearCacheOperation.cs b/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/SFCClearCacheOperation.cs
index d234b5a3..97ceeb79 100644
--- a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/SFCClearCacheOperation.cs
+++ b/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/SFCClearCacheOperation.cs
@@ -77,6 +77,9 @@ namespace YooAsset
protected abstract bool ParseOptionsStep();
}
+ ///
+ /// 清理所有沙盒缓存操作
+ ///
internal sealed class SFCClearAllCacheOperation : SFCClearCacheOperation
{
internal SFCClearAllCacheOperation(SandboxFileCache fileCache, ClearCacheOptions options)
@@ -84,15 +87,18 @@ namespace YooAsset
protected override bool ParseOptionsStep()
{
- var allEntrys = _fileCache.GetAllEntries();
- _bundleGUIDs = new List(allEntrys.Count);
- foreach (var entry in allEntrys)
+ var allEntries = _fileCache.GetAllEntries();
+ _bundleGUIDs = new List(allEntries.Count);
+ foreach (var entry in allEntries)
{
_bundleGUIDs.Add(entry.BundleGUID);
}
return true;
}
}
+ ///
+ /// 清理未使用的沙盒缓存操作
+ ///
internal sealed class SFCClearUnusedCacheOperation : SFCClearCacheOperation
{
internal SFCClearUnusedCacheOperation(SandboxFileCache fileCache, ClearCacheOptions options)
@@ -104,13 +110,13 @@ namespace YooAsset
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
- Error = "Can not found active package manifest.";
+ Error = "Active package manifest not found.";
return false;
}
- var allEntrys = _fileCache.GetAllEntries();
- _bundleGUIDs = new List(allEntrys.Count);
- foreach (var entry in allEntrys)
+ var allEntries = _fileCache.GetAllEntries();
+ _bundleGUIDs = new List(allEntries.Count);
+ foreach (var entry in allEntries)
{
if (_options.Manifest.IsIncludeBundleFile(entry.BundleGUID) == false)
{
@@ -120,6 +126,9 @@ namespace YooAsset
return true;
}
}
+ ///
+ /// 按资源地址清理沙盒缓存操作
+ ///
internal sealed class SFCClearCacheByLocationsOperation : SFCClearCacheOperation
{
internal SFCClearCacheByLocationsOperation(SandboxFileCache fileCache, ClearCacheOptions options)
@@ -131,7 +140,7 @@ namespace YooAsset
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
- Error = "Can not found active package manifest.";
+ Error = "Active package manifest not found.";
return false;
}
@@ -154,7 +163,7 @@ namespace YooAsset
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
- Error = $"Invalid clear param : {_options.ClearParam.GetType().FullName}";
+ Error = $"Invalid clear param: {_options.ClearParam.GetType().FullName}";
return false;
}
@@ -171,6 +180,9 @@ namespace YooAsset
return true;
}
}
+ ///
+ /// 按标签清理沙盒缓存操作
+ ///
internal sealed class SFCClearCacheByTagsOperation : SFCClearCacheOperation
{
internal SFCClearCacheByTagsOperation(SandboxFileCache fileCache, ClearCacheOptions options)
@@ -182,7 +194,7 @@ namespace YooAsset
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
- Error = "Can not found active package manifest.";
+ Error = "Active package manifest not found.";
return false;
}
@@ -205,13 +217,13 @@ namespace YooAsset
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
- Error = $"Invalid clear param : {_options.ClearParam.GetType().FullName}";
+ Error = $"Invalid clear param: {_options.ClearParam.GetType().FullName}";
return false;
}
- var allEntrys = _fileCache.GetAllEntries();
- _bundleGUIDs = new List(allEntrys.Count);
- foreach (var entry in allEntrys)
+ var allEntries = _fileCache.GetAllEntries();
+ _bundleGUIDs = new List(allEntries.Count);
+ foreach (var entry in allEntries)
{
if (_options.Manifest.TryGetPackageBundleByBundleGUID(entry.BundleGUID, out PackageBundle bundle))
{
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/SFCInitializeOperation.cs b/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/SFCInitializeOperation.cs
index a0dfb23b..0f26501b 100644
--- a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/SFCInitializeOperation.cs
+++ b/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/SFCInitializeOperation.cs
@@ -1,6 +1,9 @@
-
+
namespace YooAsset
{
+ ///
+ /// 沙盒文件缓存初始化操作
+ ///
internal class SFCInitializeOperation : FCInitializeOperation
{
private enum ESteps
@@ -11,14 +14,14 @@ namespace YooAsset
Done,
}
- private readonly SandboxFileCache _cache;
+ private readonly SandboxFileCache _fileCache;
private SearchCacheFilesOperation _searchCacheFilesOp;
private VerifyCacheFilesOperation _verifyCacheFilesOp;
private ESteps _steps = ESteps.None;
- public SFCInitializeOperation(SandboxFileCache cache)
+ public SFCInitializeOperation(SandboxFileCache fileCache)
{
- _cache = cache;
+ _fileCache = fileCache;
}
internal override void InternalStart()
{
@@ -33,7 +36,7 @@ namespace YooAsset
{
if (_searchCacheFilesOp == null)
{
- _searchCacheFilesOp = new SearchCacheFilesOperation(_cache);
+ _searchCacheFilesOp = new SearchCacheFilesOperation(_fileCache);
_searchCacheFilesOp.StartOperation();
AddChildOperation(_searchCacheFilesOp);
}
@@ -43,14 +46,23 @@ namespace YooAsset
if (_searchCacheFilesOp.IsDone == false)
return;
- _steps = ESteps.VerifyCacheFiles;
+ if (_searchCacheFilesOp.Status == EOperationStatus.Succeeded)
+ {
+ _steps = ESteps.VerifyCacheFiles;
+ }
+ else
+ {
+ _steps = ESteps.Done;
+ Status = EOperationStatus.Failed;
+ Error = _searchCacheFilesOp.Error;
+ }
}
if (_steps == ESteps.VerifyCacheFiles)
{
if (_verifyCacheFilesOp == null)
{
- _verifyCacheFilesOp = new VerifyCacheFilesOperation(_cache, _cache.Config.FileVerifyLevel, _cache.Config.FileVerifyMaxConcurrency, _searchCacheFilesOp.Result);
+ _verifyCacheFilesOp = new VerifyCacheFilesOperation(_fileCache, _fileCache.Config.FileVerifyLevel, _fileCache.Config.FileVerifyMaxConcurrency, _searchCacheFilesOp.Result);
_verifyCacheFilesOp.StartOperation();
AddChildOperation(_verifyCacheFilesOp);
}
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/SFCLoadBundleOperation.cs b/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/SFCLoadBundleOperation.cs
index 2003575b..c7420487 100644
--- a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/SFCLoadBundleOperation.cs
+++ b/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/SFCLoadBundleOperation.cs
@@ -1,9 +1,12 @@
-using System;
+using System;
using System.IO;
using UnityEngine;
namespace YooAsset
{
+ ///
+ /// 沙盒文件缓存加载 AssetBundle 操作
+ ///
internal class SFCLoadAssetBundleOperation : FCLoadBundleOperation
{
private enum ESteps
@@ -44,7 +47,7 @@ namespace YooAsset
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
- Error = $"Not found file cache entry: {_bundle.BundleGUID}";
+ Error = $"File cache entry not found: {_bundle.BundleGUID}";
}
else
{
@@ -60,7 +63,7 @@ namespace YooAsset
options.CacheName = _fileCache.GetType().Name;
options.Bundle = _bundle;
options.FilePath = _cacheEntry.DataFilePath;
- options.Decryptor = _fileCache.Config.AssetBundleDecryptor;
+ options.AssetBundleDecryptor = _fileCache.Config.AssetBundleDecryptor;
_loadLocalAssetBundleOp = new LoadLocalAssetBundleOperation(options);
_loadLocalAssetBundleOp.StartOperation();
AddChildOperation(_loadLocalAssetBundleOp);
@@ -104,9 +107,9 @@ namespace YooAsset
// 说明:在AssetBundle文件加载失败的情况下,我们需要重新验证文件的完整性!
if (_verifyCacheOp == null)
{
- var options = new VerifyCacheOptions();
+ var options = new FCVerifyCacheOptions();
options.Bundle = _bundle;
- options.FailedDeleteCache = true;
+ options.DeleteCacheEntryOnFailure = true;
_verifyCacheOp = _fileCache.VerifyCacheAsync(options);
_verifyCacheOp.StartOperation();
AddChildOperation(_verifyCacheOp);
@@ -147,7 +150,7 @@ namespace YooAsset
return;
}
- assetBundle = FallbackLoadDecryptAssetBundle(_fileCache.Config.AssetBundleFallbackDecryptor);
+ assetBundle = FallbackLoadEncryptedAssetBundle(_fileCache.Config.AssetBundleFallbackDecryptor);
if (assetBundle == null)
{
_steps = ESteps.Done;
@@ -182,20 +185,21 @@ namespace YooAsset
private AssetBundle FallbackLoadAssetBundle()
{
byte[] fileData = FileUtility.ReadAllBytes(_cacheEntry.DataFilePath);
- if (fileData == null || fileData.Length == 0)
- return null;
return AssetBundle.LoadFromMemory(fileData);
}
- private AssetBundle FallbackLoadDecryptAssetBundle(IBundleMemoryDecryptor decryptor)
+ private AssetBundle FallbackLoadEncryptedAssetBundle(IBundleMemoryDecryptor decryptor)
{
var args = new BundleDecryptArgs();
args.Bundle = _bundle;
args.FilePath = _cacheEntry.DataFilePath;
- var binaryData = decryptor.GetDecryptData(args);
- return AssetBundle.LoadFromMemory(binaryData);
+ var fileData = decryptor.GetDecryptData(args);
+ return AssetBundle.LoadFromMemory(fileData);
}
}
+ ///
+ /// 沙盒文件缓存加载 RawBundle 操作
+ ///
internal class SFCLoadRawBundleOperation : FCLoadBundleOperation
{
private enum ESteps
@@ -234,7 +238,7 @@ namespace YooAsset
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
- Error = $"Not found file cache entry: {_bundle.BundleGUID}";
+ Error = $"File cache entry not found: {_bundle.BundleGUID}";
}
else
{
@@ -250,7 +254,7 @@ namespace YooAsset
options.CacheName = _fileCache.GetType().Name;
options.Bundle = _bundle;
options.FilePath = _cacheEntry.DataFilePath;
- options.Decryptor = _fileCache.Config.AssetBundleDecryptor;
+ options.RawBundleDecryptor = _fileCache.Config.RawBundleDecryptor;
_loadLocalRawBundleOp = new LoadLocalRawBundleOperation(options);
_loadLocalRawBundleOp.StartOperation();
AddChildOperation(_loadLocalRawBundleOp);
@@ -268,6 +272,8 @@ namespace YooAsset
if (_loadLocalRawBundleOp.BundleResult == null)
throw new YooInternalException("Loaded raw bundle result is null.");
+ _steps = ESteps.Done;
+ Status = EOperationStatus.Succeeded;
BundleResult = _loadLocalRawBundleOp.BundleResult;
}
else
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/SFCVerifyCacheOperation.cs b/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/SFCVerifyCacheOperation.cs
index 02d60e95..f31d8098 100644
--- a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/SFCVerifyCacheOperation.cs
+++ b/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/SFCVerifyCacheOperation.cs
@@ -1,6 +1,9 @@
-
+
namespace YooAsset
{
+ ///
+ /// 沙盒文件缓存验证操作
+ ///
internal class SFCVerifyCacheOperation : FCVerifyCacheOperation
{
private enum ESteps
@@ -12,11 +15,11 @@ namespace YooAsset
}
private readonly SandboxFileCache _fileCache;
- private readonly VerifyCacheOptions _options;
- private VerifyTempFileOperation _verifyOperation;
+ private readonly FCVerifyCacheOptions _options;
+ private VerifyTempFileOperation _verifyTempFileOp;
private ESteps _steps = ESteps.None;
- public SFCVerifyCacheOperation(SandboxFileCache cache, VerifyCacheOptions options)
+ public SFCVerifyCacheOperation(SandboxFileCache cache, FCVerifyCacheOptions options)
{
_fileCache = cache;
_options = options;
@@ -36,7 +39,7 @@ namespace YooAsset
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
- Error = "Not found cached bundle.";
+ Error = "Cached bundle not found.";
}
else
{
@@ -46,23 +49,23 @@ namespace YooAsset
if (_steps == ESteps.VerifyFile)
{
- if (_verifyOperation == null)
+ if (_verifyTempFileOp == null)
{
var entry = _fileCache.GetEntry(_options.Bundle.BundleGUID);
var element = new TempFileInfo(entry.DataFilePath, _options.Bundle.FileCRC, _options.Bundle.FileSize);
- _verifyOperation = new VerifyTempFileOperation(element);
- _verifyOperation.StartOperation();
- AddChildOperation(_verifyOperation);
+ _verifyTempFileOp = new VerifyTempFileOperation(element);
+ _verifyTempFileOp.StartOperation();
+ AddChildOperation(_verifyTempFileOp);
}
if (IsWaitForCompletion)
- _verifyOperation.WaitForCompletion();
+ _verifyTempFileOp.WaitForCompletion();
- _verifyOperation.UpdateOperation();
- if (_verifyOperation.IsDone == false)
+ _verifyTempFileOp.UpdateOperation();
+ if (_verifyTempFileOp.IsDone == false)
return;
- if (_verifyOperation.Status == EOperationStatus.Succeeded)
+ if (_verifyTempFileOp.Status == EOperationStatus.Succeeded)
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeeded;
@@ -71,11 +74,11 @@ namespace YooAsset
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
- Error = _verifyOperation.Error;
+ Error = _verifyTempFileOp.Error;
- if (_options.FailedDeleteCache)
+ if (_options.DeleteCacheEntryOnFailure)
{
- YooLogger.Error($"Find corrupted bundle file and remove cache entry : {_options.Bundle.BundleGUID}");
+ YooLogger.Error($"Found corrupted bundle file. Removing cache entry: {_options.Bundle.BundleGUID}");
_fileCache.RemoveEntry(_options.Bundle.BundleGUID);
}
}
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/SFCWriteCacheOperation.cs b/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/SFCWriteCacheOperation.cs
index a01c6205..b16aae7d 100644
--- a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/SFCWriteCacheOperation.cs
+++ b/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/SFCWriteCacheOperation.cs
@@ -3,6 +3,9 @@ using System.IO;
namespace YooAsset
{
+ ///
+ /// 沙盒文件缓存写入操作
+ ///
internal class SFCWriteCacheOperation : FCWriteCacheOperation
{
private enum ESteps
@@ -14,14 +17,14 @@ namespace YooAsset
Done,
}
- private readonly SandboxFileCache _cache;
- private readonly WriteCacheOptions _options;
- private VerifyTempFileOperation _verifyOperation;
+ private readonly SandboxFileCache _fileCache;
+ private readonly FCWriteCacheOptions _options;
+ private VerifyTempFileOperation _verifyTempFileOp;
private ESteps _steps = ESteps.None;
- public SFCWriteCacheOperation(SandboxFileCache cache, WriteCacheOptions options)
+ public SFCWriteCacheOperation(SandboxFileCache fileCache, FCWriteCacheOptions options)
{
- _cache = cache;
+ _fileCache = fileCache;
_options = options;
}
internal override void InternalStart()
@@ -35,11 +38,11 @@ namespace YooAsset
if (_steps == ESteps.Check)
{
- if (_cache.IsCached(_options.Bundle.BundleGUID))
+ if (_fileCache.IsCached(_options.Bundle.BundleGUID))
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
- Error = "The bundle is cached.";
+ Error = "The bundle is already cached.";
}
else
{
@@ -49,22 +52,22 @@ namespace YooAsset
if (_steps == ESteps.VerifyFile)
{
- if (_verifyOperation == null)
+ if (_verifyTempFileOp == null)
{
var element = new TempFileInfo(_options.FilePath, _options.Bundle.FileCRC, _options.Bundle.FileSize);
- _verifyOperation = new VerifyTempFileOperation(element);
- _verifyOperation.StartOperation();
- AddChildOperation(_verifyOperation);
+ _verifyTempFileOp = new VerifyTempFileOperation(element);
+ _verifyTempFileOp.StartOperation();
+ AddChildOperation(_verifyTempFileOp);
}
if (IsWaitForCompletion)
- _verifyOperation.WaitForCompletion();
+ _verifyTempFileOp.WaitForCompletion();
- _verifyOperation.UpdateOperation();
- if (_verifyOperation.IsDone == false)
+ _verifyTempFileOp.UpdateOperation();
+ if (_verifyTempFileOp.IsDone == false)
return;
- if (_verifyOperation.Status == EOperationStatus.Succeeded)
+ if (_verifyTempFileOp.Status == EOperationStatus.Succeeded)
{
_steps = ESteps.CacheFile;
}
@@ -72,37 +75,45 @@ namespace YooAsset
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
- Error = _verifyOperation.Error;
+ Error = _verifyTempFileOp.Error;
}
}
if (_steps == ESteps.CacheFile)
{
- string infoFilePath = _cache.GetInfoFilePath(_options.Bundle);
- string dataFilePath = _cache.GetDataFilePath(_options.Bundle);
+ string dataFilePath = _fileCache.GetDataFilePath(_options.Bundle);
+ string infoFilePath = _fileCache.GetInfoFilePath(_options.Bundle);
+ string dataTempPath = _fileCache.GetDataTempFilePath(_options.Bundle);
+ string infoTempPath = _fileCache.GetInfoTempFilePath(_options.Bundle);
try
{
- if (File.Exists(infoFilePath))
- File.Delete(infoFilePath);
- if (File.Exists(dataFilePath))
- File.Delete(dataFilePath);
-
- // 拷贝数据文件
+ // 阶段A:准备目标目录,清理可能存在的残留文件
FileUtility.EnsureFileDirectory(dataFilePath);
- FileInfo fileInfo = new FileInfo(_options.FilePath);
- fileInfo.CopyTo(dataFilePath, true);
+ DeleteFileSafely(dataTempPath);
+ DeleteFileSafely(infoTempPath);
- // 写入信息文件
- FileUtility.EnsureFileDirectory(infoFilePath);
- using (FileStream fs = new FileStream(infoFilePath, FileMode.Create, FileAccess.Write, FileShare.Read))
+ // 阶段B:写入临时文件
+ FileInfo fileInfo = new FileInfo(_options.FilePath);
+ fileInfo.CopyTo(dataTempPath, true);
+
+ using (FileStream fs = new FileStream(infoTempPath, FileMode.Create, FileAccess.Write, FileShare.Read))
{
- _cache.SharedBuffer.Clear();
- _cache.SharedBuffer.WriteUInt32(_options.Bundle.FileCRC);
- _cache.SharedBuffer.WriteInt64(_options.Bundle.FileSize);
- _cache.SharedBuffer.WriteToStream(fs);
+ var buffer = new BufferWriter(128);
+ buffer.WriteUInt32(_options.Bundle.FileCRC);
+ buffer.WriteInt64(_options.Bundle.FileSize);
+ buffer.WriteToStream(fs);
fs.Flush();
}
+
+ // 阶段C:原子提交
+ if (File.Exists(dataFilePath))
+ File.Delete(dataFilePath);
+ File.Move(dataTempPath, dataFilePath);
+
+ if (File.Exists(infoFilePath))
+ File.Delete(infoFilePath);
+ File.Move(infoTempPath, infoFilePath);
}
catch (Exception ex)
{
@@ -110,11 +121,16 @@ namespace YooAsset
Status = EOperationStatus.Failed;
Error = $"Failed to write cache file. Error: {ex.Message}";
YooLogger.Error(Error);
- return; //失败后直接返回
+
+ // 回滚:清理临时文件,正式文件不受影响
+ DeleteFileSafely(dataTempPath);
+ DeleteFileSafely(infoTempPath);
+ return;
}
+ // 阶段D:注册内存缓存条目
var cacheEntry = new SandboxFileCacheEntry(_options.Bundle.BundleGUID, infoFilePath, dataFilePath);
- _cache.AddEntry(_options.Bundle.BundleGUID, cacheEntry);
+ _fileCache.AddEntry(_options.Bundle.BundleGUID, cacheEntry);
_steps = ESteps.Done;
Status = EOperationStatus.Succeeded;
}
@@ -123,5 +139,18 @@ namespace YooAsset
{
ExecuteBatch();
}
+
+ private static void DeleteFileSafely(string filePath)
+ {
+ try
+ {
+ if (File.Exists(filePath))
+ File.Delete(filePath);
+ }
+ catch (Exception ex)
+ {
+ YooLogger.Warning($"Failed to delete file: {filePath} Error: {ex.Message}");
+ }
+ }
}
}
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/SandboxFileCache.cs b/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/SandboxFileCache.cs
index 529c3c14..86e0a19a 100644
--- a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/SandboxFileCache.cs
+++ b/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/SandboxFileCache.cs
@@ -3,8 +3,14 @@ using System.Collections.Generic;
namespace YooAsset
{
+ ///
+ /// 沙盒文件缓存系统,用于管理下载到本地的资源包缓存
+ ///
internal class SandboxFileCache : IFileCache
{
+ ///
+ /// 沙盒文件缓存配置
+ ///
internal struct CacheConfig
{
///
@@ -33,17 +39,16 @@ namespace YooAsset
public IBundleMemoryDecryptor AssetBundleFallbackDecryptor { get; set; }
}
- private const int HashFolderLength = 2;
- private readonly Dictionary _caches = new Dictionary(10000);
+ private const int HashFolderNameLength = 2;
+ private readonly Dictionary _cacheEntries = new Dictionary(10000);
private readonly Dictionary _dataFilePathMapping = new Dictionary(10000);
private readonly Dictionary _infoFilePathMapping = new Dictionary(10000);
- // 缓存配置
+ ///
+ /// 缓存配置
+ ///
internal readonly CacheConfig Config;
- // 共享缓冲区
- internal readonly BufferWriter SharedBuffer = new BufferWriter(1024);
-
#region 接口属性
///
/// 包裹名称
@@ -67,7 +72,7 @@ namespace YooAsset
{
get
{
- return _caches.Count;
+ return _cacheEntries.Count;
}
}
@@ -78,6 +83,12 @@ namespace YooAsset
public long SpaceOccupied { get; private set; }
#endregion
+ ///
+ /// 创建沙盒文件缓存系统实例
+ ///
+ /// 包裹名称
+ /// 缓存根目录
+ /// 缓存配置
public SandboxFileCache(string packageName, string rootPath, CacheConfig config)
{
PackageName = packageName;
@@ -93,7 +104,7 @@ namespace YooAsset
var operation = new SFCInitializeOperation(this);
return operation;
}
- public virtual FCWriteCacheOperation WriteCacheAsync(WriteCacheOptions options)
+ public virtual FCWriteCacheOperation WriteCacheAsync(FCWriteCacheOptions options)
{
var operation = new SFCWriteCacheOperation(this, options);
return operation;
@@ -127,12 +138,12 @@ namespace YooAsset
return operation;
}
}
- public virtual FCVerifyCacheOperation VerifyCacheAsync(VerifyCacheOptions options)
+ public virtual FCVerifyCacheOperation VerifyCacheAsync(FCVerifyCacheOptions options)
{
var operation = new SFCVerifyCacheOperation(this, options);
return operation;
}
- public virtual FCLoadBundleOperation LoadBundleAsync(LoadBundleOptions options)
+ public virtual FCLoadBundleOperation LoadBundleAsync(FCLoadBundleOptions options)
{
if (options.Bundle.BundleType == (int)EBundleType.AssetBundle)
{
@@ -153,7 +164,7 @@ namespace YooAsset
}
public virtual bool IsCached(string bundleGUID)
{
- return _caches.ContainsKey(bundleGUID);
+ return _cacheEntries.ContainsKey(bundleGUID);
}
#region 内部方法
@@ -185,12 +196,30 @@ namespace YooAsset
return filePath;
}
+ ///
+ /// 获取 Bundle 数据临时文件路径
+ ///
+ internal string GetDataTempFilePath(PackageBundle bundle)
+ {
+ string folderName = GetHashFolderName(bundle.FileHash);
+ return PathUtility.Combine(RootPath, folderName, bundle.BundleGUID, SandboxFileCacheDefine.BundleDataTempFileName);
+ }
+
+ ///
+ /// 获取 Bundle 信息临时文件路径
+ ///
+ internal string GetInfoTempFilePath(PackageBundle bundle)
+ {
+ string folderName = GetHashFolderName(bundle.FileHash);
+ return PathUtility.Combine(RootPath, folderName, bundle.BundleGUID, SandboxFileCacheDefine.BundleInfoTempFileName);
+ }
+
///
/// 获取指定缓存
///
internal SandboxFileCacheEntry GetEntry(string bundleGUID)
{
- if (_caches.TryGetValue(bundleGUID, out SandboxFileCacheEntry entry))
+ if (_cacheEntries.TryGetValue(bundleGUID, out SandboxFileCacheEntry entry))
return entry;
else
return null;
@@ -201,19 +230,19 @@ namespace YooAsset
///
internal IReadOnlyCollection GetAllEntries()
{
- return _caches.Values;
+ return _cacheEntries.Values;
}
///
/// 添加指定缓存
///
- internal void AddEntry(string bundleGUID, SandboxFileCacheEntry entry)
+ internal void AddEntry(string bundleGUID, SandboxFileCacheEntry cacheEntry)
{
- if (_caches.ContainsKey(bundleGUID))
- throw new YooInternalException($"Cache entry already existed: {bundleGUID}");
+ if (_cacheEntries.ContainsKey(bundleGUID))
+ throw new YooInternalException($"Cache entry already exists: {bundleGUID}");
- _caches.Add(bundleGUID, entry);
- SpaceOccupied += entry.GetFileSize();
+ _cacheEntries.Add(bundleGUID, cacheEntry);
+ SpaceOccupied += cacheEntry.GetFileSize();
}
///
@@ -221,9 +250,9 @@ namespace YooAsset
///
internal void RemoveEntry(string bundleGUID)
{
- if (_caches.TryGetValue(bundleGUID, out SandboxFileCacheEntry entry))
+ if (_cacheEntries.TryGetValue(bundleGUID, out SandboxFileCacheEntry entry))
{
- _caches.Remove(bundleGUID);
+ _cacheEntries.Remove(bundleGUID);
_dataFilePathMapping.Remove(bundleGUID);
_infoFilePathMapping.Remove(bundleGUID);
SpaceOccupied -= entry.GetFileSize();
@@ -236,9 +265,9 @@ namespace YooAsset
if (string.IsNullOrEmpty(fileHash))
throw new YooInternalException();
- if (fileHash.Length <= HashFolderLength)
+ if (fileHash.Length <= HashFolderNameLength)
return fileHash;
- return fileHash.Substring(0, HashFolderLength);
+ return fileHash.Substring(0, HashFolderNameLength);
}
#endregion
}
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/SandboxFileCacheDefine.cs b/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/SandboxFileCacheDefine.cs
index 6f4ee2ab..a3dad407 100644
--- a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/SandboxFileCacheDefine.cs
+++ b/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/SandboxFileCacheDefine.cs
@@ -1,6 +1,9 @@
-
+
namespace YooAsset
{
+ ///
+ /// 沙盒文件缓存常量定义
+ ///
internal class SandboxFileCacheDefine
{
///
@@ -12,5 +15,15 @@ namespace YooAsset
/// 信息文件名称
///
public const string BundleInfoFileName = "__info";
+
+ ///
+ /// 数据临时文件名称
+ ///
+ public const string BundleDataTempFileName = "__data.tmp";
+
+ ///
+ /// 信息临时文件名称
+ ///
+ public const string BundleInfoTempFileName = "__info.tmp";
}
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/SandboxFileCacheEntry.cs b/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/SandboxFileCacheEntry.cs
index eb942296..a9aa030e 100644
--- a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/SandboxFileCacheEntry.cs
+++ b/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/SandboxFileCacheEntry.cs
@@ -3,13 +3,35 @@ using System.IO;
namespace YooAsset
{
+ ///
+ /// 沙盒文件缓存条目
+ ///
internal class SandboxFileCacheEntry : ICacheEntry
{
- public string BundleGUID { get; private set; }
- public string InfoFilePath { get; private set; }
- public string DataFilePath { get; private set; }
- private long _fileSize = 0;
+ private long _fileSize = -1;
+ ///
+ /// 资源包唯一标识
+ ///
+ public string BundleGUID { get; private set; }
+
+ ///
+ /// 信息文件路径
+ ///
+ public string InfoFilePath { get; private set; }
+
+ ///
+ /// 数据文件路径
+ ///
+ public string DataFilePath { get; private set; }
+
+
+ ///
+ /// 创建沙盒文件缓存条目
+ ///
+ /// 资源包唯一标识
+ /// 信息文件路径
+ /// 数据文件路径
public SandboxFileCacheEntry(string bundleGUID, string infoFilePath, string dataFilePath)
{
BundleGUID = bundleGUID;
@@ -18,8 +40,9 @@ namespace YooAsset
}
///
- /// 删除记录文件
+ /// 删除缓存文件夹及其所有内容
///
+ /// 删除是否成功
public bool Delete()
{
try
@@ -43,13 +66,14 @@ namespace YooAsset
}
}
+ ///
+ /// 获取缓存文件总大小
+ ///
+ /// 文件总大小(字节)
public long GetFileSize()
{
- if (_fileSize == 0)
- {
- _fileSize = FileUtility.GetFileSize(InfoFilePath);
- _fileSize += FileUtility.GetFileSize(DataFilePath);
- }
+ if (_fileSize < 0)
+ _fileSize = FileUtility.GetFileSize(DataFilePath);
return _fileSize;
}
}
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/SearchFileInfo.cs b/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/SearchFileInfo.cs
new file mode 100644
index 00000000..bc294b02
--- /dev/null
+++ b/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/SearchFileInfo.cs
@@ -0,0 +1,65 @@
+using System.IO;
+
+namespace YooAsset
+{
+ ///
+ /// 搜索的文件信息,用于缓存文件校验流程
+ ///
+ internal class SearchFileInfo
+ {
+ ///
+ /// 资源包唯一标识
+ ///
+ public string BundleGUID { get; private set; }
+
+ ///
+ /// 缓存文件夹路径
+ ///
+ public string FolderPath { get; private set; }
+
+ ///
+ /// 数据文件路径
+ ///
+ public string DataFilePath { get; private set; }
+
+ ///
+ /// 信息文件路径
+ ///
+ public string InfoFilePath { get; private set; }
+
+ ///
+ /// 验证结果码(原子操作对象,用于线程安全)
+ ///
+ public volatile int VerifyResultCode = 0;
+
+ ///
+ /// 创建验证文件信息
+ ///
+ /// 资源包唯一标识
+ /// 缓存文件夹路径
+ /// 数据文件路径
+ /// 信息文件路径
+ public SearchFileInfo(string bundleGUID, string folderPath, string dataFilePath, string infoFilePath)
+ {
+ BundleGUID = bundleGUID;
+ FolderPath = folderPath;
+ DataFilePath = dataFilePath;
+ InfoFilePath = infoFilePath;
+ }
+
+ ///
+ /// 删除缓存文件夹及其内容
+ ///
+ public void DeleteCacheFolder()
+ {
+ try
+ {
+ Directory.Delete(FolderPath, true);
+ }
+ catch (System.Exception ex)
+ {
+ YooLogger.Warning($"Failed to delete cache bundle folder: {ex}");
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/VerifyFileInfo.cs.meta b/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/SearchFileInfo.cs.meta
similarity index 100%
rename from Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/VerifyFileInfo.cs.meta
rename to Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/SearchFileInfo.cs.meta
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/TempFileInfo.cs b/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/TempFileInfo.cs
index 84ff3774..38d72746 100644
--- a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/TempFileInfo.cs
+++ b/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/TempFileInfo.cs
@@ -1,22 +1,42 @@
-
+
namespace YooAsset
{
+ ///
+ /// 临时的文件信息,用于存储待验证的下载文件
+ ///
internal class TempFileInfo
{
- public string TempFilePath { private set; get; }
- public uint TempFileCRC { private set; get; }
- public long TempFileSize { private set; get; }
+ ///
+ /// 临时文件路径
+ ///
+ public string FilePath { private set; get; }
///
- /// 注意:原子操作对象
+ /// 文件CRC校验值
///
- public volatile int Result = 0;
+ public uint FileCRC { private set; get; }
+ ///
+ /// 文件大小(字节)
+ ///
+ public long FileSize { private set; get; }
+
+ ///
+ /// 验证结果码(原子操作对象,用于线程安全)
+ ///
+ public volatile int VerifyResultCode = 0;
+
+ ///
+ /// 创建临时文件信息
+ ///
+ /// 临时文件路径
+ /// 文件CRC校验值
+ /// 文件大小(字节)
public TempFileInfo(string filePath, uint fileCRC, long fileSize)
{
- TempFilePath = filePath;
- TempFileCRC = fileCRC;
- TempFileSize = fileSize;
+ FilePath = filePath;
+ FileCRC = fileCRC;
+ FileSize = fileSize;
}
}
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/VerifyFileInfo.cs b/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/VerifyFileInfo.cs
deleted file mode 100644
index 24dd8e9d..00000000
--- a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/VerifyFileInfo.cs
+++ /dev/null
@@ -1,37 +0,0 @@
-using System.IO;
-
-namespace YooAsset
-{
- internal class VerifyFileInfo
- {
- public string BundleGUID { get; private set; }
- public string FolderPath { get; private set; }
- public string DataFilePath { get; private set; }
- public string InfoFilePath { get; private set; }
-
- ///
- /// 注意:原子操作对象
- ///
- public volatile int Result = 0;
-
- public VerifyFileInfo(string bundleGUID, string folderPath, string dataFilePath, string infoFilePath)
- {
- BundleGUID = bundleGUID;
- FolderPath = folderPath;
- DataFilePath = dataFilePath;
- InfoFilePath = infoFilePath;
- }
-
- public void DeleteFiles()
- {
- try
- {
- Directory.Delete(FolderPath, true);
- }
- catch (System.Exception ex)
- {
- YooLogger.Warning($"Failed to delete cache bundle folder : {ex}");
- }
- }
- }
-}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/UnityFileCache.meta b/Assets/YooAsset/Runtime/FileCache/Services/UnityFileCache.meta
deleted file mode 100644
index f508a067..00000000
--- a/Assets/YooAsset/Runtime/FileCache/Services/UnityFileCache.meta
+++ /dev/null
@@ -1,8 +0,0 @@
-fileFormatVersion: 2
-guid: 0a0a41496ce76334a958424c79db1016
-folderAsset: yes
-DefaultImporter:
- externalObjects: {}
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/UnityFileCache/Operations.meta b/Assets/YooAsset/Runtime/FileCache/Services/UnityFileCache/Operations.meta
deleted file mode 100644
index 3e017e14..00000000
--- a/Assets/YooAsset/Runtime/FileCache/Services/UnityFileCache/Operations.meta
+++ /dev/null
@@ -1,8 +0,0 @@
-fileFormatVersion: 2
-guid: 65bba40cd16af3a47bddda520ab51d6b
-folderAsset: yes
-DefaultImporter:
- externalObjects: {}
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/WebRemoteFileCache/Operations/WRFCInitializeOperation.cs b/Assets/YooAsset/Runtime/FileCache/Services/WebRemoteFileCache/Operations/WRFCInitializeOperation.cs
index b833d930..42a3eb58 100644
--- a/Assets/YooAsset/Runtime/FileCache/Services/WebRemoteFileCache/Operations/WRFCInitializeOperation.cs
+++ b/Assets/YooAsset/Runtime/FileCache/Services/WebRemoteFileCache/Operations/WRFCInitializeOperation.cs
@@ -1,6 +1,9 @@
-
+
namespace YooAsset
{
+ ///
+ /// Web远端文件缓存初始化操作
+ ///
internal class WRFCInitializeOperation : FCInitializeOperation
{
private readonly WebRemoteFileCache _fileCache;
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/WebRemoteFileCache/Operations/WRFCLoadBundleOperation.cs b/Assets/YooAsset/Runtime/FileCache/Services/WebRemoteFileCache/Operations/WRFCLoadBundleOperation.cs
index ec4f4fcf..d350d3f6 100644
--- a/Assets/YooAsset/Runtime/FileCache/Services/WebRemoteFileCache/Operations/WRFCLoadBundleOperation.cs
+++ b/Assets/YooAsset/Runtime/FileCache/Services/WebRemoteFileCache/Operations/WRFCLoadBundleOperation.cs
@@ -1,6 +1,9 @@
-
+
namespace YooAsset
{
+ ///
+ /// Web远端文件缓存加载 AssetBundle 操作
+ ///
internal class WRFCLoadAssetBundleOperation : FCLoadBundleOperation
{
private enum ESteps
@@ -12,12 +15,12 @@ namespace YooAsset
}
private readonly WebRemoteFileCache _fileCache;
- private readonly LoadBundleOptions _options;
+ private readonly FCLoadBundleOptions _options;
private LoadWebAssetBundleOperation _loadWebAssetBundleOp;
private WebRemoteFileCacheEntry _cacheEntry;
private ESteps _steps = ESteps.None;
- public WRFCLoadAssetBundleOperation(WebRemoteFileCache fileCache, LoadBundleOptions options)
+ public WRFCLoadAssetBundleOperation(WebRemoteFileCache fileCache, FCLoadBundleOptions options)
{
_fileCache = fileCache;
_options = options;
@@ -38,7 +41,7 @@ namespace YooAsset
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
- Error = $"Not found file cache entry: {_options.Bundle.BundleGUID}";
+ Error = $"File cache entry not found: {_options.Bundle.BundleGUID}";
}
else
{
@@ -55,8 +58,9 @@ namespace YooAsset
options.Bundle = _options.Bundle;
options.MainURL = _cacheEntry.MainURL;
options.FallbackURL = _cacheEntry.FallbackURL;
- options.Decryptor = _fileCache.Config.AssetBundleDecryptor;
+ options.AssetBundleDecryptor = _fileCache.Config.AssetBundleDecryptor;
options.DownloadBackend = _fileCache.Config.DownloadBackend;
+ options.DownloadVerifyLevel = _fileCache.Config.DownloadVerifyLevel;
options.WatchdogTimeout = _fileCache.Config.WatchdogTimeout;
options.DisableUnityWebCache = _fileCache.Config.DisableUnityWebCache;
@@ -76,7 +80,7 @@ namespace YooAsset
if (_loadWebAssetBundleOp.Status == EOperationStatus.Succeeded)
{
if (_loadWebAssetBundleOp.BundleResult == null)
- throw new YooInternalException("Loaded asset bundle result is null.");
+ throw new YooInternalException("Loaded bundle result is null.");
_steps = ESteps.Done;
Status = EOperationStatus.Succeeded;
@@ -90,5 +94,15 @@ namespace YooAsset
}
}
}
+ internal override void InternalWaitForCompletion()
+ {
+ if (_steps != ESteps.Done)
+ {
+ _steps = ESteps.Done;
+ Status = EOperationStatus.Failed;
+ Error = $"{nameof(WebRemoteFileCache)} not support sync load asset bundle.";
+ YooLogger.Error(Error);
+ }
+ }
}
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/WebRemoteFileCache/WebRemoteFileCache.cs b/Assets/YooAsset/Runtime/FileCache/Services/WebRemoteFileCache/WebRemoteFileCache.cs
index 18ea86bc..b7fef8f8 100644
--- a/Assets/YooAsset/Runtime/FileCache/Services/WebRemoteFileCache/WebRemoteFileCache.cs
+++ b/Assets/YooAsset/Runtime/FileCache/Services/WebRemoteFileCache/WebRemoteFileCache.cs
@@ -1,10 +1,16 @@
-using System;
+using System;
using System.Collections.Generic;
namespace YooAsset
{
+ ///
+ /// Web远端文件缓存系统,用于从远程服务器加载资源
+ ///
internal class WebRemoteFileCache : IFileCache
{
+ ///
+ /// Web远端文件缓存配置
+ ///
internal struct CacheConfig
{
///
@@ -17,6 +23,11 @@ namespace YooAsset
///
public bool DisableUnityWebCache { get; set; }
+ ///
+ /// 下载数据校验级别
+ ///
+ public EFileVerifyLevel DownloadVerifyLevel { get; set; }
+
///
/// AssetBundle 解密器
///
@@ -33,9 +44,11 @@ namespace YooAsset
public IDownloadBackend DownloadBackend { get; set; }
}
- private readonly Dictionary _caches = new Dictionary(10000);
+ private readonly Dictionary _cacheEntries = new Dictionary(10000);
- // 缓存配置
+ ///
+ /// 缓存配置
+ ///
internal readonly CacheConfig Config;
#region 接口属性
@@ -61,7 +74,7 @@ namespace YooAsset
{
get
{
- return 0;
+ return _cacheEntries.Count;
}
}
@@ -72,6 +85,12 @@ namespace YooAsset
public long SpaceOccupied { get; private set; }
#endregion
+ ///
+ /// 创建Web远端文件缓存系统实例
+ ///
+ /// 包裹名称
+ /// 缓存根目录
+ /// 缓存配置
public WebRemoteFileCache(string packageName, string rootPath, CacheConfig config)
{
PackageName = packageName;
@@ -87,7 +106,7 @@ namespace YooAsset
var operation = new WRFCInitializeOperation(this);
return operation;
}
- public virtual FCWriteCacheOperation WriteCacheAsync(WriteCacheOptions options)
+ public virtual FCWriteCacheOperation WriteCacheAsync(FCWriteCacheOptions options)
{
var operation = new FCWriteCacheCompleteOperation($"{nameof(WebRemoteFileCache)} is readonly.");
return operation;
@@ -97,12 +116,12 @@ namespace YooAsset
var operation = new FCClearCacheCompleteOperation($"{nameof(WebRemoteFileCache)} is readonly.");
return operation;
}
- public virtual FCVerifyCacheOperation VerifyCacheAsync(VerifyCacheOptions options)
+ public virtual FCVerifyCacheOperation VerifyCacheAsync(FCVerifyCacheOptions options)
{
var operation = new FCVerifyCacheCompleteOperation();
return operation;
}
- public virtual FCLoadBundleOperation LoadBundleAsync(LoadBundleOptions options)
+ public virtual FCLoadBundleOperation LoadBundleAsync(FCLoadBundleOptions options)
{
if (options.Bundle.BundleType == (int)EBundleType.AssetBundle)
{
@@ -111,7 +130,7 @@ namespace YooAsset
}
else
{
- string error = $"{nameof(WebServerFileCache)} not support load bundle type : {options.Bundle.BundleType}";
+ string error = $"{nameof(WebRemoteFileCache)} not support load bundle type : {options.Bundle.BundleType}";
var operation = new FCLoadBundleErrorOperation(error);
return operation;
}
@@ -122,9 +141,12 @@ namespace YooAsset
}
#region 内部方法
- public WebRemoteFileCacheEntry GetEntry(PackageBundle bundle)
+ ///
+ /// 获取或创建指定资源包的缓存条目
+ ///
+ internal WebRemoteFileCacheEntry GetEntry(PackageBundle bundle)
{
- if (_caches.TryGetValue(bundle.BundleGUID, out WebRemoteFileCacheEntry entry))
+ if (_cacheEntries.TryGetValue(bundle.BundleGUID, out WebRemoteFileCacheEntry entry))
{
return entry;
}
@@ -133,7 +155,7 @@ namespace YooAsset
string mainURL = Config.RemoteServices.GetRemoteMainURL(bundle.FileName);
string fallbackURL = Config.RemoteServices.GetRemoteFallbackURL(bundle.FileName);
var newEntry = new WebRemoteFileCacheEntry(bundle.BundleGUID, mainURL, fallbackURL);
- _caches.Add(bundle.BundleGUID, newEntry);
+ _cacheEntries.Add(bundle.BundleGUID, newEntry);
return newEntry;
}
}
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/WebRemoteFileCache/WebRemoteFileCacheEntry.cs b/Assets/YooAsset/Runtime/FileCache/Services/WebRemoteFileCache/WebRemoteFileCacheEntry.cs
index 5e7b519a..c799a425 100644
--- a/Assets/YooAsset/Runtime/FileCache/Services/WebRemoteFileCache/WebRemoteFileCacheEntry.cs
+++ b/Assets/YooAsset/Runtime/FileCache/Services/WebRemoteFileCache/WebRemoteFileCacheEntry.cs
@@ -1,12 +1,32 @@
-
+
namespace YooAsset
{
+ ///
+ /// Web远端文件缓存条目
+ ///
internal class WebRemoteFileCacheEntry : ICacheEntry
{
+ ///
+ /// 资源包唯一标识
+ ///
public string BundleGUID { get; private set; }
+
+ ///
+ /// 主下载地址
+ ///
public string MainURL { get; private set; }
+
+ ///
+ /// 备用下载地址
+ ///
public string FallbackURL { get; private set; }
+ ///
+ /// 创建Web远端文件缓存条目
+ ///
+ /// 资源包唯一标识
+ /// 主下载地址
+ /// 备用下载地址
public WebRemoteFileCacheEntry(string bundleGUID, string mainURL, string fallbackURL)
{
BundleGUID = bundleGUID;
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/Operations/Internal.meta b/Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/Operations/Internal.meta
deleted file mode 100644
index ecc5cf33..00000000
--- a/Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/Operations/Internal.meta
+++ /dev/null
@@ -1,8 +0,0 @@
-fileFormatVersion: 2
-guid: a72d34ce1de343d4291428371af736a5
-folderAsset: yes
-DefaultImporter:
- externalObjects: {}
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/Operations/Internal/LoadWebServerCatalogOperation.cs b/Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/Operations/Internal/LoadWebServerCatalogOperation.cs
deleted file mode 100644
index 6792169a..00000000
--- a/Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/Operations/Internal/LoadWebServerCatalogOperation.cs
+++ /dev/null
@@ -1,96 +0,0 @@
-using System;
-
-namespace YooAsset
-{
- internal sealed class LoadWebServerCatalogOperation : AsyncOperationBase
- {
- private enum ESteps
- {
- None,
- RequestFileData,
- LoadCatalog,
- CheckResut,
- Done,
- }
-
- private readonly WebServerFileCache _fileCache;
- private IDownloadBytesRequest _webDataRequestOp;
- private byte[] _fileData;
- private ESteps _steps = ESteps.None;
-
- ///
- /// 内置资源目录
- ///
- public BuiltinFileCatalog Catalog;
-
- internal LoadWebServerCatalogOperation(WebServerFileCache fileCache)
- {
- _fileCache = fileCache;
- }
- internal override void InternalStart()
- {
- _steps = ESteps.RequestFileData;
- }
- internal override void InternalUpdate()
- {
- if (_steps == ESteps.None || _steps == ESteps.Done)
- return;
-
- if (_steps == ESteps.RequestFileData)
- {
- if (_webDataRequestOp == null)
- {
- string filePath = _fileCache.GetCatalogBinaryFileLoadPath();
- string url = DownloadSystemTools.ToLocalUrl(filePath);
- var args = new DownloadDataRequestArgs(url, 60, 0);
- _webDataRequestOp = _fileCache.Config.DownloadBackend.CreateBytesRequest(args);
- _webDataRequestOp.SendRequest();
- }
-
- if (_webDataRequestOp.IsDone == false)
- return;
-
- if (_webDataRequestOp.Status == EDownloadRequestStatus.Succeeded)
- {
- _fileData = _webDataRequestOp.Result;
- _steps = ESteps.LoadCatalog;
- }
- else
- {
- _steps = ESteps.Done;
- Status = EOperationStatus.Failed;
- Error = _webDataRequestOp.Error;
- }
- }
-
- if (_steps == ESteps.LoadCatalog)
- {
- try
- {
- Catalog = BuiltinFileCatalogTools.DeserializeFromBinary(_fileData);
- _steps = ESteps.CheckResut;
- }
- catch (Exception ex)
- {
- _steps = ESteps.Done;
- Status = EOperationStatus.Failed;
- Error = $"Failed to load catalog file : {ex.Message}";
- }
- }
-
- if (_steps == ESteps.CheckResut)
- {
- if (Catalog.PackageName != _fileCache.PackageName)
- {
- _steps = ESteps.Done;
- Status = EOperationStatus.Failed;
- Error = $"Catalog file package name {Catalog.PackageName} cannot match the file cache package name {_fileCache.PackageName}";
- return;
- }
-
- _steps = ESteps.Done;
- Status = EOperationStatus.Succeeded;
- }
- }
- }
-}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/Operations/WSFCInitializeOperation.cs b/Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/Operations/WSFCInitializeOperation.cs
index 32727824..5593bee9 100644
--- a/Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/Operations/WSFCInitializeOperation.cs
+++ b/Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/Operations/WSFCInitializeOperation.cs
@@ -1,18 +1,21 @@
-
+
namespace YooAsset
{
+ ///
+ /// Web服务器文件缓存初始化操作
+ ///
internal class WSFCInitializeOperation : FCInitializeOperation
{
private enum ESteps
{
None,
- LoadCatalogFile,
- RecordFiles,
+ LoadCatalog,
+ RecordEntry,
Done,
}
private readonly WebServerFileCache _fileCache;
- private LoadWebServerCatalogOperation _loadWebCatalogFileOp;
+ private LoadBuiltinCatalogOperation _loadBuiltinCatalogOp;
private ESteps _steps = ESteps.None;
public WSFCInitializeOperation(WebServerFileCache cache)
@@ -21,47 +24,54 @@ namespace YooAsset
}
internal override void InternalStart()
{
- _steps = ESteps.LoadCatalogFile;
+ _steps = ESteps.LoadCatalog;
}
internal override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
- if (_steps == ESteps.LoadCatalogFile)
+ if (_steps == ESteps.LoadCatalog)
{
- if (_loadWebCatalogFileOp == null)
+ if (_loadBuiltinCatalogOp == null)
{
- _loadWebCatalogFileOp = new LoadWebServerCatalogOperation(_fileCache);
- _loadWebCatalogFileOp.StartOperation();
- AddChildOperation(_loadWebCatalogFileOp);
+ var options = new LoadBuiltinCatalogOptions();
+ options.PackageName = _fileCache.PackageName;
+ options.FilePath = _fileCache.GetCatalogBinaryFileLoadPath();
+ options.DownloadBackend = _fileCache.Config.DownloadBackend;
+ _loadBuiltinCatalogOp = new LoadBuiltinCatalogOperation(options);
+ _loadBuiltinCatalogOp.StartOperation();
+ AddChildOperation(_loadBuiltinCatalogOp);
}
- _loadWebCatalogFileOp.UpdateOperation();
- if (_loadWebCatalogFileOp.IsDone == false)
+ _loadBuiltinCatalogOp.UpdateOperation();
+ if (_loadBuiltinCatalogOp.IsDone == false)
return;
- if (_loadWebCatalogFileOp.Status == EOperationStatus.Succeeded)
+ if (_loadBuiltinCatalogOp.Status == EOperationStatus.Succeeded)
{
- _steps = ESteps.RecordFiles;
+ _steps = ESteps.RecordEntry;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
- Error = _loadWebCatalogFileOp.Error;
+ Error = _loadBuiltinCatalogOp.Error;
}
}
- if (_steps == ESteps.RecordFiles)
+ if (_steps == ESteps.RecordEntry)
{
- var catalog = _loadWebCatalogFileOp.Catalog;
- foreach (var wrapper in catalog.Wrappers)
+ var catalog = _loadBuiltinCatalogOp.Catalog;
+ foreach (var fileEntry in catalog.FileEntries)
{
- string filePath = PathUtility.Combine(_fileCache.RootPath, wrapper.FileName);
- var entry = new WebServerFileCacheEntry(wrapper.BundleGUID, filePath);
- _fileCache.AddEntry(wrapper.BundleGUID, entry);
+ string filePath = PathUtility.Combine(_fileCache.RootPath, fileEntry.FileName);
+ var cacheEntry = new WebServerFileCacheEntry(fileEntry.BundleGUID, filePath);
+ _fileCache.AddEntry(fileEntry.BundleGUID, cacheEntry);
}
+
+ _steps = ESteps.Done;
+ Status = EOperationStatus.Succeeded;
}
}
}
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/Operations/WSFCLoadBundleOperation.cs b/Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/Operations/WSFCLoadBundleOperation.cs
index cf2bcf22..7fd05def 100644
--- a/Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/Operations/WSFCLoadBundleOperation.cs
+++ b/Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/Operations/WSFCLoadBundleOperation.cs
@@ -1,6 +1,9 @@
-
+
namespace YooAsset
{
+ ///
+ /// Web服务器文件缓存加载 AssetBundle 操作
+ ///
internal class WSFCLoadAssetBundleOperation : FCLoadBundleOperation
{
private enum ESteps
@@ -12,12 +15,12 @@ namespace YooAsset
}
private readonly WebServerFileCache _fileCache;
- private readonly LoadBundleOptions _options;
+ private readonly FCLoadBundleOptions _options;
private LoadWebAssetBundleOperation _loadWebAssetBundleOp;
private WebServerFileCacheEntry _cacheEntry;
private ESteps _steps = ESteps.None;
- public WSFCLoadAssetBundleOperation(WebServerFileCache fileCache, LoadBundleOptions options)
+ public WSFCLoadAssetBundleOperation(WebServerFileCache fileCache, FCLoadBundleOptions options)
{
_fileCache = fileCache;
_options = options;
@@ -38,7 +41,7 @@ namespace YooAsset
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
- Error = $"Not found file cache entry: {_options.Bundle.BundleGUID}";
+ Error = $"File cache entry not found: {_options.Bundle.BundleGUID}";
}
else
{
@@ -56,8 +59,9 @@ namespace YooAsset
options.Bundle = _options.Bundle;
options.MainURL = url;
options.FallbackURL = url;
- options.Decryptor = _fileCache.Config.AssetBundleDecryptor;
+ options.AssetBundleDecryptor = _fileCache.Config.AssetBundleDecryptor;
options.DownloadBackend = _fileCache.Config.DownloadBackend;
+ options.DownloadVerifyLevel = _fileCache.Config.DownloadVerifyLevel;
options.WatchdogTimeout = _fileCache.Config.WatchdogTimeout;
options.DisableUnityWebCache = _fileCache.Config.DisableUnityWebCache;
@@ -77,7 +81,7 @@ namespace YooAsset
if (_loadWebAssetBundleOp.Status == EOperationStatus.Succeeded)
{
if (_loadWebAssetBundleOp.BundleResult == null)
- throw new YooInternalException("Loaded asset bundle result is null.");
+ throw new YooInternalException("Loaded bundle result is null.");
_steps = ESteps.Done;
Status = EOperationStatus.Succeeded;
@@ -91,5 +95,15 @@ namespace YooAsset
}
}
}
+ internal override void InternalWaitForCompletion()
+ {
+ if (_steps != ESteps.Done)
+ {
+ _steps = ESteps.Done;
+ Status = EOperationStatus.Failed;
+ Error = $"{nameof(WebServerFileCache)} not support sync load asset bundle.";
+ YooLogger.Error(Error);
+ }
+ }
}
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/WebServerFileCache.cs b/Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/WebServerFileCache.cs
index caef84c3..7c0726c5 100644
--- a/Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/WebServerFileCache.cs
+++ b/Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/WebServerFileCache.cs
@@ -1,10 +1,16 @@
-using System;
+using System;
using System.Collections.Generic;
namespace YooAsset
{
+ ///
+ /// Web服务器文件缓存系统,用于WebGL平台从服务器加载资源
+ ///
internal class WebServerFileCache : IFileCache
{
+ ///
+ /// Web服务器文件缓存配置
+ ///
internal struct CacheConfig
{
///
@@ -17,20 +23,27 @@ namespace YooAsset
///
public bool DisableUnityWebCache { get; set; }
+ ///
+ /// 下载数据校验级别
+ ///
+ public EFileVerifyLevel DownloadVerifyLevel { get; set; }
+
///
/// AssetBundle 解密器
///
public IBundleDecryptor AssetBundleDecryptor { get; set; }
///
- /// 下载后台接口
+ /// 下载后台
///
public IDownloadBackend DownloadBackend { get; set; }
}
- private readonly Dictionary _caches = new Dictionary(10000);
+ private readonly Dictionary _cacheEntries = new Dictionary(10000);
- // 缓存配置
+ ///
+ /// 缓存配置
+ ///
internal readonly CacheConfig Config;
#region 接口属性
@@ -56,7 +69,7 @@ namespace YooAsset
{
get
{
- return _caches.Count;
+ return _cacheEntries.Count;
}
}
@@ -67,6 +80,12 @@ namespace YooAsset
public long SpaceOccupied { get; private set; }
#endregion
+ ///
+ /// 创建Web服务器文件缓存系统实例
+ ///
+ /// 包裹名称
+ /// 缓存根目录
+ /// 缓存配置
public WebServerFileCache(string packageName, string rootPath, CacheConfig config)
{
PackageName = packageName;
@@ -82,7 +101,7 @@ namespace YooAsset
var operation = new WSFCInitializeOperation(this);
return operation;
}
- public virtual FCWriteCacheOperation WriteCacheAsync(WriteCacheOptions options)
+ public virtual FCWriteCacheOperation WriteCacheAsync(FCWriteCacheOptions options)
{
var operation = new FCWriteCacheCompleteOperation($"{nameof(WebServerFileCache)} is readonly.");
return operation;
@@ -92,12 +111,12 @@ namespace YooAsset
var operation = new FCClearCacheCompleteOperation($"{nameof(WebServerFileCache)} is readonly.");
return operation;
}
- public virtual FCVerifyCacheOperation VerifyCacheAsync(VerifyCacheOptions options)
+ public virtual FCVerifyCacheOperation VerifyCacheAsync(FCVerifyCacheOptions options)
{
var operation = new FCVerifyCacheCompleteOperation();
return operation;
}
- public virtual FCLoadBundleOperation LoadBundleAsync(LoadBundleOptions options)
+ public virtual FCLoadBundleOperation LoadBundleAsync(FCLoadBundleOptions options)
{
if (options.Bundle.BundleType == (int)EBundleType.AssetBundle)
{
@@ -113,13 +132,16 @@ namespace YooAsset
}
public virtual bool IsCached(string bundleGUID)
{
- return _caches.ContainsKey(bundleGUID);
+ return _cacheEntries.ContainsKey(bundleGUID);
}
#region 内部方法
- public WebServerFileCacheEntry GetEntry(string bundleGUID)
+ ///
+ /// 获取指定缓存条目
+ ///
+ internal WebServerFileCacheEntry GetEntry(string bundleGUID)
{
- if (_caches.TryGetValue(bundleGUID, out WebServerFileCacheEntry entry))
+ if (_cacheEntries.TryGetValue(bundleGUID, out WebServerFileCacheEntry entry))
return entry;
else
return null;
@@ -128,12 +150,12 @@ namespace YooAsset
///
/// 添加指定缓存
///
- internal void AddEntry(string bundleGUID, WebServerFileCacheEntry entry)
+ internal void AddEntry(string bundleGUID, WebServerFileCacheEntry cacheEntry)
{
- if (_caches.ContainsKey(bundleGUID))
- throw new YooInternalException($"Cache entry already existed: {bundleGUID}");
+ if (_cacheEntries.ContainsKey(bundleGUID))
+ throw new YooInternalException($"Cache entry already exists: {bundleGUID}");
- _caches.Add(bundleGUID, entry);
+ _cacheEntries.Add(bundleGUID, cacheEntry);
}
///
@@ -141,7 +163,7 @@ namespace YooAsset
///
internal string GetCatalogBinaryFileLoadPath()
{
- return PathUtility.Combine(RootPath, BuiltinFileCatalogDefine.BinaryFileName);
+ return PathUtility.Combine(RootPath, BuiltinCatalogDefine.BinaryFileName);
}
#endregion
}
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/WebServerFileCacheEntry.cs b/Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/WebServerFileCacheEntry.cs
index 47258ca3..f14600cf 100644
--- a/Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/WebServerFileCacheEntry.cs
+++ b/Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/WebServerFileCacheEntry.cs
@@ -1,11 +1,26 @@
-
+
namespace YooAsset
{
+ ///
+ /// Web服务器文件缓存条目
+ ///
internal class WebServerFileCacheEntry : ICacheEntry
{
+ ///
+ /// 资源包唯一标识
+ ///
public string BundleGUID { get; private set; }
+
+ ///
+ /// 资源包文件路径
+ ///
public string FilePath { get; private set; }
+ ///
+ /// 创建Web服务器文件缓存条目
+ ///
+ /// 资源包唯一标识
+ /// 资源包文件路径
public WebServerFileCacheEntry(string bundleGUID, string filePath)
{
BundleGUID = bundleGUID;
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/XXXDefaultLoadAssetBundleOperation.cs b/Assets/YooAsset/Runtime/FileCache/Services/XXXDefaultLoadAssetBundleOperation.cs
deleted file mode 100644
index 9e19d9bd..00000000
--- a/Assets/YooAsset/Runtime/FileCache/Services/XXXDefaultLoadAssetBundleOperation.cs
+++ /dev/null
@@ -1,254 +0,0 @@
-using System;
-using System.IO;
-using UnityEngine;
-
-/*
-namespace YooAsset
-{
- ///
- /// 默认的 AssetBundle 加载操作(非加密)
- /// 通用实现,适用于 BuiltinFileSystem 和 CacheFileSystem
- ///
- public class DefaultLoadAssetBundleOperation : LoadAssetBundleOperation
- {
- private enum ESteps
- {
- None,
- LoadAssetBundle,
- CheckResult,
- Done,
- }
-
- private AssetBundleCreateRequest _createRequest;
- private ESteps _steps = ESteps.None;
-
- public DefaultLoadAssetBundleOperation(LoadAssetBundleOptions opionts) : base(opionts) { }
- internal override void InternalStart()
- {
- _steps = ESteps.LoadAssetBundle;
- }
- internal override void InternalUpdate()
- {
- if (_steps == ESteps.None || _steps == ESteps.Done)
- return;
-
- if (_steps == ESteps.LoadAssetBundle)
- {
- if (IsWaitForCompletion)
- Result = AssetBundle.LoadFromFile(_options.FileLoadPath);
- else
- _createRequest = AssetBundle.LoadFromFileAsync(_options.FileLoadPath);
-
- _steps = ESteps.CheckResult;
- }
-
- if (_steps == ESteps.CheckResult)
- {
- if (_createRequest != null)
- {
- if (IsWaitForCompletion)
- {
- // 强制挂起主线程(注意:该操作会很耗时)
- YooLogger.Warning("Suspend the main thread to load unity bundle.");
- Result = _createRequest.assetBundle;
- }
- else
- {
- if (_createRequest.isDone == false)
- return;
- Result = _createRequest.assetBundle;
- }
- }
-
- if (Result == null)
- {
- _steps = ESteps.Done;
- Status = EOperationStatus.Failed;
- Error = $"Failed to load asset bundle file : {_options.Bundle.BundleName}";
- }
- else
- {
- _steps = ESteps.Done;
- Status = EOperationStatus.Succeeded;
- }
- }
- }
- internal override void InternalWaitForCompletion()
- {
- ExecuteBatch();
- }
-
- public override AssetBundle LoadFromMemory()
- {
- if (IsSupportFileIO(_options.FileLoadPath) == false)
- return null;
-
- byte[] fileData = FileUtility.ReadAllBytes(_options.FileLoadPath);
- if (fileData == null || fileData.Length == 0)
- return null;
-
- return AssetBundle.LoadFromMemory(fileData);
- }
- }
-
- ///
- /// 默认的 AssetBundle 加载操作(加密)
- /// 通用实现,适用于 BuiltinFileSystem 和 CacheFileSystem
- ///
- public abstract class DefaultLoadAssetBundleFromOffsetOperation : LoadAssetBundleOperation
- {
- protected DefaultLoadAssetBundleFromOffsetOperation(LoadAssetBundleOptions options) : base(options)
- {
- }
-
- ///
- /// 获取偏移值
- ///
- protected abstract uint GetFileOffset();
-
- public override AssetBundle LoadFromMemory()
- {
- int offset = (int)GetFileOffset();
- byte[] fileData = File.ReadAllBytes(_options.FileLoadPath);
- if (fileData == null || fileData.Length <= offset)
- return null;
-
- // 跳过偏移量
- byte[] bundleData = new byte[fileData.Length - offset];
- Buffer.BlockCopy(fileData, offset, bundleData, 0, bundleData.Length);
-
- return AssetBundle.LoadFromMemory(bundleData);
- }
- }
-
- ///
- /// 默认的 AssetBundle 加载操作(加密)
- /// 通用实现,适用于 CacheFileSystem
- ///
- public abstract class DefaultLoadAssetBundleFromMemoryOperation : LoadAssetBundleOperation
- {
- private enum ESteps
- {
- None,
- CheckFilePath,
- LoadAssetBundle,
- CheckResult,
- Done,
- }
-
- private AssetBundleCreateRequest _createRequest;
- private ESteps _steps = ESteps.None;
-
- public DefaultLoadAssetBundleFromMemoryOperation(LoadAssetBundleOptions options) : base(options) { }
- internal override void InternalStart()
- {
- _steps = ESteps.CheckFilePath;
- }
- internal override void InternalUpdate()
- {
- if (_steps == ESteps.CheckFilePath)
- {
- string filePath = _options.FileLoadPath;
- if (IsSupportFileIO(filePath) == false)
- {
- _steps = ESteps.Done;
- Status = EOperationStatus.Failed;
- Error = $"FileIO not supported for builtin path : {filePath}";
- }
- else
- {
- _steps = ESteps.LoadAssetBundle;
- }
- }
-
- if (_steps == ESteps.LoadAssetBundle)
- {
- byte[] fileData = File.ReadAllBytes(_options.FileLoadPath);
- byte[] rawData = DecryptData(fileData);
- if (rawData == null || rawData.Length == 0)
- {
- _steps = ESteps.None;
- Status = EOperationStatus.Failed;
- Error = "Decrypted raw data is null or empty.";
- return;
- }
-
- if (IsWaitForCompletion)
- Result = AssetBundle.LoadFromMemory(rawData);
- else
- _createRequest = AssetBundle.LoadFromMemoryAsync(rawData);
-
- _steps = ESteps.CheckResult;
- }
- }
-
- ///
- /// 文件数据解密
- ///
- protected abstract byte[] DecryptData(byte[] data);
-
- public override AssetBundle LoadFromMemory()
- {
- byte[] fileData = File.ReadAllBytes(_options.FileLoadPath);
- byte[] rawData = DecryptData(fileData);
- if (rawData == null || rawData.Length == 0)
- return null;
-
- return AssetBundle.LoadFromMemory(rawData);
- }
- }
-
- ///
- /// 默认的 AssetBundle 加载操作(加密)
- /// 通用实现,适用于 CacheFileSystem
- ///
- public abstract class DefaultLoadAssetBundleFromStreamOperation : LoadAssetBundleOperation
- {
- private enum ESteps
- {
- None,
- CheckFilePath,
- LoadAssetBundle,
- CheckResult,
- Done,
- }
- private ESteps _steps = ESteps.None;
- protected DefaultLoadAssetBundleFromStreamOperation(LoadAssetBundleOptions options) : base(options)
- {
- }
-
- internal override void InternalUpdate()
- {
- if (_steps == ESteps.CheckFilePath)
- {
- string filePath = _options.FileLoadPath;
- if (IsSupportFileIO(filePath) == false)
- {
- _steps = ESteps.Done;
- Status = EOperationStatus.Failed;
- Error = $"FileIO not supported for builtin path : {filePath}";
- }
- else
- {
- _steps = ESteps.LoadAssetBundle;
- }
- }
- }
-
- ///
- /// 文件数据解密
- ///
- protected abstract byte[] DecryptData(byte[] data);
-
- public override AssetBundle LoadFromMemory()
- {
- byte[] fileData = File.ReadAllBytes(_options.FileLoadPath);
- byte[] rawData = DecryptData(fileData);
- if (rawData == null || rawData.Length == 0)
- return null;
-
- return AssetBundle.LoadFromMemory(rawData);
- }
- }
-}
-*/
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/XXXDefaultLoadRawBundleOperation.cs b/Assets/YooAsset/Runtime/FileCache/Services/XXXDefaultLoadRawBundleOperation.cs
deleted file mode 100644
index 61071a59..00000000
--- a/Assets/YooAsset/Runtime/FileCache/Services/XXXDefaultLoadRawBundleOperation.cs
+++ /dev/null
@@ -1,107 +0,0 @@
-using System.IO;
-
-/*
-namespace YooAsset
-{
- ///
- /// 默认的 RawBundle 加载操作(非加密)
- /// 通用实现,适用于 BuiltinFileSystem 和 CacheFileSystem
- ///
- public class DefaultLoadRawBundleOperation : LoadRawBundleOperation
- {
- private enum ESteps
- {
- None,
- CheckFilePath,
- LoadRawBundle,
- Done
- }
-
- private ESteps _steps = ESteps.None;
-
- public DefaultLoadRawBundleOperation(LoadRawBundleOptions options) : base(options) { }
- internal override void InternalStart()
- {
- _steps = ESteps.CheckFilePath;
- }
- internal override void InternalUpdate()
- {
- if (_steps == ESteps.LoadRawBundle)
- {
- string filePath = _options.FileLoadPath;
- if (File.Exists(filePath))
- {
- byte[] data = File.ReadAllBytes(filePath);
- Result = new RawBundle(data);
- _steps = ESteps.Done;
- Status = EOperationStatus.Succeeded;
- }
- else
- {
- _steps = ESteps.Done;
- Status = EOperationStatus.Failed;
- Error = $"Can not found raw bundle file : {filePath}";
- }
- }
- }
- }
-
- ///
- /// 默认的 RawBundle 加载操作(加密)
- /// 通用实现,适用于 CacheFileSystem
- ///
- public abstract class DefaultLoadRawBundleFromMemoryOperation : LoadRawBundleOperation
- {
- private enum ESteps
- {
- None,
- CheckFilePath,
- LoadRawBundle,
- Done
- }
-
- private ESteps _steps = ESteps.None;
-
- public DefaultLoadRawBundleFromMemoryOperation(LoadRawBundleOptions options) : base(options) { }
- internal override void InternalStart()
- {
- _steps = ESteps.CheckFilePath;
- }
- internal override void InternalUpdate()
- {
- if (_steps == ESteps.LoadRawBundle)
- {
- string filePath = _options.FileLoadPath;
- if (File.Exists(filePath))
- {
- byte[] fileData = File.ReadAllBytes(filePath);
- byte[] rawData = DecryptData(fileData);
- if (rawData == null || rawData.Length == 0)
- {
- _steps = ESteps.None;
- Status = EOperationStatus.Failed;
- Error = "Decrypted raw data is null or empty.";
- }
- else
- {
- Result = new RawBundle(rawData);
- _steps = ESteps.Done;
- Status = EOperationStatus.Succeeded;
- }
- }
- else
- {
- _steps = ESteps.Done;
- Status = EOperationStatus.Failed;
- Error = $"Can not found raw bundle file : {filePath}";
- }
- }
- }
-
- ///
- /// 文件数据解密
- ///
- protected abstract byte[] DecryptData(byte[] data);
- }
-}
-*/
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/XXXDefaultLoadWebAssetBundleOperation.cs b/Assets/YooAsset/Runtime/FileCache/Services/XXXDefaultLoadWebAssetBundleOperation.cs
deleted file mode 100644
index 6480ec6a..00000000
--- a/Assets/YooAsset/Runtime/FileCache/Services/XXXDefaultLoadWebAssetBundleOperation.cs
+++ /dev/null
@@ -1,251 +0,0 @@
-using UnityEngine;
-
-/*
-namespace YooAsset
-{
- ///
- /// 默认的 AssetBundle 加载操作(非加密)
- /// 通用实现,适用于 WebRemoteFileSystem 和 WebServerFileSystem
- ///
- public class DefaultLoadWebAssetBundleOperation : LoadWebAssetBundleOperation
- {
- private enum ESteps
- {
- None,
- CreateRequest,
- CheckRequest,
- TryAgain,
- Done,
- }
-
- private IDownloadAssetBundleRequest _downloadAssetBundleRequest;
- private ESteps _steps = ESteps.None;
-
- private int _requestCount = 0;
- private float _tryAgainTimer = 0;
- private int _failedTryAgain;
-
- public DefaultLoadWebAssetBundleOperation(LoadWebAssetBundleOptions opionts) : base(opionts)
- {
- _failedTryAgain = opionts.RetryCount;
- }
- internal override void InternalStart()
- {
- _steps = ESteps.CreateRequest;
- }
- internal override void InternalUpdate()
- {
- if (_steps == ESteps.None || _steps == ESteps.Done)
- return;
-
- // 创建下载器
- if (_steps == ESteps.CreateRequest)
- {
- string url = GetRequestURL();
- var args = new DownloadAssetBundleRequestArgs(url, 0, _options.WatchdogTimeout, _options.DisableUnityWebCache, _options.Bundle.FileHash, _options.Bundle.UnityCRC);
- _downloadAssetBundleRequest = _options.DownloadBackend.CreateAssetBundleRequest(args);
- _downloadAssetBundleRequest.SendRequest();
- _steps = ESteps.CheckRequest;
- }
-
- // 检测下载结果
- if (_steps == ESteps.CheckRequest)
- {
- Progress = _downloadAssetBundleRequest.DownloadProgress;
- DownloadedBytes = _downloadAssetBundleRequest.DownloadedBytes;
- DownloadProgress = _downloadAssetBundleRequest.DownloadProgress;
- if (_downloadAssetBundleRequest.IsDone == false)
- return;
-
- if (_downloadAssetBundleRequest.Status == EDownloadRequestStatus.Succeeded)
- {
- _steps = ESteps.Done;
- Status = EOperationStatus.Succeeded;
- Result = _downloadAssetBundleRequest.Result;
- }
- else
- {
- if (_failedTryAgain > 0)
- {
- _steps = ESteps.TryAgain;
- YooLogger.Warning($"Failed download : {_downloadAssetBundleRequest.Url} Try again.");
- }
- else
- {
- _steps = ESteps.Done;
- Status = EOperationStatus.Failed;
- Error = _downloadAssetBundleRequest.Error;
- YooLogger.Error(Error);
- }
- }
-
- // 最终释放请求器
- _downloadAssetBundleRequest.Dispose();
- }
-
- // 重新尝试下载
- if (_steps == ESteps.TryAgain)
- {
- _tryAgainTimer += Time.unscaledDeltaTime;
- if (_tryAgainTimer > 1f)
- {
- _tryAgainTimer = 0f;
- _failedTryAgain--;
- Progress = 0f;
- DownloadProgress = 0f;
- DownloadedBytes = 0;
- _steps = ESteps.CreateRequest;
- }
- }
- }
-
- ///
- /// 获取网络请求地址
- ///
- protected string GetRequestURL()
- {
- // 轮流返回请求地址
- _requestCount++;
- if (_requestCount % 2 == 0)
- return _options.FallbackURL;
- else
- return _options.MainURL;
- }
- }
-
- ///
- /// 默认的 AssetBundle 加载操作(加密)
- /// 通用实现,适用于 WebRemoteFileSystem 和 WebServerFileSystem
- ///
- public abstract class DefaultLoadWebAssetBundleFromMemoryOperation : LoadWebAssetBundleOperation
- {
- private enum ESteps
- {
- None,
- CreateRequest,
- CheckRequest,
- TryAgain,
- Done,
- }
-
- private IDownloadBytesRequest _downloadBytesRequest;
- private ESteps _steps = ESteps.None;
-
- private int _requestCount = 0;
- private float _tryAgainTimer = 0;
- private int _failedTryAgain;
-
- public DefaultLoadWebAssetBundleFromMemoryOperation(LoadWebAssetBundleOptions opionts) : base(opionts)
- {
- _failedTryAgain = opionts.RetryCount;
- }
- internal override void InternalStart()
- {
- _steps = ESteps.CreateRequest;
- }
- internal override void InternalUpdate()
- {
- if (_steps == ESteps.None || _steps == ESteps.Done)
- return;
-
- // 创建下载器
- if (_steps == ESteps.CreateRequest)
- {
- string url = GetRequestURL();
- var args = new DownloadDataRequestArgs(url, 0, _options.WatchdogTimeout);
- _downloadBytesRequest = _options.DownloadBackend.CreateBytesRequest(args);
- _downloadBytesRequest.SendRequest();
- _steps = ESteps.CheckRequest;
- }
-
- // 检测下载结果
- if (_steps == ESteps.CheckRequest)
- {
- Progress = _downloadBytesRequest.DownloadProgress;
- DownloadProgress = _downloadBytesRequest.DownloadProgress;
- DownloadedBytes = _downloadBytesRequest.DownloadedBytes;
- if (_downloadBytesRequest.IsDone == false)
- return;
-
- // 检查网络错误
- if (_downloadBytesRequest.Status == EDownloadRequestStatus.Succeeded)
- {
- var rawData = Decryption(_downloadBytesRequest.Result);
- if (rawData == null || rawData.Length == 0)
- {
- _steps = ESteps.Done;
- Status = EOperationStatus.Failed;
- Error = "AssetBundle raw data is null or empty.";
- }
- else
- {
- AssetBundle assetBundle = AssetBundle.LoadFromMemory(rawData);
- if (assetBundle == null)
- {
- _steps = ESteps.Done;
- Status = EOperationStatus.Failed;
- Error = $"Failed load encrypted AssetBundle: {_options.Bundle.BundleName}";
- }
- else
- {
- _steps = ESteps.Done;
- Status = EOperationStatus.Succeeded;
- Result = assetBundle;
- }
- }
- }
- else
- {
- if (_failedTryAgain > 0)
- {
- _steps = ESteps.TryAgain;
- YooLogger.Warning($"Failed download : {_downloadBytesRequest.Url} Try again.");
- }
- else
- {
- _steps = ESteps.Done;
- Status = EOperationStatus.Failed;
- Error = _downloadBytesRequest.Error;
- YooLogger.Error(Error);
- }
- }
-
- // 最终释放请求器
- _downloadBytesRequest.Dispose();
- }
-
- // 重新尝试下载
- if (_steps == ESteps.TryAgain)
- {
- _tryAgainTimer += Time.unscaledDeltaTime;
- if (_tryAgainTimer > 1f)
- {
- _tryAgainTimer = 0f;
- _failedTryAgain--;
- Progress = 0f;
- DownloadProgress = 0f;
- DownloadedBytes = 0;
- _steps = ESteps.CreateRequest;
- }
- }
- }
-
- ///
- /// 文件数据解密
- ///
- protected abstract byte[] Decryption(byte[] data);
-
- /// 获取网络请求地址
- ///
- protected string GetRequestURL()
- {
- // 轮流返回请求地址
- _requestCount++;
- if (_requestCount % 2 == 0)
- return _options.FallbackURL;
- else
- return _options.MainURL;
- }
- }
-}
-*/
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/FileSystem/Interfaces/IFileSystem.cs b/Assets/YooAsset/Runtime/FileSystem/Interfaces/IFileSystem.cs
index ed62ce1f..b12983c0 100644
--- a/Assets/YooAsset/Runtime/FileSystem/Interfaces/IFileSystem.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/Interfaces/IFileSystem.cs
@@ -31,12 +31,12 @@ namespace YooAsset
///
/// 下载Bundle文件
///
- FSDownloadFileOperation DownloadFileAsync(DownloadFileOptions options);
+ FSDownloadFileOperation DownloadFileAsync(FSDownloadFileOptions options);
///
/// 加载Bundle文件
///
- FSLoadBundleOperation LoadBundleAsync(LoadBundleOptions options);
+ FSLoadBundleOperation LoadBundleAsync(FCLoadBundleOptions options);
///
diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/Internal.meta b/Assets/YooAsset/Runtime/FileSystem/Operations/Common.meta
similarity index 100%
rename from Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/Internal.meta
rename to Assets/YooAsset/Runtime/FileSystem/Operations/Common.meta
diff --git a/Assets/YooAsset/Runtime/FileSystem/Operations/Common/LoadWebPackageManifestOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Operations/Common/LoadWebPackageManifestOperation.cs
new file mode 100644
index 00000000..4dfaa558
--- /dev/null
+++ b/Assets/YooAsset/Runtime/FileSystem/Operations/Common/LoadWebPackageManifestOperation.cs
@@ -0,0 +1,132 @@
+namespace YooAsset
+{
+ internal class LoadWebPackageManifestOperation : AsyncOperationBase
+ {
+ private enum ESteps
+ {
+ None,
+ RequestFileData,
+ VerifyFileData,
+ LoadManifest,
+ Done,
+ }
+
+ private readonly LoadWebPackageManifestOptions _options;
+ private IDownloadBytesRequest _webDataRequestOp;
+ private DeserializeManifestOperation _deserializer;
+ private int _requestCount = 0;
+ private ESteps _steps = ESteps.None;
+
+ ///
+ /// 包裹清单
+ ///
+ public PackageManifest Manifest { private set; get; }
+
+
+ internal LoadWebPackageManifestOperation(LoadWebPackageManifestOptions options)
+ {
+ _options = options;
+ }
+ internal override void InternalStart()
+ {
+ _requestCount = DownloadFailureCounter.GetFailureCount(_options.PackageName, nameof(LoadWebPackageManifestOperation));
+ _steps = ESteps.RequestFileData;
+ }
+ internal override void InternalUpdate()
+ {
+ if (_steps == ESteps.None || _steps == ESteps.Done)
+ return;
+
+ if (_steps == ESteps.RequestFileData)
+ {
+ if (_webDataRequestOp == null)
+ {
+ string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_options.PackageName, _options.PackageVersion);
+ string url = GetRequestURL(fileName);
+ var args = new DownloadDataRequestArgs(url, _options.Timeout, 0);
+ _webDataRequestOp = _options.DownloadBackend.CreateBytesRequest(args);
+ _webDataRequestOp.SendRequest();
+ }
+
+ Progress = _webDataRequestOp.DownloadProgress;
+ if (_webDataRequestOp.IsDone == false)
+ return;
+
+ if (_webDataRequestOp.Status == EDownloadRequestStatus.Succeeded)
+ {
+ _steps = ESteps.VerifyFileData;
+ }
+ else
+ {
+ _steps = ESteps.Done;
+ Status = EOperationStatus.Failed;
+ Error = _webDataRequestOp.Error;
+ DownloadFailureCounter.RecordFailure(_options.PackageName, nameof(LoadWebPackageManifestOperation));
+ }
+ }
+
+ if (_steps == ESteps.VerifyFileData)
+ {
+ if (PackageManifestTools.VerifyManifestData(_webDataRequestOp.Result, _options.PackageHash))
+ {
+ _steps = ESteps.LoadManifest;
+ }
+ else
+ {
+ _steps = ESteps.Done;
+ Status = EOperationStatus.Failed;
+ Error = "Failed to verify web package manifest file.";
+ }
+ }
+
+ if (_steps == ESteps.LoadManifest)
+ {
+ if (_deserializer == null)
+ {
+ _deserializer = new DeserializeManifestOperation(_options.ManifestDecryptor, _webDataRequestOp.Result);
+ _deserializer.StartOperation();
+ AddChildOperation(_deserializer);
+ }
+
+ _deserializer.UpdateOperation();
+ Progress = _deserializer.Progress;
+ if (_deserializer.IsDone == false)
+ return;
+
+ if (_deserializer.Status == EOperationStatus.Succeeded)
+ {
+ _steps = ESteps.Done;
+ Manifest = _deserializer.Manifest;
+ Status = EOperationStatus.Succeeded;
+ }
+ else
+ {
+ _steps = ESteps.Done;
+ Status = EOperationStatus.Failed;
+ Error = _deserializer.Error;
+ }
+ }
+ }
+ internal override void InternalDispose()
+ {
+ if (_webDataRequestOp != null)
+ {
+ _webDataRequestOp.Dispose();
+ _webDataRequestOp = null;
+ }
+ }
+ internal override string InternalGetDescription()
+ {
+ return $"PackageVersion : {_options.PackageVersion} PackageHash : {_options.PackageHash}";
+ }
+
+ private string GetRequestURL(string fileName)
+ {
+ // 轮流返回请求地址
+ if (_requestCount % 2 == 0)
+ return _options.RemoteServices.GetRemoteMainURL(fileName);
+ else
+ return _options.RemoteServices.GetRemoteFallbackURL(fileName);
+ }
+ }
+}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/Internal/LoadWebPackageManifestOperation.cs.meta b/Assets/YooAsset/Runtime/FileSystem/Operations/Common/LoadWebPackageManifestOperation.cs.meta
similarity index 100%
rename from Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/Internal/LoadWebPackageManifestOperation.cs.meta
rename to Assets/YooAsset/Runtime/FileSystem/Operations/Common/LoadWebPackageManifestOperation.cs.meta
diff --git a/Assets/YooAsset/Runtime/FileSystem/Operations/Common/LoadWebPackageManifestOptions.cs b/Assets/YooAsset/Runtime/FileSystem/Operations/Common/LoadWebPackageManifestOptions.cs
new file mode 100644
index 00000000..2685308b
--- /dev/null
+++ b/Assets/YooAsset/Runtime/FileSystem/Operations/Common/LoadWebPackageManifestOptions.cs
@@ -0,0 +1,14 @@
+namespace YooAsset
+{
+ internal struct LoadWebPackageManifestOptions
+ {
+ public string PackageName { get; set; }
+ public string PackageVersion { get; set; }
+ public string PackageHash { get; set; }
+ public int Timeout { get; set; }
+
+ public IRemoteServices RemoteServices { get; set; }
+ public IManifestDecryptor ManifestDecryptor { get; set; }
+ public IDownloadBackend DownloadBackend { get; set; }
+ }
+}
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/XXXDefaultLoadAssetBundleOperation.cs.meta b/Assets/YooAsset/Runtime/FileSystem/Operations/Common/LoadWebPackageManifestOptions.cs.meta
similarity index 83%
rename from Assets/YooAsset/Runtime/FileCache/Services/XXXDefaultLoadAssetBundleOperation.cs.meta
rename to Assets/YooAsset/Runtime/FileSystem/Operations/Common/LoadWebPackageManifestOptions.cs.meta
index 64719f4f..9e31f6a8 100644
--- a/Assets/YooAsset/Runtime/FileCache/Services/XXXDefaultLoadAssetBundleOperation.cs.meta
+++ b/Assets/YooAsset/Runtime/FileSystem/Operations/Common/LoadWebPackageManifestOptions.cs.meta
@@ -1,5 +1,5 @@
fileFormatVersion: 2
-guid: 067ac2067f265624bac214127575d7d5
+guid: cbabf286b35608d419c6b1e56499d2ca
MonoImporter:
externalObjects: {}
serializedVersion: 2
diff --git a/Assets/YooAsset/Runtime/FileSystem/Operations/Common/RequestWebPackageHashOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Operations/Common/RequestWebPackageHashOperation.cs
new file mode 100644
index 00000000..fce6f1f2
--- /dev/null
+++ b/Assets/YooAsset/Runtime/FileSystem/Operations/Common/RequestWebPackageHashOperation.cs
@@ -0,0 +1,94 @@
+namespace YooAsset
+{
+ internal class RequestWebPackageHashOperation : AsyncOperationBase
+ {
+ private enum ESteps
+ {
+ None,
+ RequestPackageHash,
+ Done,
+ }
+
+ private readonly RequestWebPackageHashOptions _options;
+ private IDownloadTextRequest _webTextRequestOp;
+ private int _requestCount = 0;
+ private ESteps _steps = ESteps.None;
+
+ ///
+ /// 包裹哈希值
+ ///
+ public string PackageHash { private set; get; }
+
+
+ public RequestWebPackageHashOperation(RequestWebPackageHashOptions options)
+ {
+ _options = options;
+ }
+ internal override void InternalStart()
+ {
+ _requestCount = DownloadFailureCounter.GetFailureCount(_options.PackageName, nameof(RequestWebPackageHashOperation));
+ _steps = ESteps.RequestPackageHash;
+ }
+ internal override void InternalUpdate()
+ {
+ if (_steps == ESteps.None || _steps == ESteps.Done)
+ return;
+
+ if (_steps == ESteps.RequestPackageHash)
+ {
+ if (_webTextRequestOp == null)
+ {
+ string fileName = YooAssetSettingsData.GetPackageHashFileName(_options.PackageName, _options.PackageVersion);
+ string url = GetRequestURL(fileName);
+ var args = new DownloadDataRequestArgs(url, _options.Timeout, 0);
+ _webTextRequestOp = _options.DownloadBackend.CreateTextRequest(args);
+ _webTextRequestOp.SendRequest();
+ }
+
+ Progress = _webTextRequestOp.DownloadProgress;
+ if (_webTextRequestOp.IsDone == false)
+ return;
+
+ if (_webTextRequestOp.Status == EDownloadRequestStatus.Succeeded)
+ {
+ PackageHash = _webTextRequestOp.Result;
+ if (string.IsNullOrEmpty(PackageHash))
+ {
+ _steps = ESteps.Done;
+ Status = EOperationStatus.Failed;
+ Error = $"Web package hash file content is empty.";
+ }
+ else
+ {
+ _steps = ESteps.Done;
+ Status = EOperationStatus.Succeeded;
+ }
+ }
+ else
+ {
+ _steps = ESteps.Done;
+ Status = EOperationStatus.Failed;
+ Error = _webTextRequestOp.Error;
+ DownloadFailureCounter.RecordFailure(_options.PackageName, nameof(RequestWebPackageHashOperation));
+ }
+ }
+ }
+ internal override void InternalDispose()
+ {
+ if (_webTextRequestOp != null)
+ {
+ _webTextRequestOp.Dispose();
+ _webTextRequestOp = null;
+ }
+ }
+
+ private string GetRequestURL(string fileName)
+ {
+ // 轮流返回请求地址
+ if (_requestCount % 2 == 0)
+ return _options.RemoteServices.GetRemoteMainURL(fileName);
+ else
+ return _options.RemoteServices.GetRemoteFallbackURL(fileName);
+ }
+ }
+}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/Internal/RequestWebPackageHashOperation.cs.meta b/Assets/YooAsset/Runtime/FileSystem/Operations/Common/RequestWebPackageHashOperation.cs.meta
similarity index 100%
rename from Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/Internal/RequestWebPackageHashOperation.cs.meta
rename to Assets/YooAsset/Runtime/FileSystem/Operations/Common/RequestWebPackageHashOperation.cs.meta
diff --git a/Assets/YooAsset/Runtime/FileSystem/Operations/Common/RequestWebPackageHashOptions.cs b/Assets/YooAsset/Runtime/FileSystem/Operations/Common/RequestWebPackageHashOptions.cs
new file mode 100644
index 00000000..96d0d119
--- /dev/null
+++ b/Assets/YooAsset/Runtime/FileSystem/Operations/Common/RequestWebPackageHashOptions.cs
@@ -0,0 +1,12 @@
+namespace YooAsset
+{
+ internal struct RequestWebPackageHashOptions
+ {
+ public string PackageName { get; set; }
+ public string PackageVersion { get; set; }
+ public int Timeout { get; set; }
+
+ public IRemoteServices RemoteServices { get; set; }
+ public IDownloadBackend DownloadBackend { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/XXXDefaultLoadRawBundleOperation.cs.meta b/Assets/YooAsset/Runtime/FileSystem/Operations/Common/RequestWebPackageHashOptions.cs.meta
similarity index 83%
rename from Assets/YooAsset/Runtime/FileCache/Services/XXXDefaultLoadRawBundleOperation.cs.meta
rename to Assets/YooAsset/Runtime/FileSystem/Operations/Common/RequestWebPackageHashOptions.cs.meta
index 94400673..d7a238df 100644
--- a/Assets/YooAsset/Runtime/FileCache/Services/XXXDefaultLoadRawBundleOperation.cs.meta
+++ b/Assets/YooAsset/Runtime/FileSystem/Operations/Common/RequestWebPackageHashOptions.cs.meta
@@ -1,5 +1,5 @@
fileFormatVersion: 2
-guid: cc25b8eb3bf83474f942e36bf7b3210d
+guid: 4ba57dfeb7916fd46bb58b673fc08ef4
MonoImporter:
externalObjects: {}
serializedVersion: 2
diff --git a/Assets/YooAsset/Runtime/FileSystem/Operations/Common/RequestWebPackageVersionOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Operations/Common/RequestWebPackageVersionOperation.cs
new file mode 100644
index 00000000..c58a463c
--- /dev/null
+++ b/Assets/YooAsset/Runtime/FileSystem/Operations/Common/RequestWebPackageVersionOperation.cs
@@ -0,0 +1,102 @@
+namespace YooAsset
+{
+ internal class RequestWebPackageVersionOperation : AsyncOperationBase
+ {
+ private enum ESteps
+ {
+ None,
+ RequestPackageVersion,
+ Done,
+ }
+
+ private readonly RequestWebPackageVersionOptions _options;
+ private IDownloadTextRequest _webTextRequestOp;
+ private int _requestCount = 0;
+ private ESteps _steps = ESteps.None;
+
+ ///
+ /// 包裹版本
+ ///
+ public string PackageVersion { private set; get; }
+
+
+ public RequestWebPackageVersionOperation(RequestWebPackageVersionOptions options)
+ {
+ _options = options;
+ }
+ internal override void InternalStart()
+ {
+ _requestCount = DownloadFailureCounter.GetFailureCount(_options.PackageName, nameof(RequestWebPackageVersionOperation));
+ _steps = ESteps.RequestPackageVersion;
+ }
+ internal override void InternalUpdate()
+ {
+ if (_steps == ESteps.None || _steps == ESteps.Done)
+ return;
+
+ if (_steps == ESteps.RequestPackageVersion)
+ {
+ if (_webTextRequestOp == null)
+ {
+ string fileName = YooAssetSettingsData.GetPackageVersionFileName(_options.PackageName);
+ string url = GetRequestURL(fileName);
+ var args = new DownloadDataRequestArgs(url, _options.Timeout, 0);
+ _webTextRequestOp = _options.DownloadBackend.CreateTextRequest(args);
+ _webTextRequestOp.SendRequest();
+ }
+
+ Progress = _webTextRequestOp.DownloadProgress;
+ if (_webTextRequestOp.IsDone == false)
+ return;
+
+ if (_webTextRequestOp.Status == EDownloadRequestStatus.Succeeded)
+ {
+ PackageVersion = _webTextRequestOp.Result;
+ if (string.IsNullOrEmpty(PackageVersion))
+ {
+ _steps = ESteps.Done;
+ Status = EOperationStatus.Failed;
+ Error = $"Web package version file content is empty.";
+ }
+ else
+ {
+ _steps = ESteps.Done;
+ Status = EOperationStatus.Succeeded;
+ }
+ }
+ else
+ {
+ _steps = ESteps.Done;
+ Status = EOperationStatus.Failed;
+ Error = _webTextRequestOp.Error;
+ DownloadFailureCounter.RecordFailure(_options.PackageName, nameof(RequestWebPackageVersionOperation));
+ }
+ }
+ }
+ internal override void InternalDispose()
+ {
+ if (_webTextRequestOp != null)
+ {
+ _webTextRequestOp.Dispose();
+ _webTextRequestOp = null;
+ }
+ }
+
+ private string GetRequestURL(string fileName)
+ {
+ string url;
+
+ // 轮流返回请求地址
+ if (_requestCount % 2 == 0)
+ url = _options.RemoteServices.GetRemoteMainURL(fileName);
+ else
+ url = _options.RemoteServices.GetRemoteFallbackURL(fileName);
+
+ // 在URL末尾添加时间戳
+ if (_options.AppendTimeTicks)
+ return $"{url}?{System.DateTime.UtcNow.Ticks}";
+ else
+ return url;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/Internal/RequestWebPackageVersionOperation.cs.meta b/Assets/YooAsset/Runtime/FileSystem/Operations/Common/RequestWebPackageVersionOperation.cs.meta
similarity index 100%
rename from Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/Internal/RequestWebPackageVersionOperation.cs.meta
rename to Assets/YooAsset/Runtime/FileSystem/Operations/Common/RequestWebPackageVersionOperation.cs.meta
diff --git a/Assets/YooAsset/Runtime/FileSystem/Operations/Common/RequestWebPackageVersionOptions.cs b/Assets/YooAsset/Runtime/FileSystem/Operations/Common/RequestWebPackageVersionOptions.cs
new file mode 100644
index 00000000..8a744ea5
--- /dev/null
+++ b/Assets/YooAsset/Runtime/FileSystem/Operations/Common/RequestWebPackageVersionOptions.cs
@@ -0,0 +1,12 @@
+namespace YooAsset
+{
+ internal struct RequestWebPackageVersionOptions
+ {
+ public string PackageName { get; set; }
+ public bool AppendTimeTicks { get; set; }
+ public int Timeout { get; set; }
+
+ public IRemoteServices RemoteServices { get; set; }
+ public IDownloadBackend DownloadBackend { get; set; }
+ }
+}
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/XXXDefaultLoadWebAssetBundleOperation.cs.meta b/Assets/YooAsset/Runtime/FileSystem/Operations/Common/RequestWebPackageVersionOptions.cs.meta
similarity index 83%
rename from Assets/YooAsset/Runtime/FileCache/Services/XXXDefaultLoadWebAssetBundleOperation.cs.meta
rename to Assets/YooAsset/Runtime/FileSystem/Operations/Common/RequestWebPackageVersionOptions.cs.meta
index 50c254b1..182ae394 100644
--- a/Assets/YooAsset/Runtime/FileCache/Services/XXXDefaultLoadWebAssetBundleOperation.cs.meta
+++ b/Assets/YooAsset/Runtime/FileSystem/Operations/Common/RequestWebPackageVersionOptions.cs.meta
@@ -1,5 +1,5 @@
fileFormatVersion: 2
-guid: 05b4aa37709184a408090202f98b93d3
+guid: 1109ea54301470d4283f1b9b88d176ca
MonoImporter:
externalObjects: {}
serializedVersion: 2
diff --git a/Assets/YooAsset/Runtime/FileSystem/Operations/FSDownloadFileOptions.cs b/Assets/YooAsset/Runtime/FileSystem/Operations/FSDownloadFileOptions.cs
index a026445b..3513a635 100644
--- a/Assets/YooAsset/Runtime/FileSystem/Operations/FSDownloadFileOptions.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/Operations/FSDownloadFileOptions.cs
@@ -1,7 +1,7 @@
namespace YooAsset
{
- internal readonly struct DownloadFileOptions
+ internal readonly struct FSDownloadFileOptions
{
///
/// 资源包对象
@@ -18,13 +18,13 @@ namespace YooAsset
///
public readonly string ImportFilePath;
- public DownloadFileOptions(PackageBundle bundle, int retryCount)
+ public FSDownloadFileOptions(PackageBundle bundle, int retryCount)
{
Bundle = bundle;
RetryCount = retryCount;
ImportFilePath = null;
}
- public DownloadFileOptions(PackageBundle bundle, int retryCount, string importFilePath)
+ public FSDownloadFileOptions(PackageBundle bundle, int retryCount, string importFilePath)
{
Bundle = bundle;
RetryCount = retryCount;
diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/BuiltinFileSystem.cs b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/BuiltinFileSystem.cs
index 89186a44..2fd15332 100644
--- a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/BuiltinFileSystem.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/BuiltinFileSystem.cs
@@ -137,12 +137,12 @@ namespace YooAsset
var operation = new BFSClearCacheOperation(this, options);
return operation;
}
- public virtual FSDownloadFileOperation DownloadFileAsync(DownloadFileOptions options)
+ public virtual FSDownloadFileOperation DownloadFileAsync(FSDownloadFileOptions options)
{
var operation = new BFSDownloadFileOperation(this, options);
return operation;
}
- public virtual FSLoadBundleOperation LoadBundleAsync(LoadBundleOptions options)
+ public virtual FSLoadBundleOperation LoadBundleAsync(FCLoadBundleOptions options)
{
var operation = new BFSLoadBundleOperation(this, options);
return operation;
@@ -235,21 +235,21 @@ namespace YooAsset
else
_packageRoot = packageRoot;
- // 创建默认的下载后台接口
- if (DownloadBackend == null)
- DownloadBackend = new UnityWebRequestBackend(WebRequestCreator);
-
- // 创建解压缓存系统
+ // 设置根目录
string unpackRoot;
if (string.IsNullOrEmpty(UnpackFileSystemRoot))
- unpackRoot = GetDefaultUnpackCacheRoot(packageName);
+ unpackRoot = GetDefaultUnpackPathRoot(packageName);
else
unpackRoot = UnpackFileSystemRoot;
_unpackManifestFilesRoot = PathUtility.Combine(unpackRoot, BuiltinFileSystemDefine.UnpackManifestFilesFolderName);
_unpackBundleFilesRoot = PathUtility.Combine(unpackRoot, BuiltinFileSystemDefine.UnpackBundleFilesFolderName);
_unpackTempFilesRoot = PathUtility.Combine(unpackRoot, BuiltinFileSystemDefine.UnpackTempFilesFolderName);
- // 创建内置缓存对象
+ // 创建默认的下载后台接口
+ if (DownloadBackend == null)
+ DownloadBackend = new UnityWebRequestBackend(WebRequestCreator);
+
+ // 创建内置文件缓存系统
{
var cacheConfig = new BuiltinFileCache.CacheConfig();
cacheConfig.AssetBundleDecryptor = AssetBundleDecryptor;
@@ -258,7 +258,7 @@ namespace YooAsset
BuiltinFileCache = new BuiltinFileCache(packageName, _packageRoot, cacheConfig);
}
- // 创建沙盒缓存对象
+ // 创建沙盒文件缓存系统
{
var cacheConfig = new SandboxFileCache.CacheConfig();
cacheConfig.FileVerifyMaxConcurrency = FileVerifyMaxConcurrency;
@@ -377,7 +377,7 @@ namespace YooAsset
}
///
- /// 删除所有缓存的资源文件
+ /// 删除所有解压的资源文件
///
public void DeleteAllBundleFiles()
{
@@ -388,9 +388,9 @@ namespace YooAsset
}
///
- /// 获取默认的解压缓存根目录
+ /// 获取默认的解压根目录
///
- public string GetDefaultUnpackCacheRoot(string packageName)
+ public string GetDefaultUnpackPathRoot(string packageName)
{
string rootDirectory = YooAssetSettingsData.GetYooDefaultCacheRoot();
return PathUtility.Combine(rootDirectory, packageName);
diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/BFSDownloadFileOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/BFSDownloadFileOperation.cs
index 85d519c0..7d6037aa 100644
--- a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/BFSDownloadFileOperation.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/BFSDownloadFileOperation.cs
@@ -14,7 +14,7 @@ namespace YooAsset
}
private readonly BuiltinFileSystem _fileSystem;
- private readonly DownloadFileOptions _options;
+ private readonly FSDownloadFileOptions _options;
private DownloadFileBaseOperation _downloadFileOp;
private ESteps _steps = ESteps.None;
@@ -22,7 +22,7 @@ namespace YooAsset
private float _tryAgainTimer = 0;
private int _failedTryAgain;
- internal BFSDownloadFileOperation(BuiltinFileSystem fileSystem, DownloadFileOptions options) : base(options.Bundle)
+ internal BFSDownloadFileOperation(BuiltinFileSystem fileSystem, FSDownloadFileOptions options) : base(options.Bundle)
{
_fileSystem = fileSystem;
_options = options;
diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/BFSLoadBundleOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/BFSLoadBundleOperation.cs
index f5e18871..390dc9b8 100644
--- a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/BFSLoadBundleOperation.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/BFSLoadBundleOperation.cs
@@ -16,12 +16,12 @@ namespace YooAsset
}
private readonly BuiltinFileSystem _fileSystem;
- private readonly LoadBundleOptions _options;
+ private readonly FCLoadBundleOptions _options;
private FSDownloadFileOperation _unpackFileOp;
private FCLoadBundleOperation _loadBundleOp;
private ESteps _steps = ESteps.None;
- internal BFSLoadBundleOperation(BuiltinFileSystem fileSystem, LoadBundleOptions options)
+ internal BFSLoadBundleOperation(BuiltinFileSystem fileSystem, FCLoadBundleOptions options)
{
_fileSystem = fileSystem;
_options = options;
@@ -73,7 +73,7 @@ namespace YooAsset
{
if (_unpackFileOp == null)
{
- var options = new DownloadFileOptions(_options.Bundle, int.MaxValue);
+ var options = new FSDownloadFileOptions(_options.Bundle, int.MaxValue);
_unpackFileOp = _fileSystem.DownloadFileAsync(options); // 注意:异步任务的开启由调度器统一控制
AddChildOperation(_unpackFileOp);
}
diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/internal/CopyBuiltinFileOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/internal/CopyBuiltinFileOperation.cs
index 8fa25428..3b51b3ba 100644
--- a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/internal/CopyBuiltinFileOperation.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/internal/CopyBuiltinFileOperation.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.IO;
namespace YooAsset
@@ -100,9 +100,17 @@ namespace YooAsset
}
}
}
+ internal override void InternalDispose()
+ {
+ if (_webFileRequestOp != null)
+ {
+ _webFileRequestOp.Dispose();
+ _webFileRequestOp = null;
+ }
+ }
internal override void InternalWaitForCompletion()
{
- //TODO 等待解压本地文件完毕,该操作会挂起主线程!
+ //注意:等待解压本地文件完毕,该操作会挂起主线程!
ExecuteUntilComplete();
}
}
diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/internal/LoadBuiltinPackageManifestOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/internal/LoadBuiltinPackageManifestOperation.cs
index e901aa0b..a8ae6f6b 100644
--- a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/internal/LoadBuiltinPackageManifestOperation.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/internal/LoadBuiltinPackageManifestOperation.cs
@@ -126,6 +126,14 @@ namespace YooAsset
}
}
}
+ internal override void InternalDispose()
+ {
+ if (_webDataRequestOp != null)
+ {
+ _webDataRequestOp.Dispose();
+ _webDataRequestOp = null;
+ }
+ }
internal override string InternalGetDescription()
{
return $"PackageVersion : {_packageVersion} PackageHash : {_packageHash}";
diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/internal/RequestBuiltinPackageHashOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/internal/RequestBuiltinPackageHashOperation.cs
index 8568a472..d3ed542a 100644
--- a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/internal/RequestBuiltinPackageHashOperation.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/internal/RequestBuiltinPackageHashOperation.cs
@@ -94,5 +94,13 @@ namespace YooAsset
}
}
}
+ internal override void InternalDispose()
+ {
+ if (_webTextRequestOp != null)
+ {
+ _webTextRequestOp.Dispose();
+ _webTextRequestOp = null;
+ }
+ }
}
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/internal/RequestBuiltinPackageVersionOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/internal/RequestBuiltinPackageVersionOperation.cs
index 1a197312..970492a4 100644
--- a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/internal/RequestBuiltinPackageVersionOperation.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/internal/RequestBuiltinPackageVersionOperation.cs
@@ -92,5 +92,13 @@ namespace YooAsset
}
}
}
+ internal override void InternalDispose()
+ {
+ if (_webTextRequestOp != null)
+ {
+ _webTextRequestOp.Dispose();
+ _webTextRequestOp = null;
+ }
+ }
}
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/internal/UnpackAndCacheFileOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/internal/UnpackAndCacheFileOperation.cs
index 142627f1..7eaee322 100644
--- a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/internal/UnpackAndCacheFileOperation.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/internal/UnpackAndCacheFileOperation.cs
@@ -19,7 +19,7 @@ namespace YooAsset
private readonly string _builtinFilePath;
private readonly string _tempFilePath;
private CopyBuiltinFileOperation _copyBuiltinFileOp;
- private FCWriteCacheOperation _bundleCacheOp;
+ private FCWriteCacheOperation _writeCacheOp;
private ESteps _steps = ESteps.None;
internal UnpackAndCacheFileOperation(BuiltinFileSystem fileSystem, PackageBundle bundle, string builtinFilePath) : base(bundle, builtinFilePath)
@@ -80,24 +80,24 @@ namespace YooAsset
// 缓存文件
if (_steps == ESteps.CacheFile)
{
- if (_bundleCacheOp == null)
+ if (_writeCacheOp == null)
{
- var options = new WriteCacheOptions();
+ var options = new FCWriteCacheOptions();
options.Bundle = Bundle;
options.FilePath = _tempFilePath;
- _bundleCacheOp = _fileSystem.UnpackFileCache.WriteCacheAsync(options);
- _bundleCacheOp.StartOperation();
- AddChildOperation(_bundleCacheOp);
+ _writeCacheOp = _fileSystem.UnpackFileCache.WriteCacheAsync(options);
+ _writeCacheOp.StartOperation();
+ AddChildOperation(_writeCacheOp);
}
if (IsWaitForCompletion)
- _bundleCacheOp.WaitForCompletion();
+ _writeCacheOp.WaitForCompletion();
- _bundleCacheOp.UpdateOperation();
- if (_bundleCacheOp.IsDone == false)
+ _writeCacheOp.UpdateOperation();
+ if (_writeCacheOp.IsDone == false)
return;
- if (_bundleCacheOp.Status == EOperationStatus.Succeeded)
+ if (_writeCacheOp.Status == EOperationStatus.Succeeded)
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeeded;
@@ -106,7 +106,7 @@ namespace YooAsset
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
- Error = _bundleCacheOp.Error;
+ Error = _writeCacheOp.Error;
}
// 注意:缓存完成后直接删除临时文件
diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/EditorFileSystem.cs b/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/EditorFileSystem.cs
index 99ae7861..79301432 100644
--- a/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/EditorFileSystem.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/EditorFileSystem.cs
@@ -99,12 +99,12 @@ namespace YooAsset
var operation = new FSClearCacheCompleteOperation();
return operation;
}
- public virtual FSDownloadFileOperation DownloadFileAsync(DownloadFileOptions options)
+ public virtual FSDownloadFileOperation DownloadFileAsync(FSDownloadFileOptions options)
{
var downloader = new EFSDownloadFileOperation(this, options);
return downloader;
}
- public virtual FSLoadBundleOperation LoadBundleAsync(LoadBundleOptions options)
+ public virtual FSLoadBundleOperation LoadBundleAsync(FCLoadBundleOptions options)
{
var operation = new EFSLoadBundleOperation(this, options);
return operation;
@@ -232,14 +232,6 @@ namespace YooAsset
}
#region 内部方法
- public string GetBundleFilePath(PackageBundle bundle)
- {
- if (bundle.IncludeMainAssets.Count == 0)
- return string.Empty;
-
- var pacakgeAsset = bundle.IncludeMainAssets[0];
- return pacakgeAsset.AssetPath;
- }
public string GetEditorPackageVersionFilePath()
{
string fileName = YooAssetSettingsData.GetPackageVersionFileName(PackageName);
diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/EditorFileSystemTools.cs b/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/EditorFileSystemTools.cs
new file mode 100644
index 00000000..83e3cd41
--- /dev/null
+++ b/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/EditorFileSystemTools.cs
@@ -0,0 +1,15 @@
+
+namespace YooAsset
+{
+ internal static class EditorFileSystemTools
+ {
+ public static string GetEditorFilePath(PackageBundle bundle)
+ {
+ if (bundle.IncludeMainAssets.Count == 0)
+ return string.Empty;
+
+ var pacakgeAsset = bundle.IncludeMainAssets[0];
+ return pacakgeAsset.AssetPath;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/EditorFileSystemTools.cs.meta b/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/EditorFileSystemTools.cs.meta
new file mode 100644
index 00000000..563584dc
--- /dev/null
+++ b/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/EditorFileSystemTools.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 3c1e490fd2f44974b92bb10d556b28d4
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/Operations/EFSDownloadFileOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/Operations/EFSDownloadFileOperation.cs
index 7bb34fa1..d2732c11 100644
--- a/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/Operations/EFSDownloadFileOperation.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/Operations/EFSDownloadFileOperation.cs
@@ -14,7 +14,7 @@ namespace YooAsset
}
private readonly EditorFileSystem _fileSystem;
- private readonly DownloadFileOptions _options;
+ private readonly FSDownloadFileOptions _options;
private DownloadFileBaseOperation _downloadFileOp;
private ESteps _steps = ESteps.None;
@@ -22,7 +22,7 @@ namespace YooAsset
private float _tryAgainTimer = 0;
private int _failedTryAgain;
- internal EFSDownloadFileOperation(EditorFileSystem fileSystem, DownloadFileOptions options) : base(options.Bundle)
+ internal EFSDownloadFileOperation(EditorFileSystem fileSystem, FSDownloadFileOptions options) : base(options.Bundle)
{
_fileSystem = fileSystem;
_options = options;
@@ -59,7 +59,7 @@ namespace YooAsset
_downloadFileOp = _fileSystem.DownloadScheduler.TryGetDownloadFile(Bundle);
if (_downloadFileOp == null)
{
- string editorFilePath = _fileSystem.GetBundleFilePath(Bundle);
+ string editorFilePath = EditorFileSystemTools.GetEditorFilePath(Bundle);
_downloadFileOp = new SimulateAndCacheFileOperation(_fileSystem, Bundle, editorFilePath);
_fileSystem.DownloadScheduler.AddDownloadFile(_downloadFileOp);
}
diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/Operations/EFSLoadBundleOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/Operations/EFSLoadBundleOperation.cs
index 889ab172..b68da20b 100644
--- a/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/Operations/EFSLoadBundleOperation.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/Operations/EFSLoadBundleOperation.cs
@@ -15,12 +15,12 @@ namespace YooAsset
}
private readonly EditorFileSystem _fileSystem;
- private readonly LoadBundleOptions _options;
+ private readonly FCLoadBundleOptions _options;
private FSDownloadFileOperation _downloadFileOp;
private FCLoadBundleOperation _loadBundleOp;
private ESteps _steps = ESteps.None;
- internal EFSLoadBundleOperation(EditorFileSystem fileSystem, LoadBundleOptions options)
+ internal EFSLoadBundleOperation(EditorFileSystem fileSystem, FCLoadBundleOptions options)
{
_fileSystem = fileSystem;
_options = options;
@@ -63,7 +63,7 @@ namespace YooAsset
{
if (_downloadFileOp == null)
{
- DownloadFileOptions options = new DownloadFileOptions(_options.Bundle, int.MaxValue);
+ FSDownloadFileOptions options = new FSDownloadFileOptions(_options.Bundle, int.MaxValue);
_downloadFileOp = _fileSystem.DownloadFileAsync(options);
_downloadFileOp.StartOperation();
AddChildOperation(_downloadFileOp);
diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/Operations/internal/SimulateAndCacheFileOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/Operations/internal/SimulateAndCacheFileOperation.cs
index 3fda45b4..a9d3f7dc 100644
--- a/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/Operations/internal/SimulateAndCacheFileOperation.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/Operations/internal/SimulateAndCacheFileOperation.cs
@@ -60,9 +60,6 @@ namespace YooAsset
Status = EOperationStatus.Failed;
Error = _downloadRequest.Error;
}
-
- // 最终释放请求器
- _downloadRequest.Dispose();
}
// 缓存文件
@@ -70,7 +67,7 @@ namespace YooAsset
{
if (_writeCacheOp == null)
{
- var options = new WriteCacheOptions();
+ var options = new FCWriteCacheOptions();
options.Bundle = Bundle;
options.FilePath = Url;
_writeCacheOp = _fileSystem.FileCache.WriteCacheAsync(options);
@@ -95,10 +92,13 @@ namespace YooAsset
}
}
}
- internal override void InternalAbort()
+ internal override void InternalDispose()
{
if (_downloadRequest != null)
+ {
_downloadRequest.Dispose();
+ _downloadRequest = null;
+ }
}
internal override void InternalWaitForCompletion()
{
diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/DownloadAndCacheFileOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/DownloadAndCacheFileOperation.cs
index 3d19fd7f..380e2d45 100644
--- a/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/DownloadAndCacheFileOperation.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/DownloadAndCacheFileOperation.cs
@@ -2,6 +2,9 @@ using System.IO;
namespace YooAsset
{
+ ///
+ /// TODO: 下载和缓存不能拆分,因为FSDownloadFileOperation下载任务并不唯一,会造成写入缓存冲突。
+ ///
internal sealed class DownloadAndCacheFileOperation : DownloadFileBaseOperation
{
private enum ESteps
@@ -79,9 +82,6 @@ namespace YooAsset
// 在遇到特殊错误的时候删除文件
if (_enableResume)
ClearTempFileWhenError(_downloadRequest.HttpCode);
-
- // 最终释放请求器
- _downloadRequest.Dispose();
}
// 缓存文件
@@ -89,7 +89,7 @@ namespace YooAsset
{
if (_writeCacheOp == null)
{
- var options = new WriteCacheOptions();
+ var options = new FCWriteCacheOptions();
options.Bundle = Bundle;
options.FilePath = _tempFilePath;
_writeCacheOp = _fileSystem.FileCache.WriteCacheAsync(options);
@@ -118,10 +118,13 @@ namespace YooAsset
File.Delete(_tempFilePath);
}
}
- internal override void InternalAbort()
+ internal override void InternalDispose()
{
if (_downloadRequest != null)
+ {
_downloadRequest.Dispose();
+ _downloadRequest = null;
+ }
}
internal override void InternalWaitForCompletion()
{
diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/DownloadPackageHashOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/DownloadPackageHashOperation.cs
index f4e9dbf6..d1c63b7b 100644
--- a/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/DownloadPackageHashOperation.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/DownloadPackageHashOperation.cs
@@ -80,6 +80,14 @@ namespace YooAsset
}
}
}
+ internal override void InternalDispose()
+ {
+ if (_webFileRequestOp != null)
+ {
+ _webFileRequestOp.Dispose();
+ _webFileRequestOp = null;
+ }
+ }
private string GetWebRequestURL(string fileName)
{
diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/DownloadPackageManifestOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/DownloadPackageManifestOperation.cs
index 72869c6a..47a45dc7 100644
--- a/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/DownloadPackageManifestOperation.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/DownloadPackageManifestOperation.cs
@@ -80,6 +80,14 @@ namespace YooAsset
}
}
}
+ internal override void InternalDispose()
+ {
+ if (_webFileRequestOp != null)
+ {
+ _webFileRequestOp.Dispose();
+ _webFileRequestOp = null;
+ }
+ }
private string GetDownloadRequestURL(string fileName)
{
diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/ImportAndCacheFileOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/ImportAndCacheFileOperation.cs
index 70e1ee07..d0b3f192 100644
--- a/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/ImportAndCacheFileOperation.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/ImportAndCacheFileOperation.cs
@@ -66,7 +66,7 @@ namespace YooAsset
{
if (_bundleCacheOp == null)
{
- var options = new WriteCacheOptions();
+ var options = new FCWriteCacheOptions();
options.Bundle = Bundle;
options.FilePath = _tempFilePath;
_bundleCacheOp = _fileSystem.FileCache.WriteCacheAsync(options);
diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/RequestRemotePackageVersionOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/RequestRemotePackageVersionOperation.cs
index 4468fa8c..a674b47c 100644
--- a/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/RequestRemotePackageVersionOperation.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/RequestRemotePackageVersionOperation.cs
@@ -79,6 +79,14 @@ namespace YooAsset
}
}
}
+ internal override void InternalDispose()
+ {
+ if (_webTextRequestOp != null)
+ {
+ _webTextRequestOp.Dispose();
+ _webTextRequestOp = null;
+ }
+ }
private string GetWebRequestURL(string fileName)
{
diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSDownloadFileOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSDownloadFileOperation.cs
index 03d6dd0c..85e401e6 100644
--- a/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSDownloadFileOperation.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSDownloadFileOperation.cs
@@ -14,7 +14,7 @@ namespace YooAsset
}
private readonly SandboxFileSystem _fileSystem;
- private readonly DownloadFileOptions _options;
+ private readonly FSDownloadFileOptions _options;
private DownloadFileBaseOperation _downloadFileOp;
private ESteps _steps = ESteps.None;
@@ -23,7 +23,7 @@ namespace YooAsset
private float _tryAgainTimer = 0;
private int _failedTryAgain;
- internal SFSDownloadFileOperation(SandboxFileSystem fileSystem, DownloadFileOptions options) : base(options.Bundle)
+ internal SFSDownloadFileOperation(SandboxFileSystem fileSystem, FSDownloadFileOptions options) : base(options.Bundle)
{
_fileSystem = fileSystem;
_options = options;
diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSLoadBundleOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSLoadBundleOperation.cs
index 73717eb8..ee40d4df 100644
--- a/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSLoadBundleOperation.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSLoadBundleOperation.cs
@@ -15,12 +15,12 @@ namespace YooAsset
}
private readonly SandboxFileSystem _fileSystem;
- private readonly LoadBundleOptions _options;
+ private readonly FCLoadBundleOptions _options;
private FSDownloadFileOperation _downloadFileOp;
private FCLoadBundleOperation _loadBundleOp;
private ESteps _steps = ESteps.None;
- internal SFSLoadBundleOperation(SandboxFileSystem fileSystem, LoadBundleOptions options)
+ internal SFSLoadBundleOperation(SandboxFileSystem fileSystem, FCLoadBundleOptions options)
{
_fileSystem = fileSystem;
_options = options;
@@ -73,7 +73,7 @@ namespace YooAsset
{
if (_downloadFileOp == null)
{
- DownloadFileOptions options = new DownloadFileOptions(_options.Bundle, int.MaxValue);
+ FSDownloadFileOptions options = new FSDownloadFileOptions(_options.Bundle, int.MaxValue);
_downloadFileOp = _fileSystem.DownloadFileAsync(options); // 注意:异步任务的开启由调度器统一控制
AddChildOperation(_downloadFileOp);
}
diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/SandboxFileSystem.cs b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/SandboxFileSystem.cs
index dc5202e2..43f417e4 100644
--- a/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/SandboxFileSystem.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/SandboxFileSystem.cs
@@ -156,12 +156,12 @@ namespace YooAsset
return operation;
}
}
- public virtual FSDownloadFileOperation DownloadFileAsync(DownloadFileOptions options)
+ public virtual FSDownloadFileOperation DownloadFileAsync(FSDownloadFileOptions options)
{
var downloader = new SFSDownloadFileOperation(this, options);
return downloader;
}
- public virtual FSLoadBundleOperation LoadBundleAsync(LoadBundleOptions options)
+ public virtual FSLoadBundleOperation LoadBundleAsync(FCLoadBundleOptions options)
{
var operation = new SFSLoadBundleOperation(this, options);
return operation;
diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/Internal/LoadWebPackageManifestOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/Internal/LoadWebPackageManifestOperation.cs
deleted file mode 100644
index e0c1fe11..00000000
--- a/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/Internal/LoadWebPackageManifestOperation.cs
+++ /dev/null
@@ -1,136 +0,0 @@
-using YooAsset;
-
-internal class LoadWebPackageManifestOperation : AsyncOperationBase
-{
- private enum ESteps
- {
- None,
- RequestFileData,
- VerifyFileData,
- LoadManifest,
- Done,
- }
-
- private readonly IManifestDecryptor _manifestDecryptor;
- private readonly IRemoteServices _remoteServices;
- private readonly IDownloadBackend _downloadBackend;
- private readonly string _packageName;
- private readonly string _packageVersion;
- private readonly string _packageHash;
- private readonly int _timeout;
- private IDownloadBytesRequest _webDataRequestOp;
- private DeserializeManifestOperation _deserializer;
- private int _requestCount = 0;
- private ESteps _steps = ESteps.None;
-
- ///
- /// 包裹清单
- ///
- public PackageManifest Manifest { private set; get; }
-
-
- internal LoadWebPackageManifestOperation(IManifestDecryptor manifestDecryptor, IRemoteServices remoteServices, IDownloadBackend downloadBackend,
- string packageName, string packageVersion, string packageHash, int timeout)
- {
- _manifestDecryptor = manifestDecryptor;
- _remoteServices = remoteServices;
- _downloadBackend = downloadBackend;
- _packageName = packageName;
- _packageVersion = packageVersion;
- _packageHash = packageHash;
- _timeout = timeout;
- }
- internal override void InternalStart()
- {
- _requestCount = DownloadFailureCounter.GetFailureCount(_packageName, nameof(LoadWebPackageManifestOperation));
- _steps = ESteps.RequestFileData;
- }
- internal override void InternalUpdate()
- {
- if (_steps == ESteps.None || _steps == ESteps.Done)
- return;
-
- if (_steps == ESteps.RequestFileData)
- {
- if (_webDataRequestOp == null)
- {
- string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_packageName, _packageVersion);
- string url = GetRequestURL(fileName);
- var args = new DownloadDataRequestArgs(url, _timeout, 0);
- _webDataRequestOp = _downloadBackend.CreateBytesRequest(args);
- _webDataRequestOp.SendRequest();
- }
-
- Progress = _webDataRequestOp.DownloadProgress;
- if (_webDataRequestOp.IsDone == false)
- return;
-
- if (_webDataRequestOp.Status == EDownloadRequestStatus.Succeeded)
- {
- _steps = ESteps.VerifyFileData;
- }
- else
- {
- _steps = ESteps.Done;
- Status = EOperationStatus.Failed;
- Error = _webDataRequestOp.Error;
- DownloadFailureCounter.RecordFailure(_packageName, nameof(LoadWebPackageManifestOperation));
- }
- }
-
- if (_steps == ESteps.VerifyFileData)
- {
- if (PackageManifestTools.VerifyManifestData(_webDataRequestOp.Result, _packageHash))
- {
- _steps = ESteps.LoadManifest;
- }
- else
- {
- _steps = ESteps.Done;
- Status = EOperationStatus.Failed;
- Error = "Failed to verify web package manifest file.";
- }
- }
-
- if (_steps == ESteps.LoadManifest)
- {
- if (_deserializer == null)
- {
- _deserializer = new DeserializeManifestOperation(_manifestDecryptor, _webDataRequestOp.Result);
- _deserializer.StartOperation();
- AddChildOperation(_deserializer);
- }
-
- _deserializer.UpdateOperation();
- Progress = _deserializer.Progress;
- if (_deserializer.IsDone == false)
- return;
-
- if (_deserializer.Status == EOperationStatus.Succeeded)
- {
- _steps = ESteps.Done;
- Manifest = _deserializer.Manifest;
- Status = EOperationStatus.Succeeded;
- }
- else
- {
- _steps = ESteps.Done;
- Status = EOperationStatus.Failed;
- Error = _deserializer.Error;
- }
- }
- }
- internal override string InternalGetDescription()
- {
- return $"PackageVersion : {_packageVersion} PackageHash : {_packageHash}";
- }
-
- private string GetRequestURL(string fileName)
- {
- // 轮流返回请求地址
- if (_requestCount % 2 == 0)
- return _remoteServices.GetRemoteMainURL(fileName);
- else
- return _remoteServices.GetRemoteFallbackURL(fileName);
- }
-}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/Internal/RequestWebPackageHashOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/Internal/RequestWebPackageHashOperation.cs
deleted file mode 100644
index 5f018531..00000000
--- a/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/Internal/RequestWebPackageHashOperation.cs
+++ /dev/null
@@ -1,93 +0,0 @@
-using YooAsset;
-
-internal class RequestWebPackageHashOperation : AsyncOperationBase
-{
- private enum ESteps
- {
- None,
- RequestPackageHash,
- Done,
- }
-
- private readonly IRemoteServices _remoteServices;
- private readonly IDownloadBackend _downloadBackend;
- private readonly string _packageName;
- private readonly string _packageVersion;
- private readonly int _timeout;
- private IDownloadTextRequest _webTextRequestOp;
- private int _requestCount = 0;
- private ESteps _steps = ESteps.None;
-
- ///
- /// 包裹哈希值
- ///
- public string PackageHash { private set; get; }
-
-
- public RequestWebPackageHashOperation(IRemoteServices remoteServices, IDownloadBackend downloadBackend, string packageName, string packageVersion, int timeout)
- {
- _remoteServices = remoteServices;
- _downloadBackend = downloadBackend;
- _packageName = packageName;
- _packageVersion = packageVersion;
- _timeout = timeout;
- }
- internal override void InternalStart()
- {
- _requestCount = DownloadFailureCounter.GetFailureCount(_packageName, nameof(RequestWebPackageHashOperation));
- _steps = ESteps.RequestPackageHash;
- }
- internal override void InternalUpdate()
- {
- if (_steps == ESteps.None || _steps == ESteps.Done)
- return;
-
- if (_steps == ESteps.RequestPackageHash)
- {
- if (_webTextRequestOp == null)
- {
- string fileName = YooAssetSettingsData.GetPackageHashFileName(_packageName, _packageVersion);
- string url = GetRequestURL(fileName);
- var args = new DownloadDataRequestArgs(url, _timeout, 0);
- _webTextRequestOp = _downloadBackend.CreateTextRequest(args);
- _webTextRequestOp.SendRequest();
- }
-
- Progress = _webTextRequestOp.DownloadProgress;
- if (_webTextRequestOp.IsDone == false)
- return;
-
- if (_webTextRequestOp.Status == EDownloadRequestStatus.Succeeded)
- {
- PackageHash = _webTextRequestOp.Result;
- if (string.IsNullOrEmpty(PackageHash))
- {
- _steps = ESteps.Done;
- Status = EOperationStatus.Failed;
- Error = $"Web package hash file content is empty.";
- }
- else
- {
- _steps = ESteps.Done;
- Status = EOperationStatus.Succeeded;
- }
- }
- else
- {
- _steps = ESteps.Done;
- Status = EOperationStatus.Failed;
- Error = _webTextRequestOp.Error;
- DownloadFailureCounter.RecordFailure(_packageName, nameof(RequestWebPackageHashOperation));
- }
- }
- }
-
- private string GetRequestURL(string fileName)
- {
- // 轮流返回请求地址
- if (_requestCount % 2 == 0)
- return _remoteServices.GetRemoteMainURL(fileName);
- else
- return _remoteServices.GetRemoteFallbackURL(fileName);
- }
-}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/Internal/RequestWebPackageVersionOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/Internal/RequestWebPackageVersionOperation.cs
deleted file mode 100644
index cb71ea34..00000000
--- a/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/Internal/RequestWebPackageVersionOperation.cs
+++ /dev/null
@@ -1,101 +0,0 @@
-using YooAsset;
-
-internal class RequestWebPackageVersionOperation : AsyncOperationBase
-{
- private enum ESteps
- {
- None,
- RequestPackageVersion,
- Done,
- }
-
- private readonly IRemoteServices _remoteServices;
- private readonly IDownloadBackend _downloadBackend;
- private readonly string _packageName;
- private readonly bool _appendTimeTicks;
- private readonly int _timeout;
- private IDownloadTextRequest _webTextRequestOp;
- private int _requestCount = 0;
- private ESteps _steps = ESteps.None;
-
- ///
- /// 包裹版本
- ///
- public string PackageVersion { private set; get; }
-
-
- public RequestWebPackageVersionOperation(IRemoteServices remoteServices, IDownloadBackend downloadBackend, string packageName, bool appendTimeTicks, int timeout)
- {
- _remoteServices = remoteServices;
- _downloadBackend = downloadBackend;
- _packageName = packageName;
- _appendTimeTicks = appendTimeTicks;
- _timeout = timeout;
- }
- internal override void InternalStart()
- {
- _requestCount = DownloadFailureCounter.GetFailureCount(_packageName, nameof(RequestWebPackageVersionOperation));
- _steps = ESteps.RequestPackageVersion;
- }
- internal override void InternalUpdate()
- {
- if (_steps == ESteps.None || _steps == ESteps.Done)
- return;
-
- if (_steps == ESteps.RequestPackageVersion)
- {
- if (_webTextRequestOp == null)
- {
- string fileName = YooAssetSettingsData.GetPackageVersionFileName(_packageName);
- string url = GetRequestURL(fileName);
- var args = new DownloadDataRequestArgs(url, _timeout, 0);
- _webTextRequestOp = _downloadBackend.CreateTextRequest(args);
- _webTextRequestOp.SendRequest();
- }
-
- Progress = _webTextRequestOp.DownloadProgress;
- if (_webTextRequestOp.IsDone == false)
- return;
-
- if (_webTextRequestOp.Status == EDownloadRequestStatus.Succeeded)
- {
- PackageVersion = _webTextRequestOp.Result;
- if (string.IsNullOrEmpty(PackageVersion))
- {
- _steps = ESteps.Done;
- Status = EOperationStatus.Failed;
- Error = $"Web package version file content is empty.";
- }
- else
- {
- _steps = ESteps.Done;
- Status = EOperationStatus.Succeeded;
- }
- }
- else
- {
- _steps = ESteps.Done;
- Status = EOperationStatus.Failed;
- Error = _webTextRequestOp.Error;
- DownloadFailureCounter.RecordFailure(_packageName, nameof(RequestWebPackageVersionOperation));
- }
- }
- }
-
- private string GetRequestURL(string fileName)
- {
- string url;
-
- // 轮流返回请求地址
- if (_requestCount % 2 == 0)
- url = _remoteServices.GetRemoteMainURL(fileName);
- else
- url = _remoteServices.GetRemoteFallbackURL(fileName);
-
- // 在URL末尾添加时间戳
- if (_appendTimeTicks)
- return $"{url}?{System.DateTime.UtcNow.Ticks}";
- else
- return url;
- }
-}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/WRFSLoadBundleOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/WRFSLoadBundleOperation.cs
index 03caccaf..78e27fd4 100644
--- a/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/WRFSLoadBundleOperation.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/WRFSLoadBundleOperation.cs
@@ -11,11 +11,11 @@ namespace YooAsset
}
private readonly WebRemoteFileSystem _fileSystem;
- private readonly LoadBundleOptions _options;
+ private readonly FCLoadBundleOptions _options;
private FCLoadBundleOperation _loadBundleOp;
private ESteps _steps = ESteps.None;
- internal WRFSLoadBundleOperation(WebRemoteFileSystem fileSystem, LoadBundleOptions options)
+ internal WRFSLoadBundleOperation(WebRemoteFileSystem fileSystem, FCLoadBundleOptions options)
{
_fileSystem = fileSystem;
_options = options;
diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/WRFSLoadManifestOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/WRFSLoadManifestOperation.cs
index baad040d..a3e89942 100644
--- a/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/WRFSLoadManifestOperation.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/WRFSLoadManifestOperation.cs
@@ -38,7 +38,13 @@ namespace YooAsset
{
if (_requestWebPackageHashOp == null)
{
- _requestWebPackageHashOp = new RequestWebPackageHashOperation(_fileSystem.RemoteServices, _fileSystem.DownloadBackend, _fileSystem.PackageName, _packageVersion, _timeout);
+ var options = new RequestWebPackageHashOptions();
+ options.PackageName = _fileSystem.PackageName;
+ options.PackageVersion = _packageVersion;
+ options.Timeout = _timeout;
+ options.RemoteServices = _fileSystem.RemoteServices;
+ options.DownloadBackend = _fileSystem.DownloadBackend;
+ _requestWebPackageHashOp = new RequestWebPackageHashOperation(options);
_requestWebPackageHashOp.StartOperation();
AddChildOperation(_requestWebPackageHashOp);
}
@@ -63,12 +69,15 @@ namespace YooAsset
{
if (_loadWebPackageManifestOp == null)
{
- string packageHash = _requestWebPackageHashOp.PackageHash;
- string packageName = _fileSystem.PackageName;
- var manifestServices = _fileSystem.ManifestDecryptor;
- var remoteServices = _fileSystem.RemoteServices;
- var downloadBackend = _fileSystem.DownloadBackend;
- _loadWebPackageManifestOp = new LoadWebPackageManifestOperation(manifestServices, remoteServices, downloadBackend, packageName, _packageVersion, packageHash, _timeout);
+ var options = new LoadWebPackageManifestOptions();
+ options.PackageName = _fileSystem.PackageName;
+ options.PackageVersion = _packageVersion;
+ options.PackageHash = _requestWebPackageHashOp.PackageHash;
+ options.Timeout = _timeout;
+ options.RemoteServices = _fileSystem.RemoteServices;
+ options.ManifestDecryptor = _fileSystem.ManifestDecryptor;
+ options.DownloadBackend = _fileSystem.DownloadBackend;
+ _loadWebPackageManifestOp = new LoadWebPackageManifestOperation(options);
_loadWebPackageManifestOp.StartOperation();
AddChildOperation(_loadWebPackageManifestOp);
}
diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/WRFSRequestVersionOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/WRFSRequestVersionOperation.cs
index 05335ff8..ffdaf3cd 100644
--- a/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/WRFSRequestVersionOperation.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/WRFSRequestVersionOperation.cs
@@ -36,7 +36,13 @@ namespace YooAsset
{
if (_requestWebPackageVersionOp == null)
{
- _requestWebPackageVersionOp = new RequestWebPackageVersionOperation(_fileSystem.RemoteServices, _fileSystem.DownloadBackend, _fileSystem.PackageName, _appendTimeTicks, _timeout);
+ var options = new RequestWebPackageVersionOptions();
+ options.PackageName = _fileSystem.PackageName;
+ options.AppendTimeTicks = _appendTimeTicks;
+ options.Timeout = _timeout;
+ options.RemoteServices = _fileSystem.RemoteServices;
+ options.DownloadBackend = _fileSystem.DownloadBackend;
+ _requestWebPackageVersionOp = new RequestWebPackageVersionOperation(options);
_requestWebPackageVersionOp.StartOperation();
AddChildOperation(_requestWebPackageVersionOp);
}
diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/WebRemoteFileSystem.cs b/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/WebRemoteFileSystem.cs
index d4b69ef6..c8bd7f88 100644
--- a/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/WebRemoteFileSystem.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/WebRemoteFileSystem.cs
@@ -6,7 +6,7 @@ using UnityEngine;
namespace YooAsset
{
///
- /// Web文件系统
+ /// Web远端文件系统
///
internal class WebRemoteFileSystem : IFileSystem
{
@@ -41,6 +41,11 @@ namespace YooAsset
///
public int DownloadWatchDogTimeout { private set; get; } = 0;
+ ///
+ /// 自定义参数:下载的资源包数据的校验级别
+ ///
+ public EFileVerifyLevel DownloadVerifyLevel { private set; get; } = EFileVerifyLevel.Middle;
+
///
/// 自定义参数:远程服务接口的实例类(支持跨域下载)
///
@@ -81,11 +86,11 @@ namespace YooAsset
var operation = new FSClearCacheCompleteOperation();
return operation;
}
- public virtual FSDownloadFileOperation DownloadFileAsync(DownloadFileOptions options)
+ public virtual FSDownloadFileOperation DownloadFileAsync(FSDownloadFileOptions options)
{
throw new System.NotImplementedException();
}
- public virtual FSLoadBundleOperation LoadBundleAsync(LoadBundleOptions options)
+ public virtual FSLoadBundleOperation LoadBundleAsync(FCLoadBundleOptions options)
{
var operation = new WRFSLoadBundleOperation(this, options);
return operation;
@@ -110,6 +115,10 @@ namespace YooAsset
int convertValue = Convert.ToInt32(value);
DownloadWatchDogTimeout = Mathf.Clamp(convertValue, 0, int.MaxValue);
}
+ else if (name == FileSystemParametersDefine.FILE_VERIFY_LEVEL)
+ {
+ DownloadVerifyLevel = (EFileVerifyLevel)value;
+ }
else if (name == FileSystemParametersDefine.REMOTE_SERVICES)
{
RemoteServices = (IRemoteServices)value;
@@ -139,6 +148,7 @@ namespace YooAsset
var cacheConfig = new WebRemoteFileCache.CacheConfig();
cacheConfig.WatchdogTimeout = DownloadWatchDogTimeout;
cacheConfig.DisableUnityWebCache = DisableUnityWebCache;
+ cacheConfig.DownloadVerifyLevel = DownloadVerifyLevel;
cacheConfig.AssetBundleDecryptor = AssetBundleDecryptor;
cacheConfig.RemoteServices = RemoteServices;
cacheConfig.DownloadBackend = DownloadBackend;
diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/Operations/WSFSLoadBundleOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/Operations/WSFSLoadBundleOperation.cs
index b94b5d57..20fa9f82 100644
--- a/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/Operations/WSFSLoadBundleOperation.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/Operations/WSFSLoadBundleOperation.cs
@@ -11,11 +11,11 @@ namespace YooAsset
}
private readonly WebServerFileSystem _fileSystem;
- private readonly LoadBundleOptions _options;
+ private readonly FCLoadBundleOptions _options;
private FCLoadBundleOperation _loadBundleOp;
private ESteps _steps = ESteps.None;
- internal WSFSLoadAssetBundleOperation(WebServerFileSystem fileSystem, LoadBundleOptions options)
+ internal WSFSLoadAssetBundleOperation(WebServerFileSystem fileSystem, FCLoadBundleOptions options)
{
_fileSystem = fileSystem;
_options = options;
diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/Operations/internal/LoadWebServerPackageManifestOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/Operations/internal/LoadWebServerPackageManifestOperation.cs
index 6ff921d3..f4d22975 100644
--- a/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/Operations/internal/LoadWebServerPackageManifestOperation.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/Operations/internal/LoadWebServerPackageManifestOperation.cs
@@ -110,6 +110,14 @@ namespace YooAsset
}
}
}
+ internal override void InternalDispose()
+ {
+ if (_webDataRequestOp != null)
+ {
+ _webDataRequestOp.Dispose();
+ _webDataRequestOp = null;
+ }
+ }
internal override string InternalGetDescription()
{
return $"PackageVersion : {_packageVersion} PackageHash : {_packageHash}";
diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/Operations/internal/RequestWebServerPackageHashOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/Operations/internal/RequestWebServerPackageHashOperation.cs
index 09bf153b..eb243ffc 100644
--- a/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/Operations/internal/RequestWebServerPackageHashOperation.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/Operations/internal/RequestWebServerPackageHashOperation.cs
@@ -75,5 +75,13 @@ namespace YooAsset
}
}
}
+ internal override void InternalDispose()
+ {
+ if (_webTextRequestOp != null)
+ {
+ _webTextRequestOp.Dispose();
+ _webTextRequestOp = null;
+ }
+ }
}
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/Operations/internal/RequestWebServerPackageVersionOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/Operations/internal/RequestWebServerPackageVersionOperation.cs
index 28c3ad8b..fa455535 100644
--- a/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/Operations/internal/RequestWebServerPackageVersionOperation.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/Operations/internal/RequestWebServerPackageVersionOperation.cs
@@ -72,5 +72,13 @@ namespace YooAsset
}
}
}
+ internal override void InternalDispose()
+ {
+ if (_webTextRequestOp != null)
+ {
+ _webTextRequestOp.Dispose();
+ _webTextRequestOp = null;
+ }
+ }
}
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/WebServerFileSystem.cs b/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/WebServerFileSystem.cs
index e4388762..39eaf4ca 100644
--- a/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/WebServerFileSystem.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/WebServerFileSystem.cs
@@ -6,7 +6,7 @@ using UnityEngine;
namespace YooAsset
{
///
- /// Web文件系统
+ /// Web服务端文件系统
///
internal class WebServerFileSystem : IFileSystem
{
@@ -44,6 +44,11 @@ namespace YooAsset
///
public int DownloadWatchDogTimeout { private set; get; } = 0;
+ ///
+ /// 自定义参数:下载的资源包数据的校验级别
+ ///
+ public EFileVerifyLevel DownloadVerifyLevel { private set; get; } = EFileVerifyLevel.Middle;
+
///
/// 自定义参数:AssetBundle 解密器
///
@@ -79,11 +84,11 @@ namespace YooAsset
var operation = new FSClearCacheCompleteOperation();
return operation;
}
- public virtual FSDownloadFileOperation DownloadFileAsync(DownloadFileOptions options)
+ public virtual FSDownloadFileOperation DownloadFileAsync(FSDownloadFileOptions options)
{
throw new System.NotImplementedException();
}
- public virtual FSLoadBundleOperation LoadBundleAsync(LoadBundleOptions options)
+ public virtual FSLoadBundleOperation LoadBundleAsync(FCLoadBundleOptions options)
{
var operation = new WSFSLoadAssetBundleOperation(this, options);
return operation;
@@ -108,6 +113,10 @@ namespace YooAsset
int convertValue = Convert.ToInt32(value);
DownloadWatchDogTimeout = Mathf.Clamp(convertValue, 0, int.MaxValue);
}
+ else if (name == FileSystemParametersDefine.FILE_VERIFY_LEVEL)
+ {
+ DownloadVerifyLevel = (EFileVerifyLevel)value;
+ }
else if (name == FileSystemParametersDefine.ASSETBUNDLE_DECRYPTOR)
{
AssetBundleDecryptor = (IBundleDecryptor)value;
@@ -138,8 +147,9 @@ namespace YooAsset
var cacheConfig = new WebServerFileCache.CacheConfig();
cacheConfig.WatchdogTimeout = DownloadWatchDogTimeout;
cacheConfig.DisableUnityWebCache = DisableUnityWebCache;
- cacheConfig.DownloadBackend = DownloadBackend;
+ cacheConfig.DownloadVerifyLevel = DownloadVerifyLevel;
cacheConfig.AssetBundleDecryptor = AssetBundleDecryptor;
+ cacheConfig.DownloadBackend = DownloadBackend;
FileCache = new WebServerFileCache(packageName, _packageRoot, cacheConfig);
}
public virtual void OnDestroy()
diff --git a/Assets/YooAsset/Runtime/ResourcePackage/BundleInfo.cs b/Assets/YooAsset/Runtime/ResourcePackage/BundleInfo.cs
index ee577e25..a25d87dd 100644
--- a/Assets/YooAsset/Runtime/ResourcePackage/BundleInfo.cs
+++ b/Assets/YooAsset/Runtime/ResourcePackage/BundleInfo.cs
@@ -46,7 +46,7 @@ namespace YooAsset
/// 返回资源包加载操作对象
public FSLoadBundleOperation CreateBundleLoader()
{
- var options = new LoadBundleOptions(Bundle);
+ var options = new FCLoadBundleOptions(Bundle);
return _fileSystem.LoadBundleAsync(options);
}
@@ -57,7 +57,7 @@ namespace YooAsset
/// 返回文件下载操作对象
public FSDownloadFileOperation CreateBundleDownloader(int retryCount)
{
- var options = new DownloadFileOptions(Bundle, retryCount, _importFilePath);
+ var options = new FSDownloadFileOptions(Bundle, retryCount, _importFilePath);
return _fileSystem.DownloadFileAsync(options);
}
diff --git a/Assets/YooAsset/Runtime/ResourcePackage/Operations/Internal/DeserializeManifestOperation.cs b/Assets/YooAsset/Runtime/ResourcePackage/Operations/Internal/DeserializeManifestOperation.cs
index 2af8483f..afa3f03d 100644
--- a/Assets/YooAsset/Runtime/ResourcePackage/Operations/Internal/DeserializeManifestOperation.cs
+++ b/Assets/YooAsset/Runtime/ResourcePackage/Operations/Internal/DeserializeManifestOperation.cs
@@ -75,7 +75,7 @@ namespace YooAsset
// 读取文件标记
uint fileSign = _buffer.ReadUInt32();
- if (fileSign != PackageManifestDefine.FileSign)
+ if (fileSign != PackageManifestDefine.FileSignature)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
diff --git a/Assets/YooAsset/Runtime/ResourcePackage/PackageManifestDefine.cs b/Assets/YooAsset/Runtime/ResourcePackage/PackageManifestDefine.cs
index 8553cb8b..16d79c83 100644
--- a/Assets/YooAsset/Runtime/ResourcePackage/PackageManifestDefine.cs
+++ b/Assets/YooAsset/Runtime/ResourcePackage/PackageManifestDefine.cs
@@ -9,12 +9,12 @@ namespace YooAsset
///
/// 文件极限大小(100MB)
///
- public const int FileMaxSize = 104857600;
+ public const int MaxFileSize = 104857600;
///
/// 文件头标记
///
- public const uint FileSign = 0x594F4F;
+ public const uint FileSignature = 0x594F4F;
///
/// 当前文件格式版本
diff --git a/Assets/YooAsset/Runtime/ResourcePackage/PackageManifestTools.cs b/Assets/YooAsset/Runtime/ResourcePackage/PackageManifestTools.cs
index ce224aa1..1c0848dd 100644
--- a/Assets/YooAsset/Runtime/ResourcePackage/PackageManifestTools.cs
+++ b/Assets/YooAsset/Runtime/ResourcePackage/PackageManifestTools.cs
@@ -61,10 +61,10 @@ namespace YooAsset
using (FileStream fs = new FileStream(savePath, FileMode.Create))
{
// 创建缓存器
- BufferWriter buffer = new BufferWriter(PackageManifestDefine.FileMaxSize);
+ BufferWriter buffer = new BufferWriter(PackageManifestDefine.MaxFileSize);
// 写入文件标记
- buffer.WriteUInt32(PackageManifestDefine.FileSign);
+ buffer.WriteUInt32(PackageManifestDefine.FileSignature);
// 写入文件版本
buffer.WriteUTF8(manifest.FileVersion);
diff --git a/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/Operations/Internal.meta b/Assets/YooAsset/Runtime/Utility/Utilities.meta
similarity index 77%
rename from Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/Operations/Internal.meta
rename to Assets/YooAsset/Runtime/Utility/Utilities.meta
index 86d7187d..b8fa5b21 100644
--- a/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/Operations/Internal.meta
+++ b/Assets/YooAsset/Runtime/Utility/Utilities.meta
@@ -1,5 +1,5 @@
fileFormatVersion: 2
-guid: 0dd4916e71be0934883f2fc404dd18fc
+guid: 1a2fe6a5da4d78a4cb47249bb851c6f1
folderAsset: yes
DefaultImporter:
externalObjects: {}
diff --git a/Assets/YooAsset/Runtime/Utility/FileUtility.cs b/Assets/YooAsset/Runtime/Utility/Utilities/FileUtility.cs
similarity index 97%
rename from Assets/YooAsset/Runtime/Utility/FileUtility.cs
rename to Assets/YooAsset/Runtime/Utility/Utilities/FileUtility.cs
index 1ee12edd..dc08fa8b 100644
--- a/Assets/YooAsset/Runtime/Utility/FileUtility.cs
+++ b/Assets/YooAsset/Runtime/Utility/Utilities/FileUtility.cs
@@ -17,6 +17,7 @@ namespace YooAsset
{
if (File.Exists(filePath) == false)
return null;
+
return File.ReadAllText(filePath, Encoding.UTF8);
}
@@ -27,6 +28,7 @@ namespace YooAsset
{
if (File.Exists(filePath) == false)
return null;
+
return File.ReadAllBytes(filePath);
}
@@ -78,6 +80,9 @@ namespace YooAsset
///
public static long GetFileSize(string filePath)
{
+ if (File.Exists(filePath) == false)
+ return 0;
+
FileInfo fileInfo = new FileInfo(filePath);
return fileInfo.Length;
}
diff --git a/Assets/YooAsset/Runtime/Utility/FileUtility.cs.meta b/Assets/YooAsset/Runtime/Utility/Utilities/FileUtility.cs.meta
similarity index 100%
rename from Assets/YooAsset/Runtime/Utility/FileUtility.cs.meta
rename to Assets/YooAsset/Runtime/Utility/Utilities/FileUtility.cs.meta
diff --git a/Assets/YooAsset/Runtime/Utility/HashUtility.cs b/Assets/YooAsset/Runtime/Utility/Utilities/HashUtility.cs
similarity index 100%
rename from Assets/YooAsset/Runtime/Utility/HashUtility.cs
rename to Assets/YooAsset/Runtime/Utility/Utilities/HashUtility.cs
diff --git a/Assets/YooAsset/Runtime/Utility/HashUtility.cs.meta b/Assets/YooAsset/Runtime/Utility/Utilities/HashUtility.cs.meta
similarity index 100%
rename from Assets/YooAsset/Runtime/Utility/HashUtility.cs.meta
rename to Assets/YooAsset/Runtime/Utility/Utilities/HashUtility.cs.meta
diff --git a/Assets/YooAsset/Runtime/Utility/PathUtility.cs b/Assets/YooAsset/Runtime/Utility/Utilities/PathUtility.cs
similarity index 100%
rename from Assets/YooAsset/Runtime/Utility/PathUtility.cs
rename to Assets/YooAsset/Runtime/Utility/Utilities/PathUtility.cs
diff --git a/Assets/YooAsset/Runtime/Utility/PathUtility.cs.meta b/Assets/YooAsset/Runtime/Utility/Utilities/PathUtility.cs.meta
similarity index 100%
rename from Assets/YooAsset/Runtime/Utility/PathUtility.cs.meta
rename to Assets/YooAsset/Runtime/Utility/Utilities/PathUtility.cs.meta
diff --git a/Assets/YooAsset/Runtime/Utility/StringUtility.cs b/Assets/YooAsset/Runtime/Utility/Utilities/StringUtility.cs
similarity index 100%
rename from Assets/YooAsset/Runtime/Utility/StringUtility.cs
rename to Assets/YooAsset/Runtime/Utility/Utilities/StringUtility.cs
diff --git a/Assets/YooAsset/Runtime/Utility/StringUtility.cs.meta b/Assets/YooAsset/Runtime/Utility/Utilities/StringUtility.cs.meta
similarity index 100%
rename from Assets/YooAsset/Runtime/Utility/StringUtility.cs.meta
rename to Assets/YooAsset/Runtime/Utility/Utilities/StringUtility.cs.meta
diff --git a/Assets/YooAsset/Runtime/Utility/TimeUtility.cs b/Assets/YooAsset/Runtime/Utility/Utilities/TimeUtility.cs
similarity index 100%
rename from Assets/YooAsset/Runtime/Utility/TimeUtility.cs
rename to Assets/YooAsset/Runtime/Utility/Utilities/TimeUtility.cs
diff --git a/Assets/YooAsset/Runtime/Utility/TimeUtility.cs.meta b/Assets/YooAsset/Runtime/Utility/Utilities/TimeUtility.cs.meta
similarity index 100%
rename from Assets/YooAsset/Runtime/Utility/TimeUtility.cs.meta
rename to Assets/YooAsset/Runtime/Utility/Utilities/TimeUtility.cs.meta
diff --git a/Assets/YooAsset/Samples~/Extension Sample/Editor/CreateBuildinCatalog/CreateBuildinCatalogWindow.cs b/Assets/YooAsset/Samples~/Extension Sample/Editor/CreateBuildinCatalog/CreateBuildinCatalogWindow.cs
index e6ed9b0e..b203035f 100644
--- a/Assets/YooAsset/Samples~/Extension Sample/Editor/CreateBuildinCatalog/CreateBuildinCatalogWindow.cs
+++ b/Assets/YooAsset/Samples~/Extension Sample/Editor/CreateBuildinCatalog/CreateBuildinCatalogWindow.cs
@@ -55,7 +55,7 @@ namespace YooAsset.Editor
string packageName = directoryInfo.Name;
try
{
- bool result = BuiltinFileCatalogTools.CreateFile(null, packageName, packageRoot); //TODO 自行处理解密
+ bool result = BuiltinCatalogTools.CreateFile(null, packageName, packageRoot); //TODO 自行处理解密
if (result == false)
{
Debug.LogError($"Create package {packageName} catalog file failed ! See the detail error in console !");
diff --git a/Assets/YooAsset/Samples~/Extension Sample/Editor/CreateBuildinCatalog/CreateEmptyCatalogWindow.cs b/Assets/YooAsset/Samples~/Extension Sample/Editor/CreateBuildinCatalog/CreateEmptyCatalogWindow.cs
index 6a57744c..5c123f8f 100644
--- a/Assets/YooAsset/Samples~/Extension Sample/Editor/CreateBuildinCatalog/CreateEmptyCatalogWindow.cs
+++ b/Assets/YooAsset/Samples~/Extension Sample/Editor/CreateBuildinCatalog/CreateEmptyCatalogWindow.cs
@@ -47,7 +47,7 @@ namespace YooAsset.Editor
{
try
{
- bool result = BuiltinFileCatalogTools.CreateEmptyFile(_packageName, string.Empty, outputPath);
+ bool result = BuiltinCatalogTools.CreateEmptyFile(_packageName, string.Empty, outputPath);
if (result == false)
{
Debug.LogError($"Create package {_packageName} catalog file failed ! See the detail error in console !");
diff --git a/Assets/YooAsset/Samples~/Extension Sample/Editor/PreprocessBuild/PreprocessBuildCatalog.cs b/Assets/YooAsset/Samples~/Extension Sample/Editor/PreprocessBuild/PreprocessBuildCatalog.cs
index c5f3b0f1..52b010c4 100644
--- a/Assets/YooAsset/Samples~/Extension Sample/Editor/PreprocessBuild/PreprocessBuildCatalog.cs
+++ b/Assets/YooAsset/Samples~/Extension Sample/Editor/PreprocessBuild/PreprocessBuildCatalog.cs
@@ -32,7 +32,7 @@ namespace YooAsset
string pacakgeDirectory = subDirectory.FullName;
try
{
- bool result = BuiltinFileCatalogTools.CreateFile(null, packageName, pacakgeDirectory); //TODO 自行处理解密
+ bool result = BuiltinCatalogTools.CreateFile(null, packageName, pacakgeDirectory); //TODO 自行处理解密
if (result == false)
{
Debug.LogError($"Create package {packageName} catalog file failed ! See the detail error in console !");
diff --git a/Assets/YooAsset/Samples~/Mini Game/Runtime/MiniGameTest/FileSystemTester.cs b/Assets/YooAsset/Samples~/Mini Game/Runtime/MiniGameTest/FileSystemTester.cs
index b193689f..a80db1d9 100644
--- a/Assets/YooAsset/Samples~/Mini Game/Runtime/MiniGameTest/FileSystemTester.cs
+++ b/Assets/YooAsset/Samples~/Mini Game/Runtime/MiniGameTest/FileSystemTester.cs
@@ -50,7 +50,7 @@ namespace YooAsset
{
var manifest = loadPackageManifestOp.Manifest;
var packageBundle = GetPackageBundle(manifest, testLocation);
- var options = new DownloadFileOptions(packageBundle, 1);
+ var options = new FSDownloadFileOptions(packageBundle, 1);
var downloadFileOp = fileSystem.DownloadFileAsync(options);
AsyncOperationSystem.StartOperation(packageName, downloadFileOp);
yield return downloadFileOp;
@@ -70,7 +70,7 @@ namespace YooAsset
{
var manifest = loadPackageManifestOp.Manifest;
var packageBundle = GetPackageBundle(manifest, testLocation);
- var loadBundleFileOptions = new LoadBundleOptions(packageBundle);
+ var loadBundleFileOptions = new FCLoadBundleOptions(packageBundle);
var loadBundleFileOp = fileSystem.LoadBundleAsync(loadBundleFileOptions);
AsyncOperationSystem.StartOperation(packageName, loadBundleFileOp);
yield return loadBundleFileOp;