diff --git a/Assets/YooAsset/Editor/AssetBundleDebugger/VisualViewers/DebuggerAssetListViewer.cs b/Assets/YooAsset/Editor/AssetBundleDebugger/VisualViewers/DebuggerAssetListViewer.cs index 473c59dc..dd242736 100644 --- a/Assets/YooAsset/Editor/AssetBundleDebugger/VisualViewers/DebuggerAssetListViewer.cs +++ b/Assets/YooAsset/Editor/AssetBundleDebugger/VisualViewers/DebuggerAssetListViewer.cs @@ -206,8 +206,7 @@ namespace YooAsset.Editor { StyleColor textColor; var providerTableData = data as ProviderTableData; - if (providerTableData.ProviderInfo.Status == EOperationStatus.Failed.ToString() || - providerTableData.ProviderInfo.Status == EOperationStatus.Aborted.ToString()) + if (providerTableData.ProviderInfo.Status == EOperationStatus.Failed.ToString()) textColor = new StyleColor(Color.yellow); else textColor = new StyleColor(Color.white); @@ -281,8 +280,7 @@ namespace YooAsset.Editor { StyleColor textColor; var dependTableData = data as DependTableData; - if (dependTableData.BundleInfo.Status == EOperationStatus.Failed.ToString() || - dependTableData.BundleInfo.Status == EOperationStatus.Aborted.ToString()) + if (dependTableData.BundleInfo.Status == EOperationStatus.Failed.ToString()) textColor = new StyleColor(Color.yellow); else textColor = new StyleColor(Color.white); diff --git a/Assets/YooAsset/Editor/AssetBundleDebugger/VisualViewers/DebuggerBundleListViewer.cs b/Assets/YooAsset/Editor/AssetBundleDebugger/VisualViewers/DebuggerBundleListViewer.cs index 7cc16fa6..50974dab 100644 --- a/Assets/YooAsset/Editor/AssetBundleDebugger/VisualViewers/DebuggerBundleListViewer.cs +++ b/Assets/YooAsset/Editor/AssetBundleDebugger/VisualViewers/DebuggerBundleListViewer.cs @@ -151,8 +151,7 @@ namespace YooAsset.Editor { StyleColor textColor; var bundleTableData = data as BundleTableData; - if (bundleTableData.BundleInfo.Status == EOperationStatus.Failed.ToString() || - bundleTableData.BundleInfo.Status == EOperationStatus.Aborted.ToString()) + if (bundleTableData.BundleInfo.Status == EOperationStatus.Failed.ToString()) textColor = new StyleColor(Color.yellow); else textColor = new StyleColor(Color.white); @@ -268,8 +267,7 @@ namespace YooAsset.Editor { StyleColor textColor; var usingTableData = data as UsingTableData; - if (usingTableData.ProviderInfo.Status == EOperationStatus.Failed.ToString() || - usingTableData.ProviderInfo.Status == EOperationStatus.Aborted.ToString()) + if (usingTableData.ProviderInfo.Status == EOperationStatus.Failed.ToString()) textColor = new StyleColor(Color.yellow); else textColor = new StyleColor(Color.white); @@ -343,8 +341,7 @@ namespace YooAsset.Editor { StyleColor textColor; var feferenceTableData = data as ReferenceTableData; - if (feferenceTableData.BundleInfo.Status == EOperationStatus.Failed.ToString() || - feferenceTableData.BundleInfo.Status == EOperationStatus.Aborted.ToString()) + if (feferenceTableData.BundleInfo.Status == EOperationStatus.Failed.ToString()) textColor = new StyleColor(Color.yellow); else textColor = new StyleColor(Color.white); diff --git a/Assets/YooAsset/Editor/AssetBundleDebugger/VisualViewers/DebuggerOperationListViewer.cs b/Assets/YooAsset/Editor/AssetBundleDebugger/VisualViewers/DebuggerOperationListViewer.cs index d63a4038..2a9f2cfc 100644 --- a/Assets/YooAsset/Editor/AssetBundleDebugger/VisualViewers/DebuggerOperationListViewer.cs +++ b/Assets/YooAsset/Editor/AssetBundleDebugger/VisualViewers/DebuggerOperationListViewer.cs @@ -207,8 +207,7 @@ namespace YooAsset.Editor { StyleColor textColor; var operationTableData = data as OperationTableData; - if (operationTableData.OperationInfo.Status == EOperationStatus.Failed.ToString() || - operationTableData.OperationInfo.Status == EOperationStatus.Aborted.ToString()) + if (operationTableData.OperationInfo.Status == EOperationStatus.Failed.ToString()) textColor = new StyleColor(Color.yellow); else textColor = new StyleColor(Color.white); @@ -480,8 +479,7 @@ namespace YooAsset.Editor // Status { StyleColor textColor; - if (operationInfo.Status == EOperationStatus.Failed.ToString() || - operationInfo.Status == EOperationStatus.Aborted.ToString()) + if (operationInfo.Status == EOperationStatus.Failed.ToString()) textColor = new StyleColor(Color.yellow); else textColor = new StyleColor(Color.white); diff --git a/Assets/YooAsset/Runtime/AsyncOperation/AsyncOperationBase.cs b/Assets/YooAsset/Runtime/AsyncOperation/AsyncOperationBase.cs index e26220d4..d910fbe9 100644 --- a/Assets/YooAsset/Runtime/AsyncOperation/AsyncOperationBase.cs +++ b/Assets/YooAsset/Runtime/AsyncOperation/AsyncOperationBase.cs @@ -78,13 +78,13 @@ namespace YooAsset public float Progress { get; protected set; } /// - /// 任务逻辑是否完成(Status为Succeeded、Failed或Aborted) + /// 任务逻辑是否完成(Status为Succeeded、Failed) /// public bool IsDone { get { - return Status == EOperationStatus.Succeeded || Status == EOperationStatus.Failed || Status == EOperationStatus.Aborted; + return Status == EOperationStatus.Succeeded || Status == EOperationStatus.Failed; } } @@ -306,7 +306,7 @@ namespace YooAsset if (IsDone == false) { InternalAbort(); - Status = EOperationStatus.Aborted; + Status = EOperationStatus.Failed; Error = "Aborted by user"; YooLogger.Warning($"Async operation {this.GetType().Name} has been aborted."); } diff --git a/Assets/YooAsset/Runtime/AsyncOperation/EOperationStatus.cs b/Assets/YooAsset/Runtime/AsyncOperation/EOperationStatus.cs index e2e20d38..103f4a81 100644 --- a/Assets/YooAsset/Runtime/AsyncOperation/EOperationStatus.cs +++ b/Assets/YooAsset/Runtime/AsyncOperation/EOperationStatus.cs @@ -25,10 +25,5 @@ namespace YooAsset /// 已失败 /// Failed, - - /// - /// 已中止(用户主动取消) - /// - Aborted, } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/FileCache.meta b/Assets/YooAsset/Runtime/BundleCache.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache.meta rename to Assets/YooAsset/Runtime/BundleCache.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Interfaces.meta b/Assets/YooAsset/Runtime/BundleCache/Interfaces.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Interfaces.meta rename to Assets/YooAsset/Runtime/BundleCache/Interfaces.meta diff --git a/Assets/YooAsset/Runtime/BundleCache/Interfaces/EvictionResult.cs b/Assets/YooAsset/Runtime/BundleCache/Interfaces/EvictionResult.cs new file mode 100644 index 00000000..bfd1d923 --- /dev/null +++ b/Assets/YooAsset/Runtime/BundleCache/Interfaces/EvictionResult.cs @@ -0,0 +1,48 @@ +using System.Collections.Generic; + +namespace YooAsset +{ + /// + /// 淘汰策略执行结果 + /// + internal readonly struct EvictionResult + { + /// + /// 错误信息 + /// + public readonly string Error; + + /// + /// 需要清理的资源标识符集合 + /// + public readonly List BundleGUIDs; + + /// + /// 是否成功 + /// + public bool Succeeded + { + get { return Error == null; } + } + + public EvictionResult(string error) + { + Error = error; + BundleGUIDs = null; + } + public EvictionResult(List bundleGUIDs) + { + Error = null; + BundleGUIDs = bundleGUIDs; + } + + public static EvictionResult Success(List bundleGUIDs) + { + return new EvictionResult(bundleGUIDs); + } + public static EvictionResult Failure(string error) + { + return new EvictionResult(error); + } + } +} diff --git a/Assets/YooAsset/Runtime/BundleCache/Interfaces/EvictionResult.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Interfaces/EvictionResult.cs.meta new file mode 100644 index 00000000..93201b1c --- /dev/null +++ b/Assets/YooAsset/Runtime/BundleCache/Interfaces/EvictionResult.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1cfc5979929f8cd43b58e1fcc541eaa8 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/FileCache/Interfaces/IFileCache.cs b/Assets/YooAsset/Runtime/BundleCache/Interfaces/IBundleCache.cs similarity index 76% rename from Assets/YooAsset/Runtime/FileCache/Interfaces/IFileCache.cs rename to Assets/YooAsset/Runtime/BundleCache/Interfaces/IBundleCache.cs index 72748b67..38db3573 100644 --- a/Assets/YooAsset/Runtime/FileCache/Interfaces/IFileCache.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Interfaces/IBundleCache.cs @@ -1,12 +1,11 @@ using System; -using System.Collections.Generic; namespace YooAsset { /// /// 文件缓存系统接口 /// - internal interface IFileCache : IDisposable + internal interface IBundleCache : IDisposable { /// /// 包裹名称 @@ -37,27 +36,27 @@ namespace YooAsset /// /// 初始化文件缓存系统 /// - FCInitializeOperation InitializeAsync(); + BCInitializeOperation InitializeAsync(); /// /// 写入缓存文件 /// - FCWriteCacheOperation WriteCacheAsync(FCWriteCacheOptions options); + BCWriteCacheOperation WriteCacheAsync(BCWriteCacheOptions options); /// /// 清理缓存文件 /// - FCClearCacheOperation ClearCacheAsync(FCClearCacheOptions options); + BCClearCacheOperation ClearCacheAsync(BCClearCacheOptions options); /// /// 验证缓存文件 /// - FCVerifyCacheOperation VerifyCacheAsync(FCVerifyCacheOptions options); + BCVerifyCacheOperation VerifyCacheAsync(BCVerifyCacheOptions options); /// /// 加载资源包 /// - FCLoadBundleOperation LoadBundleAsync(FCLoadBundleOptions options); + BCLoadBundleOperation LoadBundleAsync(BCLoadBundleOptions options); /// /// 是否已缓存指定 Bundle diff --git a/Assets/YooAsset/Runtime/FileCache/Interfaces/IFileCache.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Interfaces/IBundleCache.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Interfaces/IFileCache.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Interfaces/IBundleCache.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Interfaces/ICacheEntry.cs b/Assets/YooAsset/Runtime/BundleCache/Interfaces/ICacheEntry.cs similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Interfaces/ICacheEntry.cs rename to Assets/YooAsset/Runtime/BundleCache/Interfaces/ICacheEntry.cs diff --git a/Assets/YooAsset/Runtime/FileCache/Interfaces/ICacheEntry.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Interfaces/ICacheEntry.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Interfaces/ICacheEntry.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Interfaces/ICacheEntry.cs.meta diff --git a/Assets/YooAsset/Runtime/BundleCache/Interfaces/ICacheEvictionPolicy.cs b/Assets/YooAsset/Runtime/BundleCache/Interfaces/ICacheEvictionPolicy.cs new file mode 100644 index 00000000..ec6d37dd --- /dev/null +++ b/Assets/YooAsset/Runtime/BundleCache/Interfaces/ICacheEvictionPolicy.cs @@ -0,0 +1,15 @@ +using System.Collections.Generic; + +namespace YooAsset +{ + /// + /// 缓存淘汰策略接口 + /// + internal interface ICacheEvictionPolicy + { + /// + /// 根据策略从缓存条目中选出需要清理的 BundleGUID 列表 + /// + EvictionResult SelectEvictionTargets(IReadOnlyCollection cacheEntries, BCClearCacheOptions options); + } +} diff --git a/Assets/YooAsset/Runtime/BundleCache/Interfaces/ICacheEvictionPolicy.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Interfaces/ICacheEvictionPolicy.cs.meta new file mode 100644 index 00000000..01e6c5fb --- /dev/null +++ b/Assets/YooAsset/Runtime/BundleCache/Interfaces/ICacheEvictionPolicy.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c113f2d8eaa9d58408001ddea8d20020 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/FileCache/Operations.meta b/Assets/YooAsset/Runtime/BundleCache/Operations.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Operations.meta rename to Assets/YooAsset/Runtime/BundleCache/Operations.meta diff --git a/Assets/YooAsset/Runtime/BundleCache/Operations/BCClearCacheOperation.cs b/Assets/YooAsset/Runtime/BundleCache/Operations/BCClearCacheOperation.cs new file mode 100644 index 00000000..0b1818fb --- /dev/null +++ b/Assets/YooAsset/Runtime/BundleCache/Operations/BCClearCacheOperation.cs @@ -0,0 +1,42 @@ + +namespace YooAsset +{ + /// + /// 清理缓存操作基类 + /// + internal abstract class BCClearCacheOperation : AsyncOperationBase + { + } + + /// + /// 清理缓存完成操作 + /// + internal class BCClearCacheCompleteOperation : BCClearCacheOperation + { + private readonly string _error; + + public BCClearCacheCompleteOperation() + { + _error = null; + } + public BCClearCacheCompleteOperation(string error) + { + _error = error; + } + internal override void InternalStart() + { + if (string.IsNullOrEmpty(_error)) + { + Status = EOperationStatus.Succeeded; + } + else + { + Status = EOperationStatus.Failed; + Error = _error; + } + } + internal override void InternalUpdate() + { + } + } +} diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/FCClearCacheOperation.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Operations/BCClearCacheOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Operations/FCClearCacheOperation.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Operations/BCClearCacheOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/FCClearCacheOptions.cs b/Assets/YooAsset/Runtime/BundleCache/Operations/BCClearCacheOptions.cs similarity index 92% rename from Assets/YooAsset/Runtime/FileCache/Operations/FCClearCacheOptions.cs rename to Assets/YooAsset/Runtime/BundleCache/Operations/BCClearCacheOptions.cs index f4730ff7..2b2fc6c3 100644 --- a/Assets/YooAsset/Runtime/FileCache/Operations/FCClearCacheOptions.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Operations/BCClearCacheOptions.cs @@ -4,7 +4,7 @@ namespace YooAsset /// /// 清理缓存操作选项 /// - internal struct FCClearCacheOptions + internal struct BCClearCacheOptions { /// /// 清理模式 diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/FCClearCacheOptions.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Operations/BCClearCacheOptions.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Operations/FCClearCacheOptions.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Operations/BCClearCacheOptions.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/FCInitializeOperation.cs b/Assets/YooAsset/Runtime/BundleCache/Operations/BCInitializeOperation.cs similarity index 65% rename from Assets/YooAsset/Runtime/FileCache/Operations/FCInitializeOperation.cs rename to Assets/YooAsset/Runtime/BundleCache/Operations/BCInitializeOperation.cs index bfe6a2cd..3cc43278 100644 --- a/Assets/YooAsset/Runtime/FileCache/Operations/FCInitializeOperation.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Operations/BCInitializeOperation.cs @@ -4,7 +4,7 @@ namespace YooAsset /// /// 文件缓存初始化操作基类 /// - internal abstract class FCInitializeOperation : AsyncOperationBase + internal abstract class BCInitializeOperation : AsyncOperationBase { } } diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/FCInitializeOperation.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Operations/BCInitializeOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Operations/FCInitializeOperation.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Operations/BCInitializeOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/FCLoadBundleOperation.cs b/Assets/YooAsset/Runtime/BundleCache/Operations/BCLoadBundleOperation.cs similarity index 88% rename from Assets/YooAsset/Runtime/FileCache/Operations/FCLoadBundleOperation.cs rename to Assets/YooAsset/Runtime/BundleCache/Operations/BCLoadBundleOperation.cs index 98d924b8..be65f829 100644 --- a/Assets/YooAsset/Runtime/FileCache/Operations/FCLoadBundleOperation.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Operations/BCLoadBundleOperation.cs @@ -4,7 +4,7 @@ namespace YooAsset /// /// 加载资源包操作基类 /// - internal abstract class FCLoadBundleOperation : AsyncOperationBase + internal abstract class BCLoadBundleOperation : AsyncOperationBase { protected readonly struct LoadResult { @@ -45,11 +45,11 @@ namespace YooAsset /// /// 加载资源包失败操作 /// - internal sealed class FCLoadBundleErrorOperation : FCLoadBundleOperation + internal sealed class BCLoadBundleErrorOperation : BCLoadBundleOperation { private readonly string _error; - internal FCLoadBundleErrorOperation(string error) + internal BCLoadBundleErrorOperation(string error) { _error = error; } diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/FCLoadBundleOperation.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Operations/BCLoadBundleOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Operations/FCLoadBundleOperation.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Operations/BCLoadBundleOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/FCLoadBundleOptions.cs b/Assets/YooAsset/Runtime/BundleCache/Operations/BCLoadBundleOptions.cs similarity index 71% rename from Assets/YooAsset/Runtime/FileCache/Operations/FCLoadBundleOptions.cs rename to Assets/YooAsset/Runtime/BundleCache/Operations/BCLoadBundleOptions.cs index dcb614f5..b8333305 100644 --- a/Assets/YooAsset/Runtime/FileCache/Operations/FCLoadBundleOptions.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Operations/BCLoadBundleOptions.cs @@ -4,14 +4,14 @@ namespace YooAsset /// /// 加载资源包操作选项 /// - internal readonly struct FCLoadBundleOptions + internal readonly struct BCLoadBundleOptions { /// /// 资源包 /// public readonly PackageBundle Bundle; - public FCLoadBundleOptions(PackageBundle bundle) + public BCLoadBundleOptions(PackageBundle bundle) { Bundle = bundle; } diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/FCLoadBundleOptions.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Operations/BCLoadBundleOptions.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Operations/FCLoadBundleOptions.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Operations/BCLoadBundleOptions.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/FCVerifyCacheOperation.cs b/Assets/YooAsset/Runtime/BundleCache/Operations/BCVerifyCacheOperation.cs similarity index 75% rename from Assets/YooAsset/Runtime/FileCache/Operations/FCVerifyCacheOperation.cs rename to Assets/YooAsset/Runtime/BundleCache/Operations/BCVerifyCacheOperation.cs index 0cfa9319..78610eb7 100644 --- a/Assets/YooAsset/Runtime/FileCache/Operations/FCVerifyCacheOperation.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Operations/BCVerifyCacheOperation.cs @@ -4,22 +4,22 @@ namespace YooAsset /// /// 验证缓存操作基类 /// - internal abstract class FCVerifyCacheOperation : AsyncOperationBase + internal abstract class BCVerifyCacheOperation : AsyncOperationBase { } /// /// 验证缓存完成操作 /// - internal class FCVerifyCacheCompleteOperation : FCVerifyCacheOperation + internal class BCVerifyCacheCompleteOperation : BCVerifyCacheOperation { private readonly string _error; - public FCVerifyCacheCompleteOperation() + public BCVerifyCacheCompleteOperation() { _error = null; } - public FCVerifyCacheCompleteOperation(string error) + public BCVerifyCacheCompleteOperation(string error) { _error = error; } diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/FCVerifyCacheOperation.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Operations/BCVerifyCacheOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Operations/FCVerifyCacheOperation.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Operations/BCVerifyCacheOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/FCVerifyCacheOptions.cs b/Assets/YooAsset/Runtime/BundleCache/Operations/BCVerifyCacheOptions.cs similarity index 90% rename from Assets/YooAsset/Runtime/FileCache/Operations/FCVerifyCacheOptions.cs rename to Assets/YooAsset/Runtime/BundleCache/Operations/BCVerifyCacheOptions.cs index 9b14ce2f..e42a1cda 100644 --- a/Assets/YooAsset/Runtime/FileCache/Operations/FCVerifyCacheOptions.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Operations/BCVerifyCacheOptions.cs @@ -4,7 +4,7 @@ namespace YooAsset /// /// 验证缓存操作选项 /// - internal struct FCVerifyCacheOptions + internal struct BCVerifyCacheOptions { /// /// 要验证的资源包 diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/FCVerifyCacheOptions.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Operations/BCVerifyCacheOptions.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Operations/FCVerifyCacheOptions.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Operations/BCVerifyCacheOptions.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/FCWriteCacheOperation.cs b/Assets/YooAsset/Runtime/BundleCache/Operations/BCWriteCacheOperation.cs similarity index 75% rename from Assets/YooAsset/Runtime/FileCache/Operations/FCWriteCacheOperation.cs rename to Assets/YooAsset/Runtime/BundleCache/Operations/BCWriteCacheOperation.cs index d5f5f30e..c9659bb3 100644 --- a/Assets/YooAsset/Runtime/FileCache/Operations/FCWriteCacheOperation.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Operations/BCWriteCacheOperation.cs @@ -4,22 +4,22 @@ namespace YooAsset /// /// 写入缓存操作基类 /// - internal abstract class FCWriteCacheOperation : AsyncOperationBase + internal abstract class BCWriteCacheOperation : AsyncOperationBase { } /// /// 写入缓存完成操作 /// - internal class FCWriteCacheCompleteOperation : FCWriteCacheOperation + internal class BCWriteCacheCompleteOperation : BCWriteCacheOperation { private readonly string _error; - public FCWriteCacheCompleteOperation() + public BCWriteCacheCompleteOperation() { _error = null; } - public FCWriteCacheCompleteOperation(string error) + public BCWriteCacheCompleteOperation(string error) { _error = error; } diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/FCWriteCacheOperation.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Operations/BCWriteCacheOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Operations/FCWriteCacheOperation.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Operations/BCWriteCacheOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/FCWriteCacheOptions.cs b/Assets/YooAsset/Runtime/BundleCache/Operations/BCWriteCacheOptions.cs similarity index 92% rename from Assets/YooAsset/Runtime/FileCache/Operations/FCWriteCacheOptions.cs rename to Assets/YooAsset/Runtime/BundleCache/Operations/BCWriteCacheOptions.cs index 787faa7d..2b57d525 100644 --- a/Assets/YooAsset/Runtime/FileCache/Operations/FCWriteCacheOptions.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Operations/BCWriteCacheOptions.cs @@ -4,7 +4,7 @@ namespace YooAsset /// /// 写入缓存操作选项 /// - internal struct FCWriteCacheOptions + internal struct BCWriteCacheOptions { /// /// 要缓存的资源包 diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/FCWriteCacheOptions.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Operations/BCWriteCacheOptions.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Operations/FCWriteCacheOptions.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Operations/BCWriteCacheOptions.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/Common.meta b/Assets/YooAsset/Runtime/BundleCache/Operations/Common.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Operations/Common.meta rename to Assets/YooAsset/Runtime/BundleCache/Operations/Common.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadBuiltinCatalogOperation.cs b/Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadBuiltinCatalogOperation.cs similarity index 97% rename from Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadBuiltinCatalogOperation.cs rename to Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadBuiltinCatalogOperation.cs index 6c75f9a3..59eac32a 100644 --- a/Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadBuiltinCatalogOperation.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadBuiltinCatalogOperation.cs @@ -69,7 +69,7 @@ namespace YooAsset // 注意:从Web服务器下载数据 if (_downloadBytesRequest == null) { - string url = DownloadSystemTools.ToLocalUrl(_options.FilePath); + string url = DownloadSystemTools.ToLocalFileUrl(_options.FilePath); var args = new DownloadDataRequestArgs(url, 60, 0); _downloadBytesRequest = _options.DownloadBackend.CreateBytesRequest(args); _downloadBytesRequest.SendRequest(); diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadBuiltinCatalogOperation.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadBuiltinCatalogOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadBuiltinCatalogOperation.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadBuiltinCatalogOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadBuiltinCatalogOptions.cs b/Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadBuiltinCatalogOptions.cs similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadBuiltinCatalogOptions.cs rename to Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadBuiltinCatalogOptions.cs diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadBuiltinCatalogOptions.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadBuiltinCatalogOptions.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadBuiltinCatalogOptions.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadBuiltinCatalogOptions.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadLocalAssetBundleOperation.cs b/Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadLocalAssetBundleOperation.cs similarity index 99% rename from Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadLocalAssetBundleOperation.cs rename to Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadLocalAssetBundleOperation.cs index 1e3b86cc..0cc864f6 100644 --- a/Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadLocalAssetBundleOperation.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadLocalAssetBundleOperation.cs @@ -6,7 +6,7 @@ namespace YooAsset /// /// 从本地文件加载 AssetBundle 操作 /// - internal class LoadLocalAssetBundleOperation : FCLoadBundleOperation + internal class LoadLocalAssetBundleOperation : BCLoadBundleOperation { private enum ESteps { diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadLocalAssetBundleOperation.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadLocalAssetBundleOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadLocalAssetBundleOperation.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadLocalAssetBundleOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadLocalAssetBundleOptions.cs b/Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadLocalAssetBundleOptions.cs similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadLocalAssetBundleOptions.cs rename to Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadLocalAssetBundleOptions.cs diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadLocalAssetBundleOptions.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadLocalAssetBundleOptions.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadLocalAssetBundleOptions.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadLocalAssetBundleOptions.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadLocalRawBundleOperation.cs b/Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadLocalRawBundleOperation.cs similarity index 98% rename from Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadLocalRawBundleOperation.cs rename to Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadLocalRawBundleOperation.cs index ba0f8a5e..551a6fe0 100644 --- a/Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadLocalRawBundleOperation.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadLocalRawBundleOperation.cs @@ -6,7 +6,7 @@ namespace YooAsset /// /// 从本地加载 RawBundle 操作 /// - internal class LoadLocalRawBundleOperation : FCLoadBundleOperation + internal class LoadLocalRawBundleOperation : BCLoadBundleOperation { private enum ESteps { diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadLocalRawBundleOperation.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadLocalRawBundleOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadLocalRawBundleOperation.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadLocalRawBundleOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadLocalRawBundleOptions.cs b/Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadLocalRawBundleOptions.cs similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadLocalRawBundleOptions.cs rename to Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadLocalRawBundleOptions.cs diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadLocalRawBundleOptions.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadLocalRawBundleOptions.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadLocalRawBundleOptions.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadLocalRawBundleOptions.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadWebAssetBundleOperation.cs b/Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadWebAssetBundleOperation.cs similarity index 88% rename from Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadWebAssetBundleOperation.cs rename to Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadWebAssetBundleOperation.cs index 2ad97daa..11691991 100644 --- a/Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadWebAssetBundleOperation.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadWebAssetBundleOperation.cs @@ -5,7 +5,7 @@ namespace YooAsset /// /// 从网络加载 AssetBundle 操作的抽象基类 /// - internal abstract class LoadWebAssetBundleOperation : FCLoadBundleOperation + internal abstract class LoadWebAssetBundleOperation : BCLoadBundleOperation { } @@ -23,8 +23,8 @@ namespace YooAsset Done, } - protected readonly LoadWebAssetBundleOptions _options; - private readonly DownloadRetry _downloadRetry; + private readonly LoadWebAssetBundleOptions _options; + private readonly DownloadRetryController _downloadRetryController; private IDownloadAssetBundleRequest _downloadAssetBundleRequest; private ESteps _steps = ESteps.None; @@ -33,7 +33,7 @@ namespace YooAsset _options = options; // 注意:网络原因失败后,重新尝试直到成功 - _downloadRetry = new DownloadRetry(int.MaxValue, options.RetryPolicy); + _downloadRetryController = new DownloadRetryController(int.MaxValue, options.RetryPolicy); } internal override void InternalStart() { @@ -61,7 +61,7 @@ namespace YooAsset if (_downloadAssetBundleRequest.Status == EDownloadRequestStatus.Succeeded) { - _options.URLPolicy.OnSuccess(_downloadAssetBundleRequest.Url); + _options.URLPolicy.OnRequestSucceeded(_downloadAssetBundleRequest.Url); var assetBundle = _downloadAssetBundleRequest.Result; if (assetBundle == null) { @@ -81,10 +81,10 @@ namespace YooAsset string url = _downloadAssetBundleRequest.Url; long httpCode = _downloadAssetBundleRequest.HttpCode; string httpError = _downloadAssetBundleRequest.HttpError; - _options.URLPolicy.OnFailure(url, httpCode, httpError); - if (IsWaitForCompletion == false && _downloadRetry.CanRetry(url, httpCode, httpError)) + _options.URLPolicy.OnRequestFailed(url, httpCode, httpError); + if (IsWaitForCompletion == false && _downloadRetryController.CanRetryRequest(url, httpCode, httpError)) { - _downloadRetry.BeginWait(); + _downloadRetryController.StartRetryDelay(); _steps = ESteps.TryAgain; } else @@ -105,7 +105,7 @@ namespace YooAsset _downloadAssetBundleRequest = null; } - if (_downloadRetry.Tick()) + if (_downloadRetryController.UpdateRetryDelay()) { Progress = 0f; _steps = ESteps.BundleRequest; @@ -123,7 +123,7 @@ namespace YooAsset private string GetRequestURL() { - return _options.URLPolicy.SelectURL(_options.CandidateURLs); + return _options.URLPolicy.SelectUrl(_options.CandidateURLs); } } @@ -144,8 +144,8 @@ namespace YooAsset Done, } - protected readonly LoadWebAssetBundleOptions _options; - private readonly DownloadRetry _downloadRetry; + private readonly LoadWebAssetBundleOptions _options; + private readonly DownloadRetryController _downloadRetryController; private IDownloadBytesRequest _downloadBytesRequest; private IBundleMemoryDecryptor _decryptor; private AssetBundleCreateRequest _createRequest; @@ -156,7 +156,7 @@ namespace YooAsset _options = options; // 注意:网络原因失败后,重新尝试直到成功 - _downloadRetry = new DownloadRetry(int.MaxValue, options.RetryPolicy); + _downloadRetryController = new DownloadRetryController(int.MaxValue, options.RetryPolicy); } internal override void InternalStart() { @@ -204,7 +204,7 @@ namespace YooAsset if (_downloadBytesRequest.Status == EDownloadRequestStatus.Succeeded) { - _options.URLPolicy.OnSuccess(_downloadBytesRequest.Url); + _options.URLPolicy.OnRequestSucceeded(_downloadBytesRequest.Url); _steps = ESteps.VerifyData; } else @@ -212,10 +212,10 @@ namespace YooAsset string url = _downloadBytesRequest.Url; long httpCode = _downloadBytesRequest.HttpCode; string httpError = _downloadBytesRequest.HttpError; - _options.URLPolicy.OnFailure(url, httpCode, httpError); - if (IsWaitForCompletion == false && _downloadRetry.CanRetry(url, httpCode, httpError)) + _options.URLPolicy.OnRequestFailed(url, httpCode, httpError); + if (IsWaitForCompletion == false && _downloadRetryController.CanRetryRequest(url, httpCode, httpError)) { - _downloadRetry.BeginWait(); + _downloadRetryController.StartRetryDelay(); _steps = ESteps.TryAgain; } else @@ -247,9 +247,9 @@ namespace YooAsset string error = $"[WebBundleVerify] Verify failed. Url:{_downloadBytesRequest.Url} Level: {_options.DownloadVerifyLevel} Result: {verifyResult}"; YooLogger.Warning(error); - if (IsWaitForCompletion == false && _downloadRetry.CanRetry()) + if (IsWaitForCompletion == false && _downloadRetryController.HasRetryQuota()) { - _downloadRetry.BeginWait(); + _downloadRetryController.StartRetryDelay(); _steps = ESteps.TryAgain; } else @@ -304,7 +304,7 @@ namespace YooAsset _downloadBytesRequest = null; } - if (_downloadRetry.Tick()) + if (_downloadRetryController.UpdateRetryDelay()) { Progress = 0f; _steps = ESteps.DataRequest; @@ -334,7 +334,7 @@ namespace YooAsset } private string GetRequestURL() { - return _options.URLPolicy.SelectURL(_options.CandidateURLs); + return _options.URLPolicy.SelectUrl(_options.CandidateURLs); } } } diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadWebAssetBundleOperation.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadWebAssetBundleOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadWebAssetBundleOperation.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadWebAssetBundleOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadWebAssetBundleOptions.cs b/Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadWebAssetBundleOptions.cs similarity index 96% rename from Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadWebAssetBundleOptions.cs rename to Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadWebAssetBundleOptions.cs index 829f48b6..23a4ffdc 100644 --- a/Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadWebAssetBundleOptions.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadWebAssetBundleOptions.cs @@ -55,6 +55,6 @@ namespace YooAsset /// /// URL 选择策略 /// - public IDownloadURLPolicy URLPolicy { get; set; } + public IDownloadUrlPolicy URLPolicy { get; set; } } } diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadWebAssetBundleOptions.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadWebAssetBundleOptions.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Operations/Common/LoadWebAssetBundleOptions.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadWebAssetBundleOptions.cs.meta diff --git a/Assets/YooAsset/Runtime/BundleCache/Policies.meta b/Assets/YooAsset/Runtime/BundleCache/Policies.meta new file mode 100644 index 00000000..6aea1d36 --- /dev/null +++ b/Assets/YooAsset/Runtime/BundleCache/Policies.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 4d3ccbed787d48c4d9051bac3503dacb +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/BundleCache/Policies/EvictionAllPolicy.cs b/Assets/YooAsset/Runtime/BundleCache/Policies/EvictionAllPolicy.cs new file mode 100644 index 00000000..2bc0438b --- /dev/null +++ b/Assets/YooAsset/Runtime/BundleCache/Policies/EvictionAllPolicy.cs @@ -0,0 +1,20 @@ +using System.Collections.Generic; + +namespace YooAsset +{ + /// + /// 清理所有缓存文件 + /// + internal class EvictionAllPolicy : ICacheEvictionPolicy + { + public EvictionResult SelectEvictionTargets(IReadOnlyCollection cacheEntries, BCClearCacheOptions options) + { + var bundleGUIDs = new List(cacheEntries.Count); + foreach (var entry in cacheEntries) + { + bundleGUIDs.Add(entry.BundleGUID); + } + return EvictionResult.Success(bundleGUIDs); + } + } +} diff --git a/Assets/YooAsset/Runtime/BundleCache/Policies/EvictionAllPolicy.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Policies/EvictionAllPolicy.cs.meta new file mode 100644 index 00000000..0c2f94e5 --- /dev/null +++ b/Assets/YooAsset/Runtime/BundleCache/Policies/EvictionAllPolicy.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8bd939b4d035fe54fb4adc975a3b7980 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/BundleCache/Policies/EvictionByLocationsPolicy.cs b/Assets/YooAsset/Runtime/BundleCache/Policies/EvictionByLocationsPolicy.cs new file mode 100644 index 00000000..053a3a69 --- /dev/null +++ b/Assets/YooAsset/Runtime/BundleCache/Policies/EvictionByLocationsPolicy.cs @@ -0,0 +1,41 @@ +using System.Collections.Generic; + +namespace YooAsset +{ + /// + /// 按资源地址清理缓存文件 + /// ClearParam 类型:string / string[] / List + /// + internal class EvictionByLocationsPolicy : ICacheEvictionPolicy + { + public EvictionResult SelectEvictionTargets(IReadOnlyCollection cacheEntries, BCClearCacheOptions options) + { + if (options.Manifest == null) + return EvictionResult.Failure("Active package manifest not found."); + if (options.ClearParam == null) + return EvictionResult.Failure("Clear param is null."); + + string[] locations; + if (options.ClearParam is string str) + locations = new string[] { str }; + else if (options.ClearParam is List list) + locations = list.ToArray(); + else if (options.ClearParam is string[] array) + locations = array; + else + return EvictionResult.Failure($"Invalid clear param: {options.ClearParam.GetType().FullName}"); + + var bundleGUIDs = new List(locations.Length); + foreach (var location in locations) + { + string assetPath = options.Manifest.TryMappingToAssetPath(location); + if (options.Manifest.TryGetPackageAsset(assetPath, out PackageAsset packageAsset)) + { + PackageBundle bundle = options.Manifest.GetMainPackageBundle(packageAsset.BundleID); + bundleGUIDs.Add(bundle.BundleGUID); + } + } + return EvictionResult.Success(bundleGUIDs); + } + } +} diff --git a/Assets/YooAsset/Runtime/BundleCache/Policies/EvictionByLocationsPolicy.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Policies/EvictionByLocationsPolicy.cs.meta new file mode 100644 index 00000000..07edb7ed --- /dev/null +++ b/Assets/YooAsset/Runtime/BundleCache/Policies/EvictionByLocationsPolicy.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f1f8b4ec99aecd94f8da510f81f12e09 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/BundleCache/Policies/EvictionByTagsPolicy.cs b/Assets/YooAsset/Runtime/BundleCache/Policies/EvictionByTagsPolicy.cs new file mode 100644 index 00000000..1d1bb81e --- /dev/null +++ b/Assets/YooAsset/Runtime/BundleCache/Policies/EvictionByTagsPolicy.cs @@ -0,0 +1,40 @@ +using System.Collections.Generic; + +namespace YooAsset +{ + /// + /// 按标签清理缓存文件 + /// ClearParam 类型:string / string[] / List + /// + internal class EvictionByTagsPolicy : ICacheEvictionPolicy + { + public EvictionResult SelectEvictionTargets(IReadOnlyCollection cacheEntries, BCClearCacheOptions options) + { + if (options.Manifest == null) + return EvictionResult.Failure("Active package manifest not found."); + if (options.ClearParam == null) + return EvictionResult.Failure("Clear param is null."); + + string[] tags; + if (options.ClearParam is string str) + tags = new string[] { str }; + else if (options.ClearParam is List list) + tags = list.ToArray(); + else if (options.ClearParam is string[] array) + tags = array; + else + return EvictionResult.Failure($"Invalid clear param: {options.ClearParam.GetType().FullName}"); + + var bundleGUIDs = new List(cacheEntries.Count); + foreach (var entry in cacheEntries) + { + if (options.Manifest.TryGetPackageBundleByBundleGUID(entry.BundleGUID, out PackageBundle bundle)) + { + if (bundle.HasTag(tags)) + bundleGUIDs.Add(bundle.BundleGUID); + } + } + return EvictionResult.Success(bundleGUIDs); + } + } +} diff --git a/Assets/YooAsset/Runtime/BundleCache/Policies/EvictionByTagsPolicy.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Policies/EvictionByTagsPolicy.cs.meta new file mode 100644 index 00000000..2d5eebd7 --- /dev/null +++ b/Assets/YooAsset/Runtime/BundleCache/Policies/EvictionByTagsPolicy.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 839c397ca55acea439d217ab3b504565 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/BundleCache/Policies/EvictionUnusedPolicy.cs b/Assets/YooAsset/Runtime/BundleCache/Policies/EvictionUnusedPolicy.cs new file mode 100644 index 00000000..e3693b0c --- /dev/null +++ b/Assets/YooAsset/Runtime/BundleCache/Policies/EvictionUnusedPolicy.cs @@ -0,0 +1,26 @@ +using System.Collections.Generic; + +namespace YooAsset +{ + /// + /// 清理 Manifest 中未引用的缓存文件 + /// + internal class EvictionUnusedPolicy : ICacheEvictionPolicy + { + public EvictionResult SelectEvictionTargets(IReadOnlyCollection cacheEntries, BCClearCacheOptions options) + { + if (options.Manifest == null) + return EvictionResult.Failure("Active package manifest not found."); + + var bundleGUIDs = new List(cacheEntries.Count); + foreach (var entry in cacheEntries) + { + if (options.Manifest.IsIncludeBundleFile(entry.BundleGUID) == false) + { + bundleGUIDs.Add(entry.BundleGUID); + } + } + return EvictionResult.Success(bundleGUIDs); + } + } +} diff --git a/Assets/YooAsset/Runtime/BundleCache/Policies/EvictionUnusedPolicy.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Policies/EvictionUnusedPolicy.cs.meta new file mode 100644 index 00000000..971405a8 --- /dev/null +++ b/Assets/YooAsset/Runtime/BundleCache/Policies/EvictionUnusedPolicy.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b9e404b43b235964c86a0be5373bb450 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/FileCache/Services.meta b/Assets/YooAsset/Runtime/BundleCache/Services.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services.meta rename to Assets/YooAsset/Runtime/BundleCache/Services.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache.meta b/Assets/YooAsset/Runtime/BundleCache/Services/BuiltinBundleCache.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache.meta rename to Assets/YooAsset/Runtime/BundleCache/Services/BuiltinBundleCache.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinFileCache.cs b/Assets/YooAsset/Runtime/BundleCache/Services/BuiltinBundleCache/BuiltinBundleCache.cs similarity index 76% rename from Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinFileCache.cs rename to Assets/YooAsset/Runtime/BundleCache/Services/BuiltinBundleCache/BuiltinBundleCache.cs index 50f18588..2178e5cc 100644 --- a/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinFileCache.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Services/BuiltinBundleCache/BuiltinBundleCache.cs @@ -6,7 +6,7 @@ namespace YooAsset /// /// 内置文件缓存系统,用于管理 StreamingAssets 中的资源包 /// - internal class BuiltinFileCache : IFileCache + internal class BuiltinBundleCache : IBundleCache { /// /// 内置文件缓存配置 @@ -29,7 +29,7 @@ namespace YooAsset public IDownloadBackend DownloadBackend { get; set; } } - private readonly Dictionary _cacheEntries = new Dictionary(10000); + private readonly Dictionary _cacheEntries = new Dictionary(10000); /// /// 缓存配置 @@ -76,7 +76,7 @@ namespace YooAsset /// 包裹名称 /// 缓存根目录 /// 缓存配置 - public BuiltinFileCache(string packageName, string rootPath, CacheConfig config) + public BuiltinBundleCache(string packageName, string rootPath, CacheConfig config) { PackageName = packageName; RootPath = rootPath; @@ -86,27 +86,27 @@ namespace YooAsset public void Dispose() { } - public virtual FCInitializeOperation InitializeAsync() + public virtual BCInitializeOperation InitializeAsync() { var operation = new BFCInitializeOperation(this); return operation; } - public virtual FCWriteCacheOperation WriteCacheAsync(FCWriteCacheOptions options) + public virtual BCWriteCacheOperation WriteCacheAsync(BCWriteCacheOptions options) { - var operation = new FCWriteCacheCompleteOperation($"{nameof(BuiltinFileCache)} is readonly."); + var operation = new BCWriteCacheCompleteOperation($"{nameof(BuiltinBundleCache)} is readonly."); return operation; } - public virtual FCClearCacheOperation ClearCacheAsync(FCClearCacheOptions options) + public virtual BCClearCacheOperation ClearCacheAsync(BCClearCacheOptions options) { - var operation = new FCClearCacheCompleteOperation($"{nameof(BuiltinFileCache)} is readonly."); + var operation = new BCClearCacheCompleteOperation(); return operation; } - public virtual FCVerifyCacheOperation VerifyCacheAsync(FCVerifyCacheOptions options) + public virtual BCVerifyCacheOperation VerifyCacheAsync(BCVerifyCacheOptions options) { - var operation = new FCVerifyCacheCompleteOperation(); + var operation = new BCVerifyCacheCompleteOperation(); return operation; } - public virtual FCLoadBundleOperation LoadBundleAsync(FCLoadBundleOptions options) + public virtual BCLoadBundleOperation LoadBundleAsync(BCLoadBundleOptions options) { if (options.Bundle.BundleType == (int)EBundleType.AssetBundle) { @@ -120,8 +120,8 @@ namespace YooAsset } else { - string error = $"{nameof(BuiltinFileCache)} does not support bundle type: {options.Bundle.BundleType}"; - var operation = new FCLoadBundleErrorOperation(error); + string error = $"{nameof(BuiltinBundleCache)} does not support bundle type: {options.Bundle.BundleType}"; + var operation = new BCLoadBundleErrorOperation(error); return operation; } } @@ -134,9 +134,9 @@ namespace YooAsset /// /// 获取指定缓存条目 /// - internal BuiltinFileCacheEntry GetEntry(string bundleGUID) + internal BuiltinBundleCacheEntry GetEntry(string bundleGUID) { - if (_cacheEntries.TryGetValue(bundleGUID, out BuiltinFileCacheEntry entry)) + if (_cacheEntries.TryGetValue(bundleGUID, out BuiltinBundleCacheEntry entry)) return entry; else return null; @@ -145,7 +145,7 @@ namespace YooAsset /// /// 添加指定缓存条目 /// - internal void AddEntry(string bundleGUID, BuiltinFileCacheEntry cacheEntry) + internal void AddEntry(string bundleGUID, BuiltinBundleCacheEntry cacheEntry) { if (_cacheEntries.ContainsKey(bundleGUID)) throw new YooInternalException($"Cache entry already exists: {bundleGUID}"); diff --git a/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinFileCache.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Services/BuiltinBundleCache/BuiltinBundleCache.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinFileCache.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Services/BuiltinBundleCache/BuiltinBundleCache.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinFileCacheEntry.cs b/Assets/YooAsset/Runtime/BundleCache/Services/BuiltinBundleCache/BuiltinBundleCacheEntry.cs similarity index 83% rename from Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinFileCacheEntry.cs rename to Assets/YooAsset/Runtime/BundleCache/Services/BuiltinBundleCache/BuiltinBundleCacheEntry.cs index acd72b27..c3783037 100644 --- a/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinFileCacheEntry.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Services/BuiltinBundleCache/BuiltinBundleCacheEntry.cs @@ -4,7 +4,7 @@ namespace YooAsset /// /// 内置文件缓存条目 /// - internal class BuiltinFileCacheEntry : ICacheEntry + internal class BuiltinBundleCacheEntry : ICacheEntry { /// /// 资源包唯一标识 @@ -21,7 +21,7 @@ namespace YooAsset /// /// 资源包唯一标识 /// 资源包文件路径 - public BuiltinFileCacheEntry(string bundleGUID, string filePath) + public BuiltinBundleCacheEntry(string bundleGUID, string filePath) { BundleGUID = bundleGUID; FilePath = filePath; diff --git a/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinFileCacheEntry.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Services/BuiltinBundleCache/BuiltinBundleCacheEntry.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinFileCacheEntry.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Services/BuiltinBundleCache/BuiltinBundleCacheEntry.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinCatalog.cs b/Assets/YooAsset/Runtime/BundleCache/Services/BuiltinBundleCache/BuiltinCatalog.cs similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinCatalog.cs rename to Assets/YooAsset/Runtime/BundleCache/Services/BuiltinBundleCache/BuiltinCatalog.cs diff --git a/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinCatalog.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Services/BuiltinBundleCache/BuiltinCatalog.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinCatalog.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Services/BuiltinBundleCache/BuiltinCatalog.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinCatalogConsts.cs b/Assets/YooAsset/Runtime/BundleCache/Services/BuiltinBundleCache/BuiltinCatalogConsts.cs similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinCatalogConsts.cs rename to Assets/YooAsset/Runtime/BundleCache/Services/BuiltinBundleCache/BuiltinCatalogConsts.cs diff --git a/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinCatalogConsts.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Services/BuiltinBundleCache/BuiltinCatalogConsts.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinCatalogConsts.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Services/BuiltinBundleCache/BuiltinCatalogConsts.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinCatalogTools.cs b/Assets/YooAsset/Runtime/BundleCache/Services/BuiltinBundleCache/BuiltinCatalogTools.cs similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinCatalogTools.cs rename to Assets/YooAsset/Runtime/BundleCache/Services/BuiltinBundleCache/BuiltinCatalogTools.cs diff --git a/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinCatalogTools.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Services/BuiltinBundleCache/BuiltinCatalogTools.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinCatalogTools.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Services/BuiltinBundleCache/BuiltinCatalogTools.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/Operations.meta b/Assets/YooAsset/Runtime/BundleCache/Services/BuiltinBundleCache/Operations.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/Operations.meta rename to Assets/YooAsset/Runtime/BundleCache/Services/BuiltinBundleCache/Operations.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/Operations/BFCInitializeOperation.cs b/Assets/YooAsset/Runtime/BundleCache/Services/BuiltinBundleCache/Operations/BBCInitializeOperation.cs similarity index 89% rename from Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/Operations/BFCInitializeOperation.cs rename to Assets/YooAsset/Runtime/BundleCache/Services/BuiltinBundleCache/Operations/BBCInitializeOperation.cs index 933db7fa..e4f22b15 100644 --- a/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/Operations/BFCInitializeOperation.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Services/BuiltinBundleCache/Operations/BBCInitializeOperation.cs @@ -4,7 +4,7 @@ namespace YooAsset /// /// 内置文件缓存初始化操作 /// - internal class BFCInitializeOperation : FCInitializeOperation + internal class BFCInitializeOperation : BCInitializeOperation { private enum ESteps { @@ -14,11 +14,11 @@ namespace YooAsset Done, } - private readonly BuiltinFileCache _fileCache; + private readonly BuiltinBundleCache _fileCache; private LoadBuiltinCatalogOperation _loadBuiltinCatalogOp; private ESteps _steps = ESteps.None; - public BFCInitializeOperation(BuiltinFileCache fileCache) + public BFCInitializeOperation(BuiltinBundleCache fileCache) { _fileCache = fileCache; } @@ -66,7 +66,7 @@ namespace YooAsset foreach (var fileEntry in catalog.FileEntries) { string filePath = PathUtility.Combine(_fileCache.RootPath, fileEntry.FileName); - var cacheEntry = new BuiltinFileCacheEntry(fileEntry.BundleGUID, filePath); + var cacheEntry = new BuiltinBundleCacheEntry(fileEntry.BundleGUID, filePath); _fileCache.AddEntry(fileEntry.BundleGUID, cacheEntry); } diff --git a/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/Operations/BFCInitializeOperation.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Services/BuiltinBundleCache/Operations/BBCInitializeOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/Operations/BFCInitializeOperation.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Services/BuiltinBundleCache/Operations/BBCInitializeOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/Operations/BFCLoadBundleOperation.cs b/Assets/YooAsset/Runtime/BundleCache/Services/BuiltinBundleCache/Operations/BBCLoadBundleOperation.cs similarity index 92% rename from Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/Operations/BFCLoadBundleOperation.cs rename to Assets/YooAsset/Runtime/BundleCache/Services/BuiltinBundleCache/Operations/BBCLoadBundleOperation.cs index e32f16d4..79ac3e2f 100644 --- a/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/Operations/BFCLoadBundleOperation.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Services/BuiltinBundleCache/Operations/BBCLoadBundleOperation.cs @@ -4,7 +4,7 @@ namespace YooAsset /// /// 内置文件缓存加载 AssetBundle 操作 /// - internal class BFCLoadAssetBundleOperation : FCLoadBundleOperation + internal class BFCLoadAssetBundleOperation : BCLoadBundleOperation { private enum ESteps { @@ -14,13 +14,13 @@ namespace YooAsset Done, } - private readonly BuiltinFileCache _fileCache; + private readonly BuiltinBundleCache _fileCache; private readonly PackageBundle _bundle; private LoadLocalAssetBundleOperation _loadLocalAssetBundleOp; - private BuiltinFileCacheEntry _cacheEntry; + private BuiltinBundleCacheEntry _cacheEntry; private ESteps _steps = ESteps.None; - public BFCLoadAssetBundleOperation(BuiltinFileCache fileCache, PackageBundle bundle) + public BFCLoadAssetBundleOperation(BuiltinBundleCache fileCache, PackageBundle bundle) { _fileCache = fileCache; _bundle = bundle; @@ -96,7 +96,7 @@ namespace YooAsset /// /// 内置文件缓存加载 RawBundle 操作 /// - internal class BFCLoadRawBundleOperation : FCLoadBundleOperation + internal class BFCLoadRawBundleOperation : BCLoadBundleOperation { private enum ESteps { @@ -106,13 +106,13 @@ namespace YooAsset Done, } - private readonly BuiltinFileCache _fileCache; + private readonly BuiltinBundleCache _fileCache; private readonly PackageBundle _bundle; private LoadLocalRawBundleOperation _loadLocalRawBundleOp; - private BuiltinFileCacheEntry _cacheEntry; + private BuiltinBundleCacheEntry _cacheEntry; private ESteps _steps = ESteps.None; - public BFCLoadRawBundleOperation(BuiltinFileCache fileCache, PackageBundle bundle) + public BFCLoadRawBundleOperation(BuiltinBundleCache fileCache, PackageBundle bundle) { _fileCache = fileCache; _bundle = bundle; diff --git a/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/Operations/BFCLoadBundleOperation.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Services/BuiltinBundleCache/Operations/BBCLoadBundleOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/Operations/BFCLoadBundleOperation.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Services/BuiltinBundleCache/Operations/BBCLoadBundleOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache.meta b/Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache.meta rename to Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/EditorFileCache.cs b/Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/EditorBundleCache.cs similarity index 61% rename from Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/EditorFileCache.cs rename to Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/EditorBundleCache.cs index d8c24eef..ae665764 100644 --- a/Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/EditorFileCache.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/EditorBundleCache.cs @@ -6,7 +6,7 @@ namespace YooAsset /// /// 编辑器文件缓存系统,用于编辑器模式下的资源模拟加载 /// - internal class EditorFileCache : IFileCache + internal class EditorBundleCache : IBundleCache { /// /// 编辑器文件缓存配置 @@ -34,7 +34,7 @@ namespace YooAsset public int AsyncSimulateMaxFrame { get; set; } } - private readonly Dictionary _cacheEntries = new Dictionary(10000); + private readonly Dictionary _cacheEntries = new Dictionary(10000); /// /// 缓存配置 @@ -81,7 +81,7 @@ namespace YooAsset /// 包裹名称 /// 缓存根目录 /// 缓存配置 - public EditorFileCache(string packageName, string rootPath, CacheConfig config) + public EditorBundleCache(string packageName, string rootPath, CacheConfig config) { PackageName = packageName; RootPath = rootPath; @@ -91,37 +91,60 @@ namespace YooAsset public void Dispose() { } - public virtual FCInitializeOperation InitializeAsync() + public virtual BCInitializeOperation InitializeAsync() { - var operation = new EFCInitializeOperation(this); + var operation = new EBCInitializeOperation(this); return operation; } - public virtual FCWriteCacheOperation WriteCacheAsync(FCWriteCacheOptions options) + public virtual BCWriteCacheOperation WriteCacheAsync(BCWriteCacheOptions options) { - var operation = new EFCWriteCacheOperation(this, options); + var operation = new EBCWriteCacheOperation(this, options); return operation; } - public virtual FCClearCacheOperation ClearCacheAsync(FCClearCacheOptions options) + public virtual BCClearCacheOperation ClearCacheAsync(BCClearCacheOptions options) { - var operation = new EFCClearCacheOperation(this, options); + ICacheEvictionPolicy policy = CreateEvictionPolicy(options); + if (policy == null) + return new BCClearCacheCompleteOperation($"Invalid clear mode: {options.ClearMode}"); + + return new EBCClearCacheOperation(this, options, policy); + } + + /// + /// 根据 ClearMode 创建对应的淘汰策略实例 + /// + protected virtual ICacheEvictionPolicy CreateEvictionPolicy(BCClearCacheOptions options) + { + if (options.ClearMode == EFileClearMode.ClearAllBundleFiles.ToString()) + return new EvictionAllPolicy(); + if (options.ClearMode == EFileClearMode.ClearUnusedBundleFiles.ToString()) + return new EvictionUnusedPolicy(); + if (options.ClearMode == EFileClearMode.ClearBundleFilesByLocations.ToString()) + return new EvictionByLocationsPolicy(); + if (options.ClearMode == EFileClearMode.ClearBundleFilesByTags.ToString()) + return new EvictionByTagsPolicy(); + + if (options.ClearParam is ICacheEvictionPolicy customPolicy) + return customPolicy; + + return null; + } + public virtual BCVerifyCacheOperation VerifyCacheAsync(BCVerifyCacheOptions options) + { + var operation = new BCVerifyCacheCompleteOperation(); return operation; } - public virtual FCVerifyCacheOperation VerifyCacheAsync(FCVerifyCacheOptions options) - { - var operation = new FCVerifyCacheCompleteOperation(); - return operation; - } - public virtual FCLoadBundleOperation LoadBundleAsync(FCLoadBundleOptions options) + public virtual BCLoadBundleOperation LoadBundleAsync(BCLoadBundleOptions options) { if (options.Bundle.BundleType == (int)EBundleType.VirtualBundle) { - var operation = new EFCLoadBundleOperation(this, options.Bundle); + var operation = new EBCLoadBundleOperation(this, options.Bundle); return operation; } else { - string error = $"{nameof(EditorFileCache)} does not support bundle type: {options.Bundle.BundleType}"; - var operation = new FCLoadBundleErrorOperation(error); + string error = $"{nameof(EditorBundleCache)} does not support bundle type: {options.Bundle.BundleType}"; + var operation = new BCLoadBundleErrorOperation(error); return operation; } } @@ -137,7 +160,7 @@ namespace YooAsset /// /// 获取所有缓存条目 /// - internal IReadOnlyCollection GetAllEntries() + internal IReadOnlyCollection GetAllEntries() { return _cacheEntries.Values; } @@ -145,7 +168,7 @@ namespace YooAsset /// /// 添加指定缓存条目 /// - internal void AddEntry(string bundleGUID, EditorFileCacheEntry cacheEntry) + internal void AddEntry(string bundleGUID, EditorBundleCacheEntry cacheEntry) { if (_cacheEntries.ContainsKey(bundleGUID)) throw new YooInternalException($"Cache entry already exists: {bundleGUID}"); @@ -158,7 +181,7 @@ namespace YooAsset /// internal void RemoveEntry(string bundleGUID) { - if (_cacheEntries.TryGetValue(bundleGUID, out EditorFileCacheEntry entry)) + if (_cacheEntries.TryGetValue(bundleGUID, out EditorBundleCacheEntry entry)) { _cacheEntries.Remove(bundleGUID); } diff --git a/Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/EditorFileCache.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/EditorBundleCache.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/EditorFileCache.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/EditorBundleCache.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/EditorFileCacheEntry.cs b/Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/EditorBundleCacheEntry.cs similarity index 84% rename from Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/EditorFileCacheEntry.cs rename to Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/EditorBundleCacheEntry.cs index 55fcc890..70a99fbd 100644 --- a/Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/EditorFileCacheEntry.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/EditorBundleCacheEntry.cs @@ -4,7 +4,7 @@ namespace YooAsset /// /// 编辑器文件缓存条目 /// - internal class EditorFileCacheEntry : ICacheEntry + internal class EditorBundleCacheEntry : ICacheEntry { /// /// 资源包唯一标识 @@ -21,7 +21,7 @@ namespace YooAsset /// /// 资源包唯一标识 /// 资源包文件路径 - public EditorFileCacheEntry(string bundleGUID, string filePath) + public EditorBundleCacheEntry(string bundleGUID, string filePath) { BundleGUID = bundleGUID; FilePath = filePath; diff --git a/Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/EditorFileCacheEntry.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/EditorBundleCacheEntry.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/EditorFileCacheEntry.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/EditorBundleCacheEntry.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/Operations.meta b/Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/Operations.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/Operations.meta rename to Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/Operations.meta diff --git a/Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/Operations/EBCClearCacheOperation.cs b/Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/Operations/EBCClearCacheOperation.cs new file mode 100644 index 00000000..3f8acec4 --- /dev/null +++ b/Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/Operations/EBCClearCacheOperation.cs @@ -0,0 +1,72 @@ +using System.Collections.Generic; + +namespace YooAsset +{ + /// + /// 清理编辑器文件缓存操作 + /// + internal sealed class EBCClearCacheOperation : BCClearCacheOperation + { + private enum ESteps + { + None, + GetResult, + ClearCacheFiles, + Done, + } + + private readonly EditorBundleCache _fileCache; + private readonly BCClearCacheOptions _options; + private readonly ICacheEvictionPolicy _policy; + private List _bundleGUIDs; + private ESteps _steps = ESteps.None; + + internal EBCClearCacheOperation(EditorBundleCache fileCache, BCClearCacheOptions options, ICacheEvictionPolicy policy) + { + _fileCache = fileCache; + _options = options; + _policy = policy; + } + internal override void InternalStart() + { + _steps = ESteps.GetResult; + } + internal override void InternalUpdate() + { + if (_steps == ESteps.None || _steps == ESteps.Done) + return; + + if (_steps == ESteps.GetResult) + { + var cacheEntries = _fileCache.GetAllEntries(); + EvictionResult clearResult = _policy.SelectEvictionTargets(cacheEntries, _options); + + if (clearResult.Succeeded == false) + { + _steps = ESteps.Done; + Status = EOperationStatus.Failed; + Error = clearResult.Error; + return; + } + + _bundleGUIDs = clearResult.BundleGUIDs; + _steps = ESteps.ClearCacheFiles; + } + + if (_steps == ESteps.ClearCacheFiles) + { + foreach (var bundleGUID in _bundleGUIDs) + { + _fileCache.RemoveEntry(bundleGUID); + } + + _steps = ESteps.Done; + Status = EOperationStatus.Succeeded; + } + } + internal override void InternalWaitForCompletion() + { + ExecuteBatch(); + } + } +} diff --git a/Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/Operations/EFCClearCacheOperation.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/Operations/EBCClearCacheOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/Operations/EFCClearCacheOperation.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/Operations/EBCClearCacheOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/Operations/EFCInitializeOperation.cs b/Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/Operations/EBCInitializeOperation.cs similarity index 66% rename from Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/Operations/EFCInitializeOperation.cs rename to Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/Operations/EBCInitializeOperation.cs index 615e92f9..e0d6a597 100644 --- a/Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/Operations/EFCInitializeOperation.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/Operations/EBCInitializeOperation.cs @@ -4,11 +4,11 @@ namespace YooAsset /// /// 编辑器文件缓存初始化操作 /// - internal class EFCInitializeOperation : FCInitializeOperation + internal class EBCInitializeOperation : BCInitializeOperation { - private readonly EditorFileCache _fileCache; + private readonly EditorBundleCache _fileCache; - public EFCInitializeOperation(EditorFileCache cache) + public EBCInitializeOperation(EditorBundleCache cache) { _fileCache = cache; } diff --git a/Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/Operations/EFCInitializeOperation.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/Operations/EBCInitializeOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/Operations/EFCInitializeOperation.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/Operations/EBCInitializeOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/Operations/EFCLoadBundleOperation.cs b/Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/Operations/EBCLoadBundleOperation.cs similarity index 93% rename from Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/Operations/EFCLoadBundleOperation.cs rename to Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/Operations/EBCLoadBundleOperation.cs index a274e7c8..29d58a59 100644 --- a/Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/Operations/EFCLoadBundleOperation.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/Operations/EBCLoadBundleOperation.cs @@ -4,7 +4,7 @@ namespace YooAsset /// /// 编辑器文件缓存加载资源包操作 /// - internal class EFCLoadBundleOperation : FCLoadBundleOperation + internal class EBCLoadBundleOperation : BCLoadBundleOperation { private enum ESteps { @@ -15,13 +15,13 @@ namespace YooAsset Done, } - private readonly EditorFileCache _fileCache; + private readonly EditorBundleCache _fileCache; private readonly PackageBundle _bundle; private int _asyncSimulateFrame; private string _editorFilePath; private ESteps _steps = ESteps.None; - public EFCLoadBundleOperation(EditorFileCache fileCache, PackageBundle bundle) + public EBCLoadBundleOperation(EditorBundleCache fileCache, PackageBundle bundle) { _fileCache = fileCache; _bundle = bundle; diff --git a/Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/Operations/EFCLoadBundleOperation.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/Operations/EBCLoadBundleOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/Operations/EFCLoadBundleOperation.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/Operations/EBCLoadBundleOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/Operations/EFCWriteCacheOperation.cs b/Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/Operations/EBCWriteCacheOperation.cs similarity index 79% rename from Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/Operations/EFCWriteCacheOperation.cs rename to Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/Operations/EBCWriteCacheOperation.cs index 75a2f422..e80f6d5d 100644 --- a/Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/Operations/EFCWriteCacheOperation.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/Operations/EBCWriteCacheOperation.cs @@ -4,7 +4,7 @@ namespace YooAsset /// /// 编辑器文件缓存写入操作 /// - internal class EFCWriteCacheOperation : FCWriteCacheOperation + internal class EBCWriteCacheOperation : BCWriteCacheOperation { private enum ESteps { @@ -14,11 +14,11 @@ namespace YooAsset Done, } - private readonly EditorFileCache _fileCache; - private readonly FCWriteCacheOptions _options; + private readonly EditorBundleCache _fileCache; + private readonly BCWriteCacheOptions _options; private ESteps _steps = ESteps.None; - public EFCWriteCacheOperation(EditorFileCache cache, FCWriteCacheOptions options) + public EBCWriteCacheOperation(EditorBundleCache cache, BCWriteCacheOptions options) { _fileCache = cache; _options = options; @@ -48,7 +48,7 @@ namespace YooAsset if (_steps == ESteps.CacheFile) { - var cacheEntry = new EditorFileCacheEntry(_options.Bundle.BundleGUID, _options.FilePath); + var cacheEntry = new EditorBundleCacheEntry(_options.Bundle.BundleGUID, _options.FilePath); _fileCache.AddEntry(_options.Bundle.BundleGUID, cacheEntry); _steps = ESteps.Done; Status = EOperationStatus.Succeeded; diff --git a/Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/Operations/EFCWriteCacheOperation.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/Operations/EBCWriteCacheOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/Operations/EFCWriteCacheOperation.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/Operations/EBCWriteCacheOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache.meta b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache.meta rename to Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/EFileClearMode.cs b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/EFileClearMode.cs similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/EFileClearMode.cs rename to Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/EFileClearMode.cs diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/EFileClearMode.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/EFileClearMode.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/EFileClearMode.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/EFileClearMode.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/EFileVerifyLevel.cs b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/EFileVerifyLevel.cs similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/EFileVerifyLevel.cs rename to Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/EFileVerifyLevel.cs diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/EFileVerifyLevel.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/EFileVerifyLevel.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/EFileVerifyLevel.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/EFileVerifyLevel.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/EFileVerifyResult.cs b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/EFileVerifyResult.cs similarity index 51% rename from Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/EFileVerifyResult.cs rename to Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/EFileVerifyResult.cs index 1d48c022..d1a458da 100644 --- a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/EFileVerifyResult.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/EFileVerifyResult.cs @@ -1,4 +1,4 @@ - + namespace YooAsset { /// @@ -7,44 +7,54 @@ namespace YooAsset internal enum EFileVerifyResult { /// - /// 验证异常 + /// 信息文件内容无效 /// - Exception = -8, + InfoFileInvalid = -24, /// - /// 数据无效 + /// 信息文件头标识不匹配 /// - BytesDataInvalid = -7, - + InfoFileMagicError = -23, + /// - /// 未找到缓存信息 + /// 信息文件版本不匹配 /// - CacheNotFound = -6, + InfoFileVersionError = -22, /// /// 信息文件不存在 /// - InfoFileNotExisted = -5, + InfoFileNotExisted = -21, + + /// + /// 数据文件内容无效 + /// + DataFileInvalid = -15, + + /// + /// 数据文件内容不足(小于正常大小) + /// + DataFileNotComplete = -14, + + /// + /// 数据文件内容溢出(超过正常大小) + /// + DataFileOverflow = -13, + + /// + /// 数据文件内容不匹配 + /// + DataFileCrcError = -12, /// /// 数据文件不存在 /// - DataFileNotExisted = -4, + DataFileNotExisted = -11, /// - /// 文件内容不足(小于正常大小) + /// 验证异常 /// - FileNotComplete = -3, - - /// - /// 文件内容溢出(超过正常大小) - /// - FileOverflow = -2, - - /// - /// 文件内容不匹配 - /// - FileCrcError = -1, + Exception = -1, /// /// 默认状态(校验未完成) diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/EFileVerifyResult.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/EFileVerifyResult.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/EFileVerifyResult.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/EFileVerifyResult.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/FileVerifyTools.cs b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/FileVerifyTools.cs similarity index 86% rename from Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/FileVerifyTools.cs rename to Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/FileVerifyTools.cs index fa9bc207..87bbe2c9 100644 --- a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/FileVerifyTools.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/FileVerifyTools.cs @@ -27,9 +27,9 @@ namespace YooAsset { long size = FileUtility.GetFileSize(filePath); if (size < fileSize) - return EFileVerifyResult.FileNotComplete; + return EFileVerifyResult.DataFileNotComplete; else if (size > fileSize) - return EFileVerifyResult.FileOverflow; + return EFileVerifyResult.DataFileOverflow; } // 可选条件:验证文件CRC @@ -39,7 +39,7 @@ namespace YooAsset if (crc == fileCRC) return EFileVerifyResult.Succeed; else - return EFileVerifyResult.FileCrcError; + return EFileVerifyResult.DataFileCrcError; } else { @@ -65,16 +65,16 @@ namespace YooAsset try { if (fileData == null || fileData.Length == 0) - return EFileVerifyResult.BytesDataInvalid; + return EFileVerifyResult.DataFileInvalid; // 可选条件:验证文件大小 if (fileSize > 0) { long size = fileData.Length; if (size < fileSize) - return EFileVerifyResult.FileNotComplete; + return EFileVerifyResult.DataFileNotComplete; else if (size > fileSize) - return EFileVerifyResult.FileOverflow; + return EFileVerifyResult.DataFileOverflow; } // 可选条件:验证文件CRC @@ -84,7 +84,7 @@ namespace YooAsset if (crc == fileCRC) return EFileVerifyResult.Succeed; else - return EFileVerifyResult.FileCrcError; + return EFileVerifyResult.DataFileCrcError; } else { diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/FileVerifyTools.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/FileVerifyTools.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/FileVerifyTools.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/FileVerifyTools.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations.meta b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations.meta rename to Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/Internal.meta b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations/Internal.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/Internal.meta rename to Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations/Internal.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/Internal/ClearCacheFilesOperation.cs b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations/Internal/ClearCacheFilesOperation.cs similarity index 93% rename from Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/Internal/ClearCacheFilesOperation.cs rename to Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations/Internal/ClearCacheFilesOperation.cs index 9d156836..ef833227 100644 --- a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/Internal/ClearCacheFilesOperation.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations/Internal/ClearCacheFilesOperation.cs @@ -15,12 +15,12 @@ namespace YooAsset Done, } - private readonly SandboxFileCache _fileCache; + private readonly SandboxBundleCache _fileCache; private readonly List _bundleGUIDs; private int _fileTotalCount; private ESteps _steps = ESteps.None; - public ClearCacheFilesOperation(SandboxFileCache fileCache, List bundleGUIDs) + public ClearCacheFilesOperation(SandboxBundleCache fileCache, List bundleGUIDs) { _fileCache = fileCache; _bundleGUIDs = bundleGUIDs; diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/Internal/ClearCacheFilesOperation.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations/Internal/ClearCacheFilesOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/Internal/ClearCacheFilesOperation.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations/Internal/ClearCacheFilesOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/Internal/SearchCacheFilesOperation.cs b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations/Internal/SearchCacheFilesOperation.cs similarity index 93% rename from Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/Internal/SearchCacheFilesOperation.cs rename to Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations/Internal/SearchCacheFilesOperation.cs index c2fabfe9..5ff246da 100644 --- a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/Internal/SearchCacheFilesOperation.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations/Internal/SearchCacheFilesOperation.cs @@ -18,7 +18,7 @@ namespace YooAsset Done, } - private readonly SandboxFileCache _fileCache; + private readonly SandboxBundleCache _fileCache; private IEnumerator _filesEnumerator = null; private double _verifyStartTime; private ESteps _steps = ESteps.None; @@ -29,7 +29,7 @@ namespace YooAsset public readonly List Result = new List(5000); - internal SearchCacheFilesOperation(SandboxFileCache fileCache) + internal SearchCacheFilesOperation(SandboxBundleCache fileCache) { _fileCache = fileCache; } @@ -92,8 +92,8 @@ namespace YooAsset // 创建验证元素类 string fileRootPath = childDirectory; - string dataFilePath = PathUtility.Combine(fileRootPath, SandboxFileCacheConsts.BundleDataFileName); - string infoFilePath = PathUtility.Combine(fileRootPath, SandboxFileCacheConsts.BundleInfoFileName); + string dataFilePath = PathUtility.Combine(fileRootPath, SandboxBundleCacheConsts.BundleDataFileName); + string infoFilePath = PathUtility.Combine(fileRootPath, SandboxBundleCacheConsts.BundleInfoFileName); var element = new SearchFileInfo(bundleGUID, fileRootPath, dataFilePath, infoFilePath); Result.Add(element); } diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/Internal/SearchCacheFilesOperation.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations/Internal/SearchCacheFilesOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/Internal/SearchCacheFilesOperation.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations/Internal/SearchCacheFilesOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/Internal/VerifyCacheFilesOperation.cs b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations/Internal/VerifyCacheFilesOperation.cs similarity index 77% rename from Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/Internal/VerifyCacheFilesOperation.cs rename to Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations/Internal/VerifyCacheFilesOperation.cs index de8c1370..1dc6f9c5 100644 --- a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/Internal/VerifyCacheFilesOperation.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations/Internal/VerifyCacheFilesOperation.cs @@ -19,7 +19,7 @@ namespace YooAsset Done, } - private readonly SandboxFileCache _fileCache; + private readonly SandboxBundleCache _fileCache; private readonly EFileVerifyLevel _verifyLevel; private readonly int _fileVerifyMaxConcurrency; private readonly List _pendingVerifyList; @@ -32,7 +32,7 @@ namespace YooAsset private ESteps _steps = ESteps.None; - internal VerifyCacheFilesOperation(SandboxFileCache fileCache, EFileVerifyLevel verifyLevel, int fileVerifyMaxConcurrency, List elements) + internal VerifyCacheFilesOperation(SandboxBundleCache fileCache, EFileVerifyLevel verifyLevel, int fileVerifyMaxConcurrency, List elements) { _fileCache = fileCache; _verifyLevel = verifyLevel; @@ -76,7 +76,7 @@ namespace YooAsset if (resultCode == (int)EFileVerifyResult.Succeed) { _successCount++; - var cacheEntry = new SandboxFileCacheEntry(verifyElement.BundleGUID, verifyElement.InfoFilePath, verifyElement.DataFilePath); + var cacheEntry = new SandboxBundleCacheEntry(verifyElement.BundleGUID, verifyElement.InfoFilePath, verifyElement.DataFilePath); _fileCache.AddEntry(verifyElement.BundleGUID, cacheEntry); } else @@ -138,25 +138,32 @@ namespace YooAsset if (File.Exists(element.DataFilePath) == false) return EFileVerifyResult.DataFileNotExisted; - if (verifyLevel == EFileVerifyLevel.Low) - { - return EFileVerifyResult.Succeed; - } - else - { - // 解析信息文件填充验证数据 - byte[] binaryData = FileUtility.ReadAllBytes(element.InfoFilePath); - BufferReader buffer = new BufferReader(binaryData); - uint dataFileCRC = buffer.ReadUInt32(); - long dataFileSize = buffer.ReadInt64(); + byte[] binaryData = FileUtility.ReadAllBytes(element.InfoFilePath); + if (binaryData.Length < SandboxBundleCacheConsts.InfoFileExpectedSize) + return EFileVerifyResult.InfoFileInvalid; - if (verifyLevel == EFileVerifyLevel.Middle) - return FileVerifyTools.FileVerify(element.DataFilePath, dataFileSize, 0); - else if (verifyLevel == EFileVerifyLevel.High) - return FileVerifyTools.FileVerify(element.DataFilePath, dataFileSize, dataFileCRC); - else - throw new System.NotImplementedException(verifyLevel.ToString()); - } + var reader = new BufferReader(binaryData); + uint magic = reader.ReadUInt32(); + if (magic != SandboxBundleCacheConsts.InfoFileMagic) + return EFileVerifyResult.InfoFileMagicError; + + int version = reader.ReadInt32(); + if (version != SandboxBundleCacheConsts.InfoFileVersion) + return EFileVerifyResult.InfoFileVersionError; + + uint dataFileCRC = reader.ReadUInt32(); + long dataFileSize = reader.ReadInt64(); + long createdAtTicks = reader.ReadInt64(); + long lastAccessAtTicks = reader.ReadInt64(); + + if (verifyLevel == EFileVerifyLevel.Low) + return EFileVerifyResult.Succeed; + else if (verifyLevel == EFileVerifyLevel.Middle) + return FileVerifyTools.FileVerify(element.DataFilePath, dataFileSize, 0); + else if (verifyLevel == EFileVerifyLevel.High) + return FileVerifyTools.FileVerify(element.DataFilePath, dataFileSize, dataFileCRC); + else + throw new System.NotImplementedException(verifyLevel.ToString()); } catch (Exception ex) { diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/Internal/VerifyCacheFilesOperation.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations/Internal/VerifyCacheFilesOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/Internal/VerifyCacheFilesOperation.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations/Internal/VerifyCacheFilesOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/Internal/VerifyTempFileOperation.cs b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations/Internal/VerifyTempFileOperation.cs similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/Internal/VerifyTempFileOperation.cs rename to Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations/Internal/VerifyTempFileOperation.cs diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/Internal/VerifyTempFileOperation.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations/Internal/VerifyTempFileOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/Internal/VerifyTempFileOperation.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations/Internal/VerifyTempFileOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/SFCClearCacheOperation.cs b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations/SBCClearCacheOperation.cs similarity index 59% rename from Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/SFCClearCacheOperation.cs rename to Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations/SBCClearCacheOperation.cs index cb90a4bf..f96779d4 100644 --- a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/SFCClearCacheOperation.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations/SBCClearCacheOperation.cs @@ -2,9 +2,9 @@ namespace YooAsset { /// - /// 清理沙盒文件缓存操作 + /// 沙盒文件缓存清理操作 /// - internal class SFCClearCacheOperation : FCClearCacheOperation + internal sealed class SBCClearCacheOperation : BCClearCacheOperation { private enum ESteps { @@ -14,16 +14,19 @@ namespace YooAsset Done, } - private readonly SandboxFileCache _fileCache; - private readonly FCClearCacheOptions _options; + private readonly SandboxBundleCache _fileCache; + private readonly BCClearCacheOptions _options; + private readonly ICacheEvictionPolicy _policy; private ClearCacheFilesOperation _clearCacheFilesOp; private ESteps _steps = ESteps.None; - internal SFCClearCacheOperation(SandboxFileCache fileCache, FCClearCacheOptions options) + internal SBCClearCacheOperation(SandboxBundleCache fileCache, BCClearCacheOptions options, ICacheEvictionPolicy policy) { _fileCache = fileCache; _options = options; + _policy = policy; } + internal override void InternalStart() { _steps = ESteps.GetResult; @@ -35,30 +38,8 @@ namespace YooAsset if (_steps == ESteps.GetResult) { - ClearResult clearResult; - if (_options.ClearMode == EFileClearMode.ClearAllBundleFiles.ToString()) - { - clearResult = GetAllCache(_fileCache.GetAllEntries()); - } - else if (_options.ClearMode == EFileClearMode.ClearUnusedBundleFiles.ToString()) - { - clearResult = GetUnusedCache(_options, _fileCache.GetAllEntries()); - } - else if (_options.ClearMode == EFileClearMode.ClearBundleFilesByLocations.ToString()) - { - clearResult = GetCacheByLocations(_options, _fileCache.GetAllEntries()); - } - else if (_options.ClearMode == EFileClearMode.ClearBundleFilesByTags.ToString()) - { - clearResult = GetCacheByTags(_options, _fileCache.GetAllEntries()); - } - else - { - _steps = ESteps.Done; - Status = EOperationStatus.Failed; - Error = $"Invalid clear mode: {_options.ClearMode}"; - return; - } + var cacheEntries = _fileCache.GetAllEntries(); + EvictionResult clearResult = _policy.SelectEvictionTargets(cacheEntries, _options); if (clearResult.Succeeded == false) { diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/SFCClearCacheOperation.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations/SBCClearCacheOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/SFCClearCacheOperation.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations/SBCClearCacheOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/SFCInitializeOperation.cs b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations/SBCInitializeOperation.cs similarity index 93% rename from Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/SFCInitializeOperation.cs rename to Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations/SBCInitializeOperation.cs index 0f26501b..59287ef7 100644 --- a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/SFCInitializeOperation.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations/SBCInitializeOperation.cs @@ -4,7 +4,7 @@ namespace YooAsset /// /// 沙盒文件缓存初始化操作 /// - internal class SFCInitializeOperation : FCInitializeOperation + internal class SBCInitializeOperation : BCInitializeOperation { private enum ESteps { @@ -14,12 +14,12 @@ namespace YooAsset Done, } - private readonly SandboxFileCache _fileCache; + private readonly SandboxBundleCache _fileCache; private SearchCacheFilesOperation _searchCacheFilesOp; private VerifyCacheFilesOperation _verifyCacheFilesOp; private ESteps _steps = ESteps.None; - public SFCInitializeOperation(SandboxFileCache fileCache) + public SBCInitializeOperation(SandboxBundleCache fileCache) { _fileCache = fileCache; } diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/SFCInitializeOperation.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations/SBCInitializeOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/SFCInitializeOperation.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations/SBCInitializeOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/SFCLoadBundleOperation.cs b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations/SBCLoadBundleOperation.cs similarity index 93% rename from Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/SFCLoadBundleOperation.cs rename to Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations/SBCLoadBundleOperation.cs index 2ed18202..c0b91bac 100644 --- a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/SFCLoadBundleOperation.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations/SBCLoadBundleOperation.cs @@ -7,7 +7,7 @@ namespace YooAsset /// /// 沙盒文件缓存加载 AssetBundle 操作 /// - internal class SFCLoadAssetBundleOperation : FCLoadBundleOperation + internal class SBCLoadAssetBundleOperation : BCLoadBundleOperation { private enum ESteps { @@ -19,14 +19,14 @@ namespace YooAsset Done, } - private readonly SandboxFileCache _fileCache; + private readonly SandboxBundleCache _fileCache; private readonly PackageBundle _bundle; private LoadLocalAssetBundleOperation _loadLocalAssetBundleOp; - private FCVerifyCacheOperation _verifyCacheOp; - private SandboxFileCacheEntry _cacheEntry; + private BCVerifyCacheOperation _verifyCacheOp; + private SandboxBundleCacheEntry _cacheEntry; private ESteps _steps = ESteps.None; - public SFCLoadAssetBundleOperation(SandboxFileCache fileCache, PackageBundle bundle) + public SBCLoadAssetBundleOperation(SandboxBundleCache fileCache, PackageBundle bundle) { _fileCache = fileCache; _bundle = bundle; @@ -107,7 +107,7 @@ namespace YooAsset // 说明:在AssetBundle文件加载失败的情况下,我们需要重新验证文件的完整性! if (_verifyCacheOp == null) { - var options = new FCVerifyCacheOptions(); + var options = new BCVerifyCacheOptions(); options.Bundle = _bundle; options.DeleteCacheEntryOnFailure = true; _verifyCacheOp = _fileCache.VerifyCacheAsync(options); @@ -146,7 +146,7 @@ namespace YooAsset { _steps = ESteps.Done; Status = EOperationStatus.Failed; - Error = $"{nameof(SandboxFileCache)} fallback decryptor is null."; + Error = $"{nameof(SandboxBundleCache)} fallback decryptor is null."; return; } @@ -200,7 +200,7 @@ namespace YooAsset /// /// 沙盒文件缓存加载 RawBundle 操作 /// - internal class SFCLoadRawBundleOperation : FCLoadBundleOperation + internal class SBCLoadRawBundleOperation : BCLoadBundleOperation { private enum ESteps { @@ -210,14 +210,14 @@ namespace YooAsset Done, } - private readonly SandboxFileCache _fileCache; + private readonly SandboxBundleCache _fileCache; private readonly PackageBundle _bundle; private LoadLocalRawBundleOperation _loadLocalRawBundleOp; - private SandboxFileCacheEntry _cacheEntry; + private SandboxBundleCacheEntry _cacheEntry; private ESteps _steps = ESteps.None; - public SFCLoadRawBundleOperation(SandboxFileCache fileCache, PackageBundle bundle) + public SBCLoadRawBundleOperation(SandboxBundleCache fileCache, PackageBundle bundle) { _fileCache = fileCache; _bundle = bundle; @@ -291,7 +291,7 @@ namespace YooAsset } #if TUANJIE_1_7_OR_NEWER - internal class SFCLoadInstantBundleOperation : FCLoadBundleOperation + internal class SBCLoadInstantBundleOperation : BCLoadBundleOperation { private enum ESteps { diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/SFCLoadBundleOperation.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations/SBCLoadBundleOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/SFCLoadBundleOperation.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations/SBCLoadBundleOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/SFCVerifyCacheOperation.cs b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations/SBCVerifyCacheOperation.cs similarity index 91% rename from Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/SFCVerifyCacheOperation.cs rename to Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations/SBCVerifyCacheOperation.cs index f31d8098..932471b4 100644 --- a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/SFCVerifyCacheOperation.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations/SBCVerifyCacheOperation.cs @@ -4,7 +4,7 @@ namespace YooAsset /// /// 沙盒文件缓存验证操作 /// - internal class SFCVerifyCacheOperation : FCVerifyCacheOperation + internal class SBCVerifyCacheOperation : BCVerifyCacheOperation { private enum ESteps { @@ -14,12 +14,12 @@ namespace YooAsset Done, } - private readonly SandboxFileCache _fileCache; - private readonly FCVerifyCacheOptions _options; + private readonly SandboxBundleCache _fileCache; + private readonly BCVerifyCacheOptions _options; private VerifyTempFileOperation _verifyTempFileOp; private ESteps _steps = ESteps.None; - public SFCVerifyCacheOperation(SandboxFileCache cache, FCVerifyCacheOptions options) + public SBCVerifyCacheOperation(SandboxBundleCache cache, BCVerifyCacheOptions options) { _fileCache = cache; _options = options; diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/SFCVerifyCacheOperation.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations/SBCVerifyCacheOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/SFCVerifyCacheOperation.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations/SBCVerifyCacheOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/SFCWriteCacheOperation.cs b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations/SBCWriteCacheOperation.cs similarity index 84% rename from Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/SFCWriteCacheOperation.cs rename to Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations/SBCWriteCacheOperation.cs index b16aae7d..91bd2034 100644 --- a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/SFCWriteCacheOperation.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations/SBCWriteCacheOperation.cs @@ -6,7 +6,7 @@ namespace YooAsset /// /// 沙盒文件缓存写入操作 /// - internal class SFCWriteCacheOperation : FCWriteCacheOperation + internal class SBCWriteCacheOperation : BCWriteCacheOperation { private enum ESteps { @@ -17,12 +17,12 @@ namespace YooAsset Done, } - private readonly SandboxFileCache _fileCache; - private readonly FCWriteCacheOptions _options; + private readonly SandboxBundleCache _fileCache; + private readonly BCWriteCacheOptions _options; private VerifyTempFileOperation _verifyTempFileOp; private ESteps _steps = ESteps.None; - public SFCWriteCacheOperation(SandboxFileCache fileCache, FCWriteCacheOptions options) + public SBCWriteCacheOperation(SandboxBundleCache fileCache, BCWriteCacheOptions options) { _fileCache = fileCache; _options = options; @@ -86,6 +86,7 @@ namespace YooAsset string dataTempPath = _fileCache.GetDataTempFilePath(_options.Bundle); string infoTempPath = _fileCache.GetInfoTempFilePath(_options.Bundle); + long nowTicks = DateTime.UtcNow.Ticks; try { // 阶段A:准备目标目录,清理可能存在的残留文件 @@ -96,12 +97,15 @@ namespace YooAsset // 阶段B:写入临时文件 FileInfo fileInfo = new FileInfo(_options.FilePath); fileInfo.CopyTo(dataTempPath, true); - - using (FileStream fs = new FileStream(infoTempPath, FileMode.Create, FileAccess.Write, FileShare.Read)) + using (var fs = new FileStream(infoTempPath, FileMode.Create, FileAccess.Write, FileShare.None)) { - var buffer = new BufferWriter(128); + var buffer = new BufferWriter(64); + buffer.WriteUInt32(SandboxBundleCacheConsts.InfoFileMagic); + buffer.WriteInt32(SandboxBundleCacheConsts.InfoFileVersion); buffer.WriteUInt32(_options.Bundle.FileCRC); buffer.WriteInt64(_options.Bundle.FileSize); + buffer.WriteInt64(nowTicks); // CreatedAtTicks + buffer.WriteInt64(nowTicks); // LastAccessAtTicks buffer.WriteToStream(fs); fs.Flush(); } @@ -129,7 +133,7 @@ namespace YooAsset } // 阶段D:注册内存缓存条目 - var cacheEntry = new SandboxFileCacheEntry(_options.Bundle.BundleGUID, infoFilePath, dataFilePath); + var cacheEntry = new SandboxBundleCacheEntry(_options.Bundle.BundleGUID, infoFilePath, dataFilePath); _fileCache.AddEntry(_options.Bundle.BundleGUID, cacheEntry); _steps = ESteps.Done; Status = EOperationStatus.Succeeded; diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/SFCWriteCacheOperation.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations/SBCWriteCacheOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/SFCWriteCacheOperation.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations/SBCWriteCacheOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/SandboxFileCache.cs b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/SandboxBundleCache.cs similarity index 70% rename from Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/SandboxFileCache.cs rename to Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/SandboxBundleCache.cs index ba99302f..46087afe 100644 --- a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/SandboxFileCache.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/SandboxBundleCache.cs @@ -6,7 +6,7 @@ namespace YooAsset /// /// 沙盒文件缓存系统,用于管理下载到本地的资源包缓存 /// - internal class SandboxFileCache : IFileCache + internal class SandboxBundleCache : IBundleCache { /// /// 沙盒文件缓存配置 @@ -40,7 +40,7 @@ namespace YooAsset } private const int HashFolderNameLength = 2; - private readonly Dictionary _cacheEntries = new Dictionary(10000); + private readonly Dictionary _cacheEntries = new Dictionary(10000); private readonly Dictionary _dataFilePathMapping = new Dictionary(10000); private readonly Dictionary _infoFilePathMapping = new Dictionary(10000); @@ -89,7 +89,7 @@ namespace YooAsset /// 包裹名称 /// 缓存根目录 /// 缓存配置 - public SandboxFileCache(string packageName, string rootPath, CacheConfig config) + public SandboxBundleCache(string packageName, string rootPath, CacheConfig config) { PackageName = packageName; RootPath = rootPath; @@ -99,42 +99,65 @@ namespace YooAsset public void Dispose() { } - public virtual FCInitializeOperation InitializeAsync() + public virtual BCInitializeOperation InitializeAsync() { - var operation = new SFCInitializeOperation(this); + var operation = new SBCInitializeOperation(this); return operation; } - public virtual FCWriteCacheOperation WriteCacheAsync(FCWriteCacheOptions options) + public virtual BCWriteCacheOperation WriteCacheAsync(BCWriteCacheOptions options) { - var operation = new SFCWriteCacheOperation(this, options); + var operation = new SBCWriteCacheOperation(this, options); return operation; } - public virtual FCClearCacheOperation ClearCacheAsync(FCClearCacheOptions options) + public virtual BCClearCacheOperation ClearCacheAsync(BCClearCacheOptions options) { - var operation = new SFCClearCacheOperation(this, options); + ICacheEvictionPolicy policy = CreateEvictionPolicy(options); + if (policy == null) + return new BCClearCacheCompleteOperation($"Invalid clear mode: {options.ClearMode}"); + + return new SBCClearCacheOperation(this, options, policy); + } + + /// + /// 根据 ClearMode 创建对应的淘汰策略实例 + /// + protected virtual ICacheEvictionPolicy CreateEvictionPolicy(BCClearCacheOptions options) + { + if (options.ClearMode == EFileClearMode.ClearAllBundleFiles.ToString()) + return new EvictionAllPolicy(); + if (options.ClearMode == EFileClearMode.ClearUnusedBundleFiles.ToString()) + return new EvictionUnusedPolicy(); + if (options.ClearMode == EFileClearMode.ClearBundleFilesByLocations.ToString()) + return new EvictionByLocationsPolicy(); + if (options.ClearMode == EFileClearMode.ClearBundleFilesByTags.ToString()) + return new EvictionByTagsPolicy(); + + if (options.ClearParam is ICacheEvictionPolicy customPolicy) + return customPolicy; + + return null; + } + public virtual BCVerifyCacheOperation VerifyCacheAsync(BCVerifyCacheOptions options) + { + var operation = new SBCVerifyCacheOperation(this, options); return operation; } - public virtual FCVerifyCacheOperation VerifyCacheAsync(FCVerifyCacheOptions options) - { - var operation = new SFCVerifyCacheOperation(this, options); - return operation; - } - public virtual FCLoadBundleOperation LoadBundleAsync(FCLoadBundleOptions options) + public virtual BCLoadBundleOperation LoadBundleAsync(BCLoadBundleOptions options) { if (options.Bundle.BundleType == (int)EBundleType.AssetBundle) { - var operation = new SFCLoadAssetBundleOperation(this, options.Bundle); + var operation = new SBCLoadAssetBundleOperation(this, options.Bundle); return operation; } else if (options.Bundle.BundleType == (int)EBundleType.RawBundle) { - var operation = new SFCLoadRawBundleOperation(this, options.Bundle); + var operation = new SBCLoadRawBundleOperation(this, options.Bundle); return operation; } else { - string error = $"{nameof(SandboxFileCache)} does not support bundle type: {options.Bundle.BundleType}"; - var operation = new FCLoadBundleErrorOperation(error); + string error = $"{nameof(SandboxBundleCache)} does not support bundle type: {options.Bundle.BundleType}"; + var operation = new BCLoadBundleErrorOperation(error); return operation; } } @@ -152,7 +175,7 @@ namespace YooAsset if (_dataFilePathMapping.TryGetValue(bundle.BundleGUID, out string filePath) == false) { string folderName = GetHashFolderName(bundle.FileHash); - filePath = PathUtility.Combine(RootPath, folderName, bundle.BundleGUID, SandboxFileCacheConsts.BundleDataFileName); + filePath = PathUtility.Combine(RootPath, folderName, bundle.BundleGUID, SandboxBundleCacheConsts.BundleDataFileName); _dataFilePathMapping.Add(bundle.BundleGUID, filePath); } return filePath; @@ -166,7 +189,7 @@ namespace YooAsset if (_infoFilePathMapping.TryGetValue(bundle.BundleGUID, out string filePath) == false) { string folderName = GetHashFolderName(bundle.FileHash); - filePath = PathUtility.Combine(RootPath, folderName, bundle.BundleGUID, SandboxFileCacheConsts.BundleInfoFileName); + filePath = PathUtility.Combine(RootPath, folderName, bundle.BundleGUID, SandboxBundleCacheConsts.BundleInfoFileName); _infoFilePathMapping.Add(bundle.BundleGUID, filePath); } return filePath; @@ -178,7 +201,7 @@ namespace YooAsset internal string GetDataTempFilePath(PackageBundle bundle) { string folderName = GetHashFolderName(bundle.FileHash); - return PathUtility.Combine(RootPath, folderName, bundle.BundleGUID, SandboxFileCacheConsts.BundleDataTempFileName); + return PathUtility.Combine(RootPath, folderName, bundle.BundleGUID, SandboxBundleCacheConsts.BundleDataTempFileName); } /// @@ -187,15 +210,15 @@ namespace YooAsset internal string GetInfoTempFilePath(PackageBundle bundle) { string folderName = GetHashFolderName(bundle.FileHash); - return PathUtility.Combine(RootPath, folderName, bundle.BundleGUID, SandboxFileCacheConsts.BundleInfoTempFileName); + return PathUtility.Combine(RootPath, folderName, bundle.BundleGUID, SandboxBundleCacheConsts.BundleInfoTempFileName); } /// /// 获取指定缓存条目 /// - internal SandboxFileCacheEntry GetEntry(string bundleGUID) + internal SandboxBundleCacheEntry GetEntry(string bundleGUID) { - if (_cacheEntries.TryGetValue(bundleGUID, out SandboxFileCacheEntry entry)) + if (_cacheEntries.TryGetValue(bundleGUID, out SandboxBundleCacheEntry entry)) return entry; else return null; @@ -204,7 +227,7 @@ namespace YooAsset /// /// 获取所有缓存条目 /// - internal IReadOnlyCollection GetAllEntries() + internal IReadOnlyCollection GetAllEntries() { return _cacheEntries.Values; } @@ -212,7 +235,7 @@ namespace YooAsset /// /// 添加指定缓存条目 /// - internal void AddEntry(string bundleGUID, SandboxFileCacheEntry cacheEntry) + internal void AddEntry(string bundleGUID, SandboxBundleCacheEntry cacheEntry) { if (_cacheEntries.ContainsKey(bundleGUID)) throw new YooInternalException($"Cache entry already exists: {bundleGUID}"); @@ -226,7 +249,7 @@ namespace YooAsset /// internal void RemoveEntry(string bundleGUID) { - if (_cacheEntries.TryGetValue(bundleGUID, out SandboxFileCacheEntry entry)) + if (_cacheEntries.TryGetValue(bundleGUID, out SandboxBundleCacheEntry entry)) { _cacheEntries.Remove(bundleGUID); _dataFilePathMapping.Remove(bundleGUID); diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/SandboxFileCache.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/SandboxBundleCache.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/SandboxFileCache.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/SandboxBundleCache.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/SandboxFileCacheConsts.cs b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/SandboxBundleCacheConsts.cs similarity index 59% rename from Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/SandboxFileCacheConsts.cs rename to Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/SandboxBundleCacheConsts.cs index 3852e49d..3a5f9e22 100644 --- a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/SandboxFileCacheConsts.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/SandboxBundleCacheConsts.cs @@ -4,7 +4,7 @@ namespace YooAsset /// /// 沙盒文件缓存常量定义 /// - internal class SandboxFileCacheConsts + internal class SandboxBundleCacheConsts { /// /// 数据文件名称 @@ -25,5 +25,20 @@ namespace YooAsset /// 信息临时文件名称 /// public const string BundleInfoTempFileName = "__info.tmp"; + + /// + /// 信息文件头标识 (ASCII "YOC1") + /// + public const uint InfoFileMagic = 0x31434F59; + + /// + /// 信息文件版本号 + /// + public const int InfoFileVersion = 1; + + /// + /// 信息文件预期大小(字节) + /// + public const int InfoFileExpectedSize = 36; } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/SandboxFileCacheConsts.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/SandboxBundleCacheConsts.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/SandboxFileCacheConsts.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/SandboxBundleCacheConsts.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/SandboxFileCacheEntry.cs b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/SandboxBundleCacheEntry.cs similarity index 93% rename from Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/SandboxFileCacheEntry.cs rename to Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/SandboxBundleCacheEntry.cs index a9aa030e..ef07b8e6 100644 --- a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/SandboxFileCacheEntry.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/SandboxBundleCacheEntry.cs @@ -6,7 +6,7 @@ namespace YooAsset /// /// 沙盒文件缓存条目 /// - internal class SandboxFileCacheEntry : ICacheEntry + internal class SandboxBundleCacheEntry : ICacheEntry { private long _fileSize = -1; @@ -32,7 +32,7 @@ namespace YooAsset /// 资源包唯一标识 /// 信息文件路径 /// 数据文件路径 - public SandboxFileCacheEntry(string bundleGUID, string infoFilePath, string dataFilePath) + public SandboxBundleCacheEntry(string bundleGUID, string infoFilePath, string dataFilePath) { BundleGUID = bundleGUID; InfoFilePath = infoFilePath; diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/SandboxFileCacheEntry.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/SandboxBundleCacheEntry.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/SandboxFileCacheEntry.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/SandboxBundleCacheEntry.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/SearchFileInfo.cs b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/SearchFileInfo.cs similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/SearchFileInfo.cs rename to Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/SearchFileInfo.cs diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/SearchFileInfo.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/SearchFileInfo.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/SearchFileInfo.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/SearchFileInfo.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/TempFileInfo.cs b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/TempFileInfo.cs similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/TempFileInfo.cs rename to Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/TempFileInfo.cs diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/TempFileInfo.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/TempFileInfo.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/TempFileInfo.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/TempFileInfo.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/WebRemoteFileCache.meta b/Assets/YooAsset/Runtime/BundleCache/Services/WebRemoteBundleCache.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/WebRemoteFileCache.meta rename to Assets/YooAsset/Runtime/BundleCache/Services/WebRemoteBundleCache.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/WebRemoteFileCache/Operations.meta b/Assets/YooAsset/Runtime/BundleCache/Services/WebRemoteBundleCache/Operations.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/WebRemoteFileCache/Operations.meta rename to Assets/YooAsset/Runtime/BundleCache/Services/WebRemoteBundleCache/Operations.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/WebRemoteFileCache/Operations/WRFCInitializeOperation.cs b/Assets/YooAsset/Runtime/BundleCache/Services/WebRemoteBundleCache/Operations/WRBCInitializeOperation.cs similarity index 65% rename from Assets/YooAsset/Runtime/FileCache/Services/WebRemoteFileCache/Operations/WRFCInitializeOperation.cs rename to Assets/YooAsset/Runtime/BundleCache/Services/WebRemoteBundleCache/Operations/WRBCInitializeOperation.cs index 42a3eb58..6b6ead6b 100644 --- a/Assets/YooAsset/Runtime/FileCache/Services/WebRemoteFileCache/Operations/WRFCInitializeOperation.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Services/WebRemoteBundleCache/Operations/WRBCInitializeOperation.cs @@ -4,11 +4,11 @@ namespace YooAsset /// /// Web远端文件缓存初始化操作 /// - internal class WRFCInitializeOperation : FCInitializeOperation + internal class WRBCInitializeOperation : BCInitializeOperation { - private readonly WebRemoteFileCache _fileCache; + private readonly WebRemoteBundleCache _fileCache; - public WRFCInitializeOperation(WebRemoteFileCache cache) + public WRBCInitializeOperation(WebRemoteBundleCache cache) { _fileCache = cache; } diff --git a/Assets/YooAsset/Runtime/FileCache/Services/WebRemoteFileCache/Operations/WRFCInitializeOperation.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Services/WebRemoteBundleCache/Operations/WRBCInitializeOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/WebRemoteFileCache/Operations/WRFCInitializeOperation.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Services/WebRemoteBundleCache/Operations/WRBCInitializeOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/WebRemoteFileCache/Operations/WRFCLoadBundleOperation.cs b/Assets/YooAsset/Runtime/BundleCache/Services/WebRemoteBundleCache/Operations/WRBCLoadBundleOperation.cs similarity index 89% rename from Assets/YooAsset/Runtime/FileCache/Services/WebRemoteFileCache/Operations/WRFCLoadBundleOperation.cs rename to Assets/YooAsset/Runtime/BundleCache/Services/WebRemoteBundleCache/Operations/WRBCLoadBundleOperation.cs index d1fee9bf..14099e66 100644 --- a/Assets/YooAsset/Runtime/FileCache/Services/WebRemoteFileCache/Operations/WRFCLoadBundleOperation.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Services/WebRemoteBundleCache/Operations/WRBCLoadBundleOperation.cs @@ -4,7 +4,7 @@ namespace YooAsset /// /// Web远端文件缓存加载 AssetBundle 操作 /// - internal class WRFCLoadAssetBundleOperation : FCLoadBundleOperation + internal class WRBCLoadAssetBundleOperation : BCLoadBundleOperation { private enum ESteps { @@ -14,13 +14,13 @@ namespace YooAsset Done, } - private readonly WebRemoteFileCache _fileCache; - private readonly FCLoadBundleOptions _options; + private readonly WebRemoteBundleCache _fileCache; + private readonly BCLoadBundleOptions _options; private LoadWebAssetBundleOperation _loadWebAssetBundleOp; - private WebRemoteFileCacheEntry _cacheEntry; + private WebRemoteBundleCacheEntry _cacheEntry; private ESteps _steps = ESteps.None; - public WRFCLoadAssetBundleOperation(WebRemoteFileCache fileCache, FCLoadBundleOptions options) + public WRBCLoadAssetBundleOperation(WebRemoteBundleCache fileCache, BCLoadBundleOptions options) { _fileCache = fileCache; _options = options; @@ -101,7 +101,7 @@ namespace YooAsset { _steps = ESteps.Done; Status = EOperationStatus.Failed; - Error = $"{nameof(WebRemoteFileCache)} does not support synchronous asset bundle loading."; + Error = $"{nameof(WebRemoteBundleCache)} does not support synchronous asset bundle loading."; YooLogger.Error(Error); } } diff --git a/Assets/YooAsset/Runtime/FileCache/Services/WebRemoteFileCache/Operations/WRFCLoadBundleOperation.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Services/WebRemoteBundleCache/Operations/WRBCLoadBundleOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/WebRemoteFileCache/Operations/WRFCLoadBundleOperation.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Services/WebRemoteBundleCache/Operations/WRBCLoadBundleOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/WebRemoteFileCache/WebRemoteFileCache.cs b/Assets/YooAsset/Runtime/BundleCache/Services/WebRemoteBundleCache/WebRemoteBundleCache.cs similarity index 73% rename from Assets/YooAsset/Runtime/FileCache/Services/WebRemoteFileCache/WebRemoteFileCache.cs rename to Assets/YooAsset/Runtime/BundleCache/Services/WebRemoteBundleCache/WebRemoteBundleCache.cs index fe402aa7..6011a53d 100644 --- a/Assets/YooAsset/Runtime/FileCache/Services/WebRemoteFileCache/WebRemoteFileCache.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Services/WebRemoteBundleCache/WebRemoteBundleCache.cs @@ -6,7 +6,7 @@ namespace YooAsset /// /// Web远端文件缓存系统,用于从远程服务器加载资源 /// - internal class WebRemoteFileCache : IFileCache + internal class WebRemoteBundleCache : IBundleCache { /// /// Web远端文件缓存配置 @@ -51,10 +51,10 @@ namespace YooAsset /// /// URL 选择策略 /// - public IDownloadURLPolicy URLPolicy { get; set; } + public IDownloadUrlPolicy URLPolicy { get; set; } } - private readonly Dictionary _cacheEntries = new Dictionary(10000); + private readonly Dictionary _cacheEntries = new Dictionary(10000); /// /// 缓存配置 @@ -101,7 +101,7 @@ namespace YooAsset /// 包裹名称 /// 缓存根目录 /// 缓存配置 - public WebRemoteFileCache(string packageName, string rootPath, CacheConfig config) + public WebRemoteBundleCache(string packageName, string rootPath, CacheConfig config) { PackageName = packageName; RootPath = rootPath; @@ -111,37 +111,37 @@ namespace YooAsset public void Dispose() { } - public virtual FCInitializeOperation InitializeAsync() + public virtual BCInitializeOperation InitializeAsync() { - var operation = new WRFCInitializeOperation(this); + var operation = new WRBCInitializeOperation(this); return operation; } - public virtual FCWriteCacheOperation WriteCacheAsync(FCWriteCacheOptions options) + public virtual BCWriteCacheOperation WriteCacheAsync(BCWriteCacheOptions options) { - var operation = new FCWriteCacheCompleteOperation($"{nameof(WebRemoteFileCache)} is readonly."); + var operation = new BCWriteCacheCompleteOperation($"{nameof(WebRemoteBundleCache)} is readonly."); return operation; } - public virtual FCClearCacheOperation ClearCacheAsync(FCClearCacheOptions options) + public virtual BCClearCacheOperation ClearCacheAsync(BCClearCacheOptions options) { - var operation = new FCClearCacheCompleteOperation($"{nameof(WebRemoteFileCache)} is readonly."); + var operation = new BCClearCacheCompleteOperation(); return operation; } - public virtual FCVerifyCacheOperation VerifyCacheAsync(FCVerifyCacheOptions options) + public virtual BCVerifyCacheOperation VerifyCacheAsync(BCVerifyCacheOptions options) { - var operation = new FCVerifyCacheCompleteOperation(); + var operation = new BCVerifyCacheCompleteOperation(); return operation; } - public virtual FCLoadBundleOperation LoadBundleAsync(FCLoadBundleOptions options) + public virtual BCLoadBundleOperation LoadBundleAsync(BCLoadBundleOptions options) { if (options.Bundle.BundleType == (int)EBundleType.AssetBundle) { - var operation = new WRFCLoadAssetBundleOperation(this, options); + var operation = new WRBCLoadAssetBundleOperation(this, options); return operation; } else { - string error = $"{nameof(WebRemoteFileCache)} does not support bundle type: {options.Bundle.BundleType}"; - var operation = new FCLoadBundleErrorOperation(error); + string error = $"{nameof(WebRemoteBundleCache)} does not support bundle type: {options.Bundle.BundleType}"; + var operation = new BCLoadBundleErrorOperation(error); return operation; } } @@ -154,16 +154,16 @@ namespace YooAsset /// /// 获取或创建指定资源包的缓存条目 /// - internal WebRemoteFileCacheEntry GetEntry(PackageBundle bundle) + internal WebRemoteBundleCacheEntry GetEntry(PackageBundle bundle) { - if (_cacheEntries.TryGetValue(bundle.BundleGUID, out WebRemoteFileCacheEntry entry)) + if (_cacheEntries.TryGetValue(bundle.BundleGUID, out WebRemoteBundleCacheEntry entry)) { return entry; } else { var urls = Config.RemoteServices.GetRemoteURLs(bundle.FileName); - var newEntry = new WebRemoteFileCacheEntry(bundle.BundleGUID, urls); + var newEntry = new WebRemoteBundleCacheEntry(bundle.BundleGUID, urls); _cacheEntries.Add(bundle.BundleGUID, newEntry); return newEntry; } diff --git a/Assets/YooAsset/Runtime/FileCache/Services/WebRemoteFileCache/WebRemoteFileCache.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Services/WebRemoteBundleCache/WebRemoteBundleCache.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/WebRemoteFileCache/WebRemoteFileCache.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Services/WebRemoteBundleCache/WebRemoteBundleCache.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/WebRemoteFileCache/WebRemoteFileCacheEntry.cs b/Assets/YooAsset/Runtime/BundleCache/Services/WebRemoteBundleCache/WebRemoteBundleCacheEntry.cs similarity index 83% rename from Assets/YooAsset/Runtime/FileCache/Services/WebRemoteFileCache/WebRemoteFileCacheEntry.cs rename to Assets/YooAsset/Runtime/BundleCache/Services/WebRemoteBundleCache/WebRemoteBundleCacheEntry.cs index bb4ccbd5..d9e80013 100644 --- a/Assets/YooAsset/Runtime/FileCache/Services/WebRemoteFileCache/WebRemoteFileCacheEntry.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Services/WebRemoteBundleCache/WebRemoteBundleCacheEntry.cs @@ -5,7 +5,7 @@ namespace YooAsset /// /// Web远端文件缓存条目 /// - internal class WebRemoteFileCacheEntry : ICacheEntry + internal class WebRemoteBundleCacheEntry : ICacheEntry { /// /// 资源包唯一标识 @@ -22,7 +22,7 @@ namespace YooAsset /// /// 资源包唯一标识 /// 候选下载地址列表 - public WebRemoteFileCacheEntry(string bundleGUID, IReadOnlyList urls) + public WebRemoteBundleCacheEntry(string bundleGUID, IReadOnlyList urls) { BundleGUID = bundleGUID; URLs = urls; diff --git a/Assets/YooAsset/Runtime/FileCache/Services/WebRemoteFileCache/WebRemoteFileCacheEntry.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Services/WebRemoteBundleCache/WebRemoteBundleCacheEntry.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/WebRemoteFileCache/WebRemoteFileCacheEntry.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Services/WebRemoteBundleCache/WebRemoteBundleCacheEntry.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache.meta b/Assets/YooAsset/Runtime/BundleCache/Services/WebServerBundleCache.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache.meta rename to Assets/YooAsset/Runtime/BundleCache/Services/WebServerBundleCache.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/Operations.meta b/Assets/YooAsset/Runtime/BundleCache/Services/WebServerBundleCache/Operations.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/Operations.meta rename to Assets/YooAsset/Runtime/BundleCache/Services/WebServerBundleCache/Operations.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/Operations/WSFCInitializeOperation.cs b/Assets/YooAsset/Runtime/BundleCache/Services/WebServerBundleCache/Operations/WSBCInitializeOperation.cs similarity index 89% rename from Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/Operations/WSFCInitializeOperation.cs rename to Assets/YooAsset/Runtime/BundleCache/Services/WebServerBundleCache/Operations/WSBCInitializeOperation.cs index 5593bee9..253efdfb 100644 --- a/Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/Operations/WSFCInitializeOperation.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Services/WebServerBundleCache/Operations/WSBCInitializeOperation.cs @@ -4,7 +4,7 @@ namespace YooAsset /// /// Web服务器文件缓存初始化操作 /// - internal class WSFCInitializeOperation : FCInitializeOperation + internal class WSBCInitializeOperation : BCInitializeOperation { private enum ESteps { @@ -14,11 +14,11 @@ namespace YooAsset Done, } - private readonly WebServerFileCache _fileCache; + private readonly WebServerBundleCache _fileCache; private LoadBuiltinCatalogOperation _loadBuiltinCatalogOp; private ESteps _steps = ESteps.None; - public WSFCInitializeOperation(WebServerFileCache cache) + public WSBCInitializeOperation(WebServerBundleCache cache) { _fileCache = cache; } @@ -66,7 +66,7 @@ namespace YooAsset foreach (var fileEntry in catalog.FileEntries) { string filePath = PathUtility.Combine(_fileCache.RootPath, fileEntry.FileName); - var cacheEntry = new WebServerFileCacheEntry(fileEntry.BundleGUID, filePath); + var cacheEntry = new WebServerBundleCacheEntry(fileEntry.BundleGUID, filePath); _fileCache.AddEntry(fileEntry.BundleGUID, cacheEntry); } diff --git a/Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/Operations/WSFCInitializeOperation.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Services/WebServerBundleCache/Operations/WSBCInitializeOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/Operations/WSFCInitializeOperation.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Services/WebServerBundleCache/Operations/WSBCInitializeOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/Operations/WSFCLoadBundleOperation.cs b/Assets/YooAsset/Runtime/BundleCache/Services/WebServerBundleCache/Operations/WSBCLoadBundleOperation.cs similarity index 87% rename from Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/Operations/WSFCLoadBundleOperation.cs rename to Assets/YooAsset/Runtime/BundleCache/Services/WebServerBundleCache/Operations/WSBCLoadBundleOperation.cs index ddd5b265..b5f28d9f 100644 --- a/Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/Operations/WSFCLoadBundleOperation.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Services/WebServerBundleCache/Operations/WSBCLoadBundleOperation.cs @@ -4,7 +4,7 @@ namespace YooAsset /// /// Web服务器文件缓存加载 AssetBundle 操作 /// - internal class WSFCLoadAssetBundleOperation : FCLoadBundleOperation + internal class WSBCLoadAssetBundleOperation : BCLoadBundleOperation { private enum ESteps { @@ -14,13 +14,13 @@ namespace YooAsset Done, } - private readonly WebServerFileCache _fileCache; - private readonly FCLoadBundleOptions _options; + private readonly WebServerBundleCache _fileCache; + private readonly BCLoadBundleOptions _options; private LoadWebAssetBundleOperation _loadWebAssetBundleOp; - private WebServerFileCacheEntry _cacheEntry; + private WebServerBundleCacheEntry _cacheEntry; private ESteps _steps = ESteps.None; - public WSFCLoadAssetBundleOperation(WebServerFileCache fileCache, FCLoadBundleOptions options) + public WSBCLoadAssetBundleOperation(WebServerBundleCache fileCache, BCLoadBundleOptions options) { _fileCache = fileCache; _options = options; @@ -53,7 +53,7 @@ namespace YooAsset { if (_loadWebAssetBundleOp == null) { - string url = DownloadSystemTools.ToLocalUrl(_cacheEntry.FilePath); + string url = DownloadSystemTools.ToLocalFileUrl(_cacheEntry.FilePath); var options = new LoadWebAssetBundleOptions(); options.CacheName = _fileCache.GetType().Name; options.Bundle = _options.Bundle; @@ -102,7 +102,7 @@ namespace YooAsset { _steps = ESteps.Done; Status = EOperationStatus.Failed; - Error = $"{nameof(WebServerFileCache)} does not support synchronous asset bundle loading."; + Error = $"{nameof(WebServerBundleCache)} does not support synchronous asset bundle loading."; YooLogger.Error(Error); } } diff --git a/Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/Operations/WSFCLoadBundleOperation.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Services/WebServerBundleCache/Operations/WSBCLoadBundleOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/Operations/WSFCLoadBundleOperation.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Services/WebServerBundleCache/Operations/WSBCLoadBundleOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/WebServerFileCache.cs b/Assets/YooAsset/Runtime/BundleCache/Services/WebServerBundleCache/WebServerBundleCache.cs similarity index 74% rename from Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/WebServerFileCache.cs rename to Assets/YooAsset/Runtime/BundleCache/Services/WebServerBundleCache/WebServerBundleCache.cs index 52134162..cfab2945 100644 --- a/Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/WebServerFileCache.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Services/WebServerBundleCache/WebServerBundleCache.cs @@ -6,7 +6,7 @@ namespace YooAsset /// /// Web服务器文件缓存系统,用于WebGL平台从服务器加载资源 /// - internal class WebServerFileCache : IFileCache + internal class WebServerBundleCache : IBundleCache { /// /// Web服务器文件缓存配置 @@ -46,10 +46,10 @@ namespace YooAsset /// /// URL 选择策略 /// - public IDownloadURLPolicy URLPolicy { get; set; } + public IDownloadUrlPolicy URLPolicy { get; set; } } - private readonly Dictionary _cacheEntries = new Dictionary(10000); + private readonly Dictionary _cacheEntries = new Dictionary(10000); /// /// 缓存配置 @@ -96,7 +96,7 @@ namespace YooAsset /// 包裹名称 /// 缓存根目录 /// 缓存配置 - public WebServerFileCache(string packageName, string rootPath, CacheConfig config) + public WebServerBundleCache(string packageName, string rootPath, CacheConfig config) { PackageName = packageName; RootPath = rootPath; @@ -106,37 +106,37 @@ namespace YooAsset public void Dispose() { } - public virtual FCInitializeOperation InitializeAsync() + public virtual BCInitializeOperation InitializeAsync() { - var operation = new WSFCInitializeOperation(this); + var operation = new WSBCInitializeOperation(this); return operation; } - public virtual FCWriteCacheOperation WriteCacheAsync(FCWriteCacheOptions options) + public virtual BCWriteCacheOperation WriteCacheAsync(BCWriteCacheOptions options) { - var operation = new FCWriteCacheCompleteOperation($"{nameof(WebServerFileCache)} is readonly."); + var operation = new BCWriteCacheCompleteOperation($"{nameof(WebServerBundleCache)} is readonly."); return operation; } - public virtual FCClearCacheOperation ClearCacheAsync(FCClearCacheOptions options) + public virtual BCClearCacheOperation ClearCacheAsync(BCClearCacheOptions options) { - var operation = new FCClearCacheCompleteOperation($"{nameof(WebServerFileCache)} is readonly."); + var operation = new BCClearCacheCompleteOperation(); return operation; } - public virtual FCVerifyCacheOperation VerifyCacheAsync(FCVerifyCacheOptions options) + public virtual BCVerifyCacheOperation VerifyCacheAsync(BCVerifyCacheOptions options) { - var operation = new FCVerifyCacheCompleteOperation(); + var operation = new BCVerifyCacheCompleteOperation(); return operation; } - public virtual FCLoadBundleOperation LoadBundleAsync(FCLoadBundleOptions options) + public virtual BCLoadBundleOperation LoadBundleAsync(BCLoadBundleOptions options) { if (options.Bundle.BundleType == (int)EBundleType.AssetBundle) { - var operation = new WSFCLoadAssetBundleOperation(this, options); + var operation = new WSBCLoadAssetBundleOperation(this, options); return operation; } else { - string error = $"{nameof(WebServerFileCache)} does not support bundle type: {options.Bundle.BundleType}"; - var operation = new FCLoadBundleErrorOperation(error); + string error = $"{nameof(WebServerBundleCache)} does not support bundle type: {options.Bundle.BundleType}"; + var operation = new BCLoadBundleErrorOperation(error); return operation; } } @@ -149,9 +149,9 @@ namespace YooAsset /// /// 获取指定缓存条目 /// - internal WebServerFileCacheEntry GetEntry(string bundleGUID) + internal WebServerBundleCacheEntry GetEntry(string bundleGUID) { - if (_cacheEntries.TryGetValue(bundleGUID, out WebServerFileCacheEntry entry)) + if (_cacheEntries.TryGetValue(bundleGUID, out WebServerBundleCacheEntry entry)) return entry; else return null; @@ -160,7 +160,7 @@ namespace YooAsset /// /// 添加指定缓存条目 /// - internal void AddEntry(string bundleGUID, WebServerFileCacheEntry cacheEntry) + internal void AddEntry(string bundleGUID, WebServerBundleCacheEntry cacheEntry) { if (_cacheEntries.ContainsKey(bundleGUID)) throw new YooInternalException($"Cache entry already exists: {bundleGUID}"); diff --git a/Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/WebServerFileCache.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Services/WebServerBundleCache/WebServerBundleCache.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/WebServerFileCache.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Services/WebServerBundleCache/WebServerBundleCache.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/WebServerFileCacheEntry.cs b/Assets/YooAsset/Runtime/BundleCache/Services/WebServerBundleCache/WebServerBundleCacheEntry.cs similarity index 83% rename from Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/WebServerFileCacheEntry.cs rename to Assets/YooAsset/Runtime/BundleCache/Services/WebServerBundleCache/WebServerBundleCacheEntry.cs index f14600cf..571c1d55 100644 --- a/Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/WebServerFileCacheEntry.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Services/WebServerBundleCache/WebServerBundleCacheEntry.cs @@ -4,7 +4,7 @@ namespace YooAsset /// /// Web服务器文件缓存条目 /// - internal class WebServerFileCacheEntry : ICacheEntry + internal class WebServerBundleCacheEntry : ICacheEntry { /// /// 资源包唯一标识 @@ -21,7 +21,7 @@ namespace YooAsset /// /// 资源包唯一标识 /// 资源包文件路径 - public WebServerFileCacheEntry(string bundleGUID, string filePath) + public WebServerBundleCacheEntry(string bundleGUID, string filePath) { BundleGUID = bundleGUID; FilePath = filePath; diff --git a/Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/WebServerFileCacheEntry.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Services/WebServerBundleCache/WebServerBundleCacheEntry.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/WebServerFileCacheEntry.cs.meta rename to Assets/YooAsset/Runtime/BundleCache/Services/WebServerBundleCache/WebServerBundleCacheEntry.cs.meta diff --git a/Assets/YooAsset/Runtime/BundleHandle/EBundleType.cs b/Assets/YooAsset/Runtime/BundleHandle/EBundleType.cs index b254bbfd..eec5483b 100644 --- a/Assets/YooAsset/Runtime/BundleHandle/EBundleType.cs +++ b/Assets/YooAsset/Runtime/BundleHandle/EBundleType.cs @@ -17,17 +17,17 @@ namespace YooAsset VirtualBundle = 1, /// - /// AssetBundle + /// Unity引擎资源包 /// AssetBundle = 2, /// - /// 原生文件 + /// 原生文件资源包 /// RawBundle = 3, /// - /// 团结资源包 + /// 团结引擎资源包 /// InstantBundle = 4, } diff --git a/Assets/YooAsset/Runtime/BundleHandle/Interfaces/IBundleHandle.cs b/Assets/YooAsset/Runtime/BundleHandle/Interfaces/IBundleHandle.cs index a274a6f2..2316b954 100644 --- a/Assets/YooAsset/Runtime/BundleHandle/Interfaces/IBundleHandle.cs +++ b/Assets/YooAsset/Runtime/BundleHandle/Interfaces/IBundleHandle.cs @@ -8,33 +8,43 @@ namespace YooAsset internal interface IBundleHandle { /// - /// 获取资源包文件的本地路径 + /// 资源包文件的本地路径 /// - string GetBundleFilePath(); + string BundleFilePath { get; } /// - /// 卸载资源包文件 + /// 卸载资源包 /// - void UnloadBundleFile(); + void UnloadBundle(); /// - /// 加载资源对象 + /// 异步加载指定的主资源对象 /// + /// 待加载资源的描述信息 + /// 用于跟踪加载过程的异步操作对象 BHLoadAssetOperation LoadAssetAsync(AssetInfo assetInfo); /// - /// 加载所有资源对象 + /// 异步加载资源包内的全部资源对象 /// + /// 待加载资源的描述信息 + /// 用于跟踪加载过程的异步操作对象 BHLoadAllAssetsOperation LoadAllAssetsAsync(AssetInfo assetInfo); /// - /// 加载资源对象及所有子资源对象 + /// 异步加载指定资源对应的全部子资源对象 /// + /// 待加载资源的描述信息 + /// 用于跟踪加载过程的异步操作对象 BHLoadSubAssetsOperation LoadSubAssetsAsync(AssetInfo assetInfo); /// - /// 加载场景对象 + /// 异步加载指定的场景资源 /// - BHLoadSceneOperation LoadSceneAsync(AssetInfo assetInfo, LoadSceneParameters loadSceneParams, bool suspendLoad); + /// 待加载场景的资源信息 + /// 场景加载参数 + /// 是否允许场景在加载完成后立即激活 + /// 用于跟踪场景加载过程的异步操作对象 + BHLoadSceneOperation LoadSceneAsync(AssetInfo assetInfo, LoadSceneParameters loadSceneParams, bool allowSceneActivation); } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/BundleHandle/Operations/BHLoadAllAssetsOperation.cs b/Assets/YooAsset/Runtime/BundleHandle/Operations/BHLoadAllAssetsOperation.cs index 8b127be4..95358348 100644 --- a/Assets/YooAsset/Runtime/BundleHandle/Operations/BHLoadAllAssetsOperation.cs +++ b/Assets/YooAsset/Runtime/BundleHandle/Operations/BHLoadAllAssetsOperation.cs @@ -7,8 +7,8 @@ namespace YooAsset internal abstract class BHLoadAllAssetsOperation : AsyncOperationBase { /// - /// 加载的所有资源对象 + /// 当前加载操作产出的全部资源对象集合 /// - public UnityEngine.Object[] Result; + public UnityEngine.Object[] Result { get; protected set; } } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/BundleHandle/Operations/BHLoadAssetOperation.cs b/Assets/YooAsset/Runtime/BundleHandle/Operations/BHLoadAssetOperation.cs index 81d52bc7..1e62554d 100644 --- a/Assets/YooAsset/Runtime/BundleHandle/Operations/BHLoadAssetOperation.cs +++ b/Assets/YooAsset/Runtime/BundleHandle/Operations/BHLoadAssetOperation.cs @@ -7,8 +7,8 @@ namespace YooAsset internal abstract class BHLoadAssetOperation : AsyncOperationBase { /// - /// 加载的资源对象 + /// 当前加载操作产出的资源对象 /// - public UnityEngine.Object Result; + public UnityEngine.Object Result { get; protected set; } } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/BundleHandle/Operations/BHLoadSceneOperation.cs b/Assets/YooAsset/Runtime/BundleHandle/Operations/BHLoadSceneOperation.cs index 166acd13..c339b701 100644 --- a/Assets/YooAsset/Runtime/BundleHandle/Operations/BHLoadSceneOperation.cs +++ b/Assets/YooAsset/Runtime/BundleHandle/Operations/BHLoadSceneOperation.cs @@ -7,13 +7,13 @@ namespace YooAsset internal abstract class BHLoadSceneOperation : AsyncOperationBase { /// - /// 加载的场景对象 + /// 当前加载操作产出的场景对象 /// - public UnityEngine.SceneManagement.Scene Result; + public UnityEngine.SceneManagement.Scene Result { get; protected set; } /// - /// 恢复挂起的场景加载 + /// 允许场景在加载完成后进入激活阶段 /// - public abstract void ResumeLoad(); + public abstract void AllowSceneActivation(); } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/BundleHandle/Operations/BHLoadSubAssetsOperation.cs b/Assets/YooAsset/Runtime/BundleHandle/Operations/BHLoadSubAssetsOperation.cs index 23ae464d..a27ae870 100644 --- a/Assets/YooAsset/Runtime/BundleHandle/Operations/BHLoadSubAssetsOperation.cs +++ b/Assets/YooAsset/Runtime/BundleHandle/Operations/BHLoadSubAssetsOperation.cs @@ -7,8 +7,8 @@ namespace YooAsset internal abstract class BHLoadSubAssetsOperation : AsyncOperationBase { /// - /// 加载的子资源对象集合 + /// 当前加载操作产出的子资源对象集合 /// - public UnityEngine.Object[] Result; + public UnityEngine.Object[] Result { get; protected set; } } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/BundleHandle/Services/AssetBundleHandle/AssetBundleHandle.cs b/Assets/YooAsset/Runtime/BundleHandle/Services/AssetBundleHandle/AssetBundleHandle.cs index 866d6df4..d1d5b08c 100644 --- a/Assets/YooAsset/Runtime/BundleHandle/Services/AssetBundleHandle/AssetBundleHandle.cs +++ b/Assets/YooAsset/Runtime/BundleHandle/Services/AssetBundleHandle/AssetBundleHandle.cs @@ -12,51 +12,66 @@ namespace YooAsset private readonly string _bundleFilePath; private readonly PackageBundle _packageBundle; private readonly AssetBundle _assetBundle; - private readonly Stream _managedStream; + private readonly Stream _bundleStream; - public AssetBundleHandle(string bundleFilePath, PackageBundle packageBundle, AssetBundle assetBundle, Stream managedStream) + /// + /// 当前资源包对应的本地文件路径 + /// + public string BundleFilePath + { + get { return _bundleFilePath; } + } + + public AssetBundleHandle(string bundleFilePath, PackageBundle packageBundle, AssetBundle assetBundle, Stream bundleStream) { _bundleFilePath = bundleFilePath; _packageBundle = packageBundle; _assetBundle = assetBundle; - _managedStream = managedStream; + _bundleStream = bundleStream; } - public string GetBundleFilePath() - { - return _bundleFilePath; - } - public void UnloadBundleFile() + + /// + /// 卸载AssetBundle并释放关联的文件流 + /// + public void UnloadBundle() { if (_assetBundle != null) { _assetBundle.Unload(true); } - if (_managedStream != null) + if (_bundleStream != null) { - _managedStream.Close(); - _managedStream.Dispose(); + _bundleStream.Close(); + _bundleStream.Dispose(); } } + /// public BHLoadAssetOperation LoadAssetAsync(AssetInfo assetInfo) { var operation = new ABHLoadAssetOperation(_packageBundle, _assetBundle, assetInfo); return operation; } + + /// public BHLoadAllAssetsOperation LoadAllAssetsAsync(AssetInfo assetInfo) { var operation = new ABHLoadAllAssetsOperation(_packageBundle, _assetBundle, assetInfo); return operation; } + + /// public BHLoadSubAssetsOperation LoadSubAssetsAsync(AssetInfo assetInfo) { var operation = new ABHLoadSubAssetsOperation(_packageBundle, _assetBundle, assetInfo); return operation; } - public BHLoadSceneOperation LoadSceneAsync(AssetInfo assetInfo, LoadSceneParameters loadSceneParams, bool suspendLoad) + + /// + public BHLoadSceneOperation LoadSceneAsync(AssetInfo assetInfo, LoadSceneParameters loadSceneParams, bool allowSceneActivation) { - var operation = new ABHLoadSceneOperation(assetInfo, loadSceneParams, suspendLoad); + var operation = new ABHLoadSceneOperation(assetInfo, loadSceneParams, allowSceneActivation); return operation; } } diff --git a/Assets/YooAsset/Runtime/BundleHandle/Services/AssetBundleHandle/Operations/ABHLoadAllAssetsOperation.cs b/Assets/YooAsset/Runtime/BundleHandle/Services/AssetBundleHandle/Operations/ABHLoadAllAssetsOperation.cs index 7ac974d9..3eb19a24 100644 --- a/Assets/YooAsset/Runtime/BundleHandle/Services/AssetBundleHandle/Operations/ABHLoadAllAssetsOperation.cs +++ b/Assets/YooAsset/Runtime/BundleHandle/Services/AssetBundleHandle/Operations/ABHLoadAllAssetsOperation.cs @@ -78,7 +78,7 @@ namespace YooAsset if (IsWaitForCompletion) { // 强制挂起主线程(注意:该操作会很耗时) - YooLogger.Warning("Suspending the main thread to load Unity asset."); + YooLogger.Warning("Blocking the main thread while loading Unity assets."); Result = _request.allAssets; } else diff --git a/Assets/YooAsset/Runtime/BundleHandle/Services/AssetBundleHandle/Operations/ABHLoadAssetOperation.cs b/Assets/YooAsset/Runtime/BundleHandle/Services/AssetBundleHandle/Operations/ABHLoadAssetOperation.cs index b0d6d467..6d8ff028 100644 --- a/Assets/YooAsset/Runtime/BundleHandle/Services/AssetBundleHandle/Operations/ABHLoadAssetOperation.cs +++ b/Assets/YooAsset/Runtime/BundleHandle/Services/AssetBundleHandle/Operations/ABHLoadAssetOperation.cs @@ -78,7 +78,7 @@ namespace YooAsset if (IsWaitForCompletion) { // 强制挂起主线程(注意:该操作会很耗时) - YooLogger.Warning("Suspending the main thread to load Unity asset."); + YooLogger.Warning("Blocking the main thread while loading a Unity asset."); Result = _request.asset; } else diff --git a/Assets/YooAsset/Runtime/BundleHandle/Services/AssetBundleHandle/Operations/ABHLoadSceneOperation.cs b/Assets/YooAsset/Runtime/BundleHandle/Services/AssetBundleHandle/Operations/ABHLoadSceneOperation.cs index 603077b5..6393c34f 100644 --- a/Assets/YooAsset/Runtime/BundleHandle/Services/AssetBundleHandle/Operations/ABHLoadSceneOperation.cs +++ b/Assets/YooAsset/Runtime/BundleHandle/Services/AssetBundleHandle/Operations/ABHLoadSceneOperation.cs @@ -18,15 +18,15 @@ namespace YooAsset private readonly AssetInfo _assetInfo; private readonly LoadSceneParameters _loadSceneParams; - private bool _suspendLoad; + private bool _allowSceneActivation; private AsyncOperation _asyncOperation; private ESteps _steps = ESteps.None; - public ABHLoadSceneOperation(AssetInfo assetInfo, LoadSceneParameters loadSceneParams, bool suspendLoad) + public ABHLoadSceneOperation(AssetInfo assetInfo, LoadSceneParameters loadSceneParams, bool allowSceneActivation) { _assetInfo = assetInfo; _loadSceneParams = loadSceneParams; - _suspendLoad = suspendLoad; + _allowSceneActivation = allowSceneActivation; } internal override void InternalStart() { @@ -52,7 +52,7 @@ namespace YooAsset _asyncOperation = SceneManager.LoadSceneAsync(_assetInfo.AssetPath, _loadSceneParams); if (_asyncOperation != null) { - _asyncOperation.allowSceneActivation = !_suspendLoad; + _asyncOperation.allowSceneActivation = _allowSceneActivation; _asyncOperation.priority = 100; Result = SceneManager.GetSceneAt(SceneManager.sceneCount - 1); _steps = ESteps.CheckResult; @@ -81,7 +81,7 @@ namespace YooAsset // 注意:在业务层中途可以取消挂起 if (_asyncOperation.allowSceneActivation == false) { - if (_suspendLoad == false) + if (_allowSceneActivation) _asyncOperation.allowSceneActivation = true; } @@ -110,9 +110,9 @@ namespace YooAsset //注意:场景加载不支持异步转同步,为了支持同步加载方法需要实现该方法! ExecuteOnce(); } - public override void ResumeLoad() + public override void AllowSceneActivation() { - _suspendLoad = false; + _allowSceneActivation = true; } } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/BundleHandle/Services/AssetBundleHandle/Operations/ABHLoadSubAssetsOperation.cs b/Assets/YooAsset/Runtime/BundleHandle/Services/AssetBundleHandle/Operations/ABHLoadSubAssetsOperation.cs index 8d814c30..b01ccee4 100644 --- a/Assets/YooAsset/Runtime/BundleHandle/Services/AssetBundleHandle/Operations/ABHLoadSubAssetsOperation.cs +++ b/Assets/YooAsset/Runtime/BundleHandle/Services/AssetBundleHandle/Operations/ABHLoadSubAssetsOperation.cs @@ -78,7 +78,7 @@ namespace YooAsset if (IsWaitForCompletion) { // 强制挂起主线程(注意:该操作会很耗时) - YooLogger.Warning("Suspending the main thread to load Unity asset."); + YooLogger.Warning("Blocking the main thread while loading Unity assets."); Result = _request.allAssets; } else diff --git a/Assets/YooAsset/Runtime/BundleHandle/Services/RawBundleHandle/Operations/RBHLoadAssetOperation.cs b/Assets/YooAsset/Runtime/BundleHandle/Services/RawBundleHandle/Operations/RBHLoadAssetOperation.cs index 4540335c..583a6fc6 100644 --- a/Assets/YooAsset/Runtime/BundleHandle/Services/RawBundleHandle/Operations/RBHLoadAssetOperation.cs +++ b/Assets/YooAsset/Runtime/BundleHandle/Services/RawBundleHandle/Operations/RBHLoadAssetOperation.cs @@ -36,7 +36,7 @@ namespace YooAsset if (_steps == ESteps.LoadObject) { - Result = _rawBundle.LoadRawFileObject(); + Result = _rawBundle.CreateRawFileObject(); _steps = ESteps.CheckResult; } diff --git a/Assets/YooAsset/Runtime/BundleHandle/Services/RawBundleHandle/Operations/RBHLoadSceneOperation.cs b/Assets/YooAsset/Runtime/BundleHandle/Services/RawBundleHandle/Operations/RBHLoadSceneOperation.cs index c9f15904..65766ee1 100644 --- a/Assets/YooAsset/Runtime/BundleHandle/Services/RawBundleHandle/Operations/RBHLoadSceneOperation.cs +++ b/Assets/YooAsset/Runtime/BundleHandle/Services/RawBundleHandle/Operations/RBHLoadSceneOperation.cs @@ -9,12 +9,12 @@ namespace YooAsset internal override void InternalStart() { Status = EOperationStatus.Failed; - Error = $"{nameof(RBHLoadSceneOperation)} does not support loading scene."; + Error = $"{nameof(RBHLoadSceneOperation)} does not support scene loading."; } internal override void InternalUpdate() { } - public override void ResumeLoad() + public override void AllowSceneActivation() { } } diff --git a/Assets/YooAsset/Runtime/BundleHandle/Services/RawBundleHandle/RawBundle.cs b/Assets/YooAsset/Runtime/BundleHandle/Services/RawBundleHandle/RawBundle.cs index 338f39da..cba32dd9 100644 --- a/Assets/YooAsset/Runtime/BundleHandle/Services/RawBundleHandle/RawBundle.cs +++ b/Assets/YooAsset/Runtime/BundleHandle/Services/RawBundleHandle/RawBundle.cs @@ -2,31 +2,32 @@ namespace YooAsset { /// - /// 原生资源包 + /// 封装原生文件字节数据的资源包对象 /// public class RawBundle { - private byte[] _data; + private byte[] _bytes; - public RawBundle(byte[] data) + public RawBundle(byte[] bytes) { - _data = data; + _bytes = bytes; } /// - /// 加载原生文件对象 + /// 根据当前字节数据创建可访问的原生文件对象 /// - public RawFileObject LoadRawFileObject() + /// 创建得到的原生文件对象 + public RawFileObject CreateRawFileObject() { - return RawFileObject.Create(_data); + return RawFileObject.CreateFromBytes(_bytes); } /// - /// 卸载原生资源包数据 + /// 卸载原生资源包并释放字节数据 /// public void Unload() { - _data = null; + _bytes = null; } } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/BundleHandle/Services/RawBundleHandle/RawBundleHandle.cs b/Assets/YooAsset/Runtime/BundleHandle/Services/RawBundleHandle/RawBundleHandle.cs index 19de445d..2aac4156 100644 --- a/Assets/YooAsset/Runtime/BundleHandle/Services/RawBundleHandle/RawBundleHandle.cs +++ b/Assets/YooAsset/Runtime/BundleHandle/Services/RawBundleHandle/RawBundleHandle.cs @@ -11,17 +11,25 @@ namespace YooAsset private readonly PackageBundle _packageBundle; private readonly RawBundle _rawBundle; + /// + /// 当前资源包对应的本地文件路径 + /// + public string BundleFilePath + { + get { return _bundleFilePath; } + } + public RawBundleHandle(string bundleFilePath, PackageBundle packageBundle, RawBundle rawBundle) { _bundleFilePath = bundleFilePath; _packageBundle = packageBundle; _rawBundle = rawBundle; } - public string GetBundleFilePath() - { - return _bundleFilePath; - } - public void UnloadBundleFile() + + /// + /// 卸载原生资源包并释放字节数据 + /// + public void UnloadBundle() { if (_rawBundle != null) { @@ -29,22 +37,29 @@ namespace YooAsset } } + /// public BHLoadAssetOperation LoadAssetAsync(AssetInfo assetInfo) { var operation = new RBHLoadAssetOperation(_packageBundle, _rawBundle, assetInfo); return operation; } + + /// public BHLoadAllAssetsOperation LoadAllAssetsAsync(AssetInfo assetInfo) { var operation = new RBHLoadAllAssetsOperation(); return operation; } + + /// public BHLoadSubAssetsOperation LoadSubAssetsAsync(AssetInfo assetInfo) { var operation = new RBHLoadSubAssetsOperation(); return operation; } - public BHLoadSceneOperation LoadSceneAsync(AssetInfo assetInfo, LoadSceneParameters loadSceneParams, bool suspendLoad) + + /// + public BHLoadSceneOperation LoadSceneAsync(AssetInfo assetInfo, LoadSceneParameters loadSceneParams, bool allowSceneActivation) { var operation = new RBHLoadSceneOperation(); return operation; diff --git a/Assets/YooAsset/Runtime/BundleHandle/Services/RawBundleHandle/RawFileObject.cs b/Assets/YooAsset/Runtime/BundleHandle/Services/RawBundleHandle/RawFileObject.cs index 3fc8637f..bfd16c77 100644 --- a/Assets/YooAsset/Runtime/BundleHandle/Services/RawBundleHandle/RawFileObject.cs +++ b/Assets/YooAsset/Runtime/BundleHandle/Services/RawBundleHandle/RawFileObject.cs @@ -4,41 +4,43 @@ using UnityEngine; namespace YooAsset { /// - /// 原生文件对象 + /// 用于访问原生文件字节数据及文本内容的对象 /// public class RawFileObject : ScriptableObject { - private byte[] _fileData; + private byte[] _fileBytes; private string _fileText; /// - /// 原生文件的二进制数据 + /// 原生文件的字节数据 /// - public byte[] Data => _fileData; + public byte[] Bytes => _fileBytes; /// - /// 原生文件的UTF-8文本内容 + /// 以UTF-8编码解析得到的文本内容 /// public string Text { get { - if (_fileData == null || _fileData.Length == 0) + if (_fileBytes == null || _fileBytes.Length == 0) return null; if (string.IsNullOrEmpty(_fileText)) - _fileText = Encoding.UTF8.GetString(_fileData); + _fileText = Encoding.UTF8.GetString(_fileBytes); return _fileText; } } /// - /// 创建原生文件对象实例 + /// 根据字节数据创建原生文件对象实例 /// - public static RawFileObject Create(byte[] data) + /// 原生文件的字节数据 + /// 创建得到的原生文件对象 + public static RawFileObject CreateFromBytes(byte[] bytes) { var obj = CreateInstance(); - obj._fileData = data; + obj._fileBytes = bytes; return obj; } } diff --git a/Assets/YooAsset/Runtime/BundleHandle/Services/VirtualBundleHandle/Operations/VBHLoadAllAssetsOperation.cs b/Assets/YooAsset/Runtime/BundleHandle/Services/VirtualBundleHandle/Operations/VBHLoadAllAssetsOperation.cs index 7174a47c..03ad85bd 100644 --- a/Assets/YooAsset/Runtime/BundleHandle/Services/VirtualBundleHandle/Operations/VBHLoadAllAssetsOperation.cs +++ b/Assets/YooAsset/Runtime/BundleHandle/Services/VirtualBundleHandle/Operations/VBHLoadAllAssetsOperation.cs @@ -32,7 +32,7 @@ namespace YooAsset #else _steps = ESteps.Done; Status = EOperationStatus.Failed; - Error = $"{nameof(VirtualBundleLoadAllAssetsOperation)} only support unity editor platform."; + Error = $"{nameof(VBHLoadAllAssetsOperation)} is only supported in the Unity Editor."; #endif } internal override void InternalUpdate() diff --git a/Assets/YooAsset/Runtime/BundleHandle/Services/VirtualBundleHandle/Operations/VBHLoadAssetOperation.cs b/Assets/YooAsset/Runtime/BundleHandle/Services/VirtualBundleHandle/Operations/VBHLoadAssetOperation.cs index 00d181dc..058e955a 100644 --- a/Assets/YooAsset/Runtime/BundleHandle/Services/VirtualBundleHandle/Operations/VBHLoadAssetOperation.cs +++ b/Assets/YooAsset/Runtime/BundleHandle/Services/VirtualBundleHandle/Operations/VBHLoadAssetOperation.cs @@ -31,7 +31,7 @@ namespace YooAsset #else _steps = ESteps.Done; Status = EOperationStatus.Failed; - Error = $"{nameof(VirtualBundleLoadAssetOperation)} only support unity editor platform."; + Error = $"{nameof(VBHLoadAssetOperation)} is only supported in the Unity Editor."; #endif } internal override void InternalUpdate() diff --git a/Assets/YooAsset/Runtime/BundleHandle/Services/VirtualBundleHandle/Operations/VBHLoadSceneOperation.cs b/Assets/YooAsset/Runtime/BundleHandle/Services/VirtualBundleHandle/Operations/VBHLoadSceneOperation.cs index 66e0bd54..48dc1fff 100644 --- a/Assets/YooAsset/Runtime/BundleHandle/Services/VirtualBundleHandle/Operations/VBHLoadSceneOperation.cs +++ b/Assets/YooAsset/Runtime/BundleHandle/Services/VirtualBundleHandle/Operations/VBHLoadSceneOperation.cs @@ -18,15 +18,15 @@ namespace YooAsset private readonly AssetInfo _assetInfo; private readonly LoadSceneParameters _loadParams; - private bool _suspendLoad; + private bool _allowSceneActivation; private AsyncOperation _asyncOperation; private ESteps _steps = ESteps.None; - public VBHLoadSceneOperation(AssetInfo assetInfo, LoadSceneParameters loadParams, bool suspendLoad) + public VBHLoadSceneOperation(AssetInfo assetInfo, LoadSceneParameters loadParams, bool allowSceneActivation) { _assetInfo = assetInfo; _loadParams = loadParams; - _suspendLoad = suspendLoad; + _allowSceneActivation = allowSceneActivation; } internal override void InternalStart() { @@ -35,7 +35,7 @@ namespace YooAsset #else _steps = ESteps.Done; Status = EOperationStatus.Failed; - Error = $"{nameof(VirtualBundleLoadSceneOperation)} only support unity editor platform."; + Error = $"{nameof(VBHLoadSceneOperation)} is only supported in the Unity Editor."; #endif } internal override void InternalUpdate() @@ -56,7 +56,7 @@ namespace YooAsset _asyncOperation = UnityEditor.SceneManagement.EditorSceneManager.LoadSceneAsyncInPlayMode(_assetInfo.AssetPath, _loadParams); if (_asyncOperation != null) { - _asyncOperation.allowSceneActivation = !_suspendLoad; + _asyncOperation.allowSceneActivation = _allowSceneActivation; _asyncOperation.priority = 100; Result = SceneManager.GetSceneAt(SceneManager.sceneCount - 1); _steps = ESteps.CheckResult; @@ -86,7 +86,7 @@ namespace YooAsset // 注意:在业务层中途可以取消挂起 if (_asyncOperation.allowSceneActivation == false) { - if (_suspendLoad == false) + if (_allowSceneActivation) _asyncOperation.allowSceneActivation = true; } @@ -116,9 +116,9 @@ namespace YooAsset //注意:场景加载不支持异步转同步,为了支持同步加载方法需要实现该方法! ExecuteOnce(); } - public override void ResumeLoad() + public override void AllowSceneActivation() { - _suspendLoad = false; + _allowSceneActivation = true; } } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/BundleHandle/Services/VirtualBundleHandle/Operations/VBHLoadSubAssetsOperation.cs b/Assets/YooAsset/Runtime/BundleHandle/Services/VirtualBundleHandle/Operations/VBHLoadSubAssetsOperation.cs index 80fe3f92..2a09c41f 100644 --- a/Assets/YooAsset/Runtime/BundleHandle/Services/VirtualBundleHandle/Operations/VBHLoadSubAssetsOperation.cs +++ b/Assets/YooAsset/Runtime/BundleHandle/Services/VirtualBundleHandle/Operations/VBHLoadSubAssetsOperation.cs @@ -32,7 +32,7 @@ namespace YooAsset #else _steps = ESteps.Done; Status = EOperationStatus.Failed; - Error = $"{nameof(VirtualBundleLoadSubAssetsOperation)} only support unity editor platform."; + Error = $"{nameof(VBHLoadSubAssetsOperation)} is only supported in the Unity Editor."; #endif } internal override void InternalUpdate() diff --git a/Assets/YooAsset/Runtime/BundleHandle/Services/VirtualBundleHandle/VirtualBundleHandle.cs b/Assets/YooAsset/Runtime/BundleHandle/Services/VirtualBundleHandle/VirtualBundleHandle.cs index 4cb81d91..bdc88d4c 100644 --- a/Assets/YooAsset/Runtime/BundleHandle/Services/VirtualBundleHandle/VirtualBundleHandle.cs +++ b/Assets/YooAsset/Runtime/BundleHandle/Services/VirtualBundleHandle/VirtualBundleHandle.cs @@ -10,37 +10,52 @@ namespace YooAsset private readonly string _bundleFilePath; private readonly PackageBundle _packageBundle; - public VirtualBundleHandle(string bundleFilePath, PackageBundle bundle) + /// + /// 当前资源包对应的本地文件路径 + /// + public string BundleFilePath { - _bundleFilePath = bundleFilePath; - _packageBundle = bundle; - } - public void UnloadBundleFile() - { - } - public string GetBundleFilePath() - { - return _bundleFilePath; + get { return _bundleFilePath; } } + public VirtualBundleHandle(string bundleFilePath, PackageBundle packageBundle) + { + _bundleFilePath = bundleFilePath; + _packageBundle = packageBundle; + } + + /// + /// 虚拟资源包无需执行实际卸载操作 + /// + public void UnloadBundle() + { + } + + /// public BHLoadAssetOperation LoadAssetAsync(AssetInfo assetInfo) { var operation = new VBHLoadAssetOperation(_packageBundle, assetInfo); return operation; } + + /// public BHLoadAllAssetsOperation LoadAllAssetsAsync(AssetInfo assetInfo) { var operation = new VBHLoadAllAssetsOperation(_packageBundle, assetInfo); return operation; } + + /// public BHLoadSubAssetsOperation LoadSubAssetsAsync(AssetInfo assetInfo) { var operation = new VBHLoadSubAssetsOperation(_packageBundle, assetInfo); return operation; } - public BHLoadSceneOperation LoadSceneAsync(AssetInfo assetInfo, LoadSceneParameters loadSceneParams, bool suspendLoad) + + /// + public BHLoadSceneOperation LoadSceneAsync(AssetInfo assetInfo, LoadSceneParameters loadSceneParams, bool allowSceneActivation) { - var operation = new VBHLoadSceneOperation(assetInfo, loadSceneParams, suspendLoad); + var operation = new VBHLoadSceneOperation(assetInfo, loadSceneParams, allowSceneActivation); return operation; } } diff --git a/Assets/YooAsset/Runtime/DownloadSystem/DownloadReport.cs b/Assets/YooAsset/Runtime/DownloadSystem/DownloadReport.cs index c422b721..0429c48a 100644 --- a/Assets/YooAsset/Runtime/DownloadSystem/DownloadReport.cs +++ b/Assets/YooAsset/Runtime/DownloadSystem/DownloadReport.cs @@ -1,10 +1,16 @@ namespace YooAsset { + /// + /// 下载过程中的状态报告 + /// + /// + /// 用于传递当前请求的 HTTP 状态、错误信息、已下载字节数和下载进度。 + /// public struct DownloadReport { /// - /// HTTP 返回码 + /// HTTP 响应状态码 /// public long HttpCode { get; set; } @@ -21,11 +27,17 @@ namespace YooAsset /// /// 当前下载进度(0f - 1f) /// + /// + /// 取值范围通常为 0 到 1。 + /// public float DownloadProgress { get; set; } /// - /// 创建默认的下载进度实例 + /// 获取一个默认的下载报告实例 /// + /// + /// 默认实例中的各项字段均为其类型的默认值。 + /// public static DownloadReport Default { get diff --git a/Assets/YooAsset/Runtime/DownloadSystem/DownloadRetry.cs b/Assets/YooAsset/Runtime/DownloadSystem/DownloadRetry.cs deleted file mode 100644 index cecd124e..00000000 --- a/Assets/YooAsset/Runtime/DownloadSystem/DownloadRetry.cs +++ /dev/null @@ -1,93 +0,0 @@ -using UnityEngine; - -namespace YooAsset -{ - /// - /// 下载重试控制器 - /// - internal sealed class DownloadRetry - { - private readonly int _maxRetryCount; - private readonly IDownloadRetryPolicy _retryPolicy; - private int _retryCount; - private float _waitTimer; - private float _waitDuration; - - /// - /// 已重试次数 - /// - public int RetryCount => _retryCount; - - /// - /// 当前等待目标时长(秒) - /// - public float WaitDuration => _waitDuration; - - /// - /// 创建下载重试控制器 - /// - /// 最大重试次数 - /// 重试策略 - public DownloadRetry(int maxRetryCount, IDownloadRetryPolicy retryPolicy) - { - _maxRetryCount = maxRetryCount; - _retryPolicy = retryPolicy; - _retryCount = 0; - _waitTimer = 0f; - _waitDuration = 0f; - } - - /// - /// 判断本次失败是否允许重试 - /// - /// 请求地址 - /// HTTP 状态码 - /// HTTP 错误信息 - /// - /// 返回 true 表示允许重试;调用方应紧接着调用 BeginWait() 启动等待。 - /// 返回 false 表示不允许重试(达到次数上限或错误不可重试)。 - /// - public bool CanRetry(string url, long httpCode, string httpError) - { - if (_retryCount >= _maxRetryCount) - return false; - - if (_retryPolicy.IsRetryableError(url, httpCode, httpError) == false) - return false; - - YooLogger.Warning($"Download failed: {url}. HttpCode={httpCode}"); - return true; - } - - /// - /// 判断是否可以进入网络重试 - /// - public bool CanRetry() - { - if (_retryCount >= _maxRetryCount) - return false; - - return true; - } - - /// - /// 开始本次重试等待 - /// - public void BeginWait() - { - _waitTimer = 0f; - _retryCount++; - _waitDuration = _retryPolicy.ComputeDelay(_retryCount, _waitDuration); - YooLogger.Warning($"Download retrying in {WaitDuration:F1}s."); - } - - /// - /// 推进等待计时 - /// - public bool Tick() - { - _waitTimer += Time.unscaledDeltaTime; - return _waitTimer >= _waitDuration; - } - } -} diff --git a/Assets/YooAsset/Runtime/DownloadSystem/DownloadRetryController.cs b/Assets/YooAsset/Runtime/DownloadSystem/DownloadRetryController.cs new file mode 100644 index 00000000..9837d047 --- /dev/null +++ b/Assets/YooAsset/Runtime/DownloadSystem/DownloadRetryController.cs @@ -0,0 +1,105 @@ +using UnityEngine; + +namespace YooAsset +{ + /// + /// 下载重试控制器 + /// + /// + /// 负责管理下载请求的重试次数、重试资格判断以及重试前的等待时间。 + /// 该控制器本身不执行下载,仅用于驱动重试流程。 + /// + internal sealed class DownloadRetryController + { + private readonly int _maxRetryCount; + private readonly IDownloadRetryPolicy _retryPolicy; + private float _elapsedWaitTime; + private float _retryDelay; + private int _retryCount; + + /// + /// 已执行的重试次数 + /// + public int RetryCount => _retryCount; + + /// + /// 当前重试前需要等待的时长(秒) + /// + public float RetryDelay => _retryDelay; + + /// + /// 创建下载重试控制器 + /// + /// 最大重试次数 + /// 重试策略 + public DownloadRetryController(int maxRetryCount, IDownloadRetryPolicy retryPolicy) + { + _maxRetryCount = maxRetryCount; + _retryPolicy = retryPolicy; + _retryCount = 0; + _elapsedWaitTime = 0f; + _retryDelay = 0f; + } + + /// + /// 判断本次失败是否允许重试 + /// + /// 请求地址 + /// HTTP 状态码 + /// HTTP 错误信息 + /// + /// 返回 true 表示允许重试,调用方应紧接着调用 开始等待。 + /// 返回 false 表示本次失败不应继续重试。 + /// + public bool CanRetryRequest(string url, long httpCode, string httpError) + { + if (_retryCount >= _maxRetryCount) + return false; + + if (_retryPolicy.IsRetryableError(url, httpCode, httpError) == false) + return false; + + YooLogger.Warning($"Download failed: {url}. HttpCode={httpCode}"); + return true; + } + + /// + /// 判断当前是否还有可用的重试次数 + /// + /// + /// 返回 true 表示尚未达到最大重试次数。 + /// 返回 false 表示重试次数已耗尽。 + /// + public bool HasRetryQuota() + { + if (_retryCount >= _maxRetryCount) + return false; + + return true; + } + + /// + /// 开始本轮重试前的等待 + /// + public void StartRetryDelay() + { + _elapsedWaitTime = 0f; + _retryCount++; + _retryDelay = _retryPolicy.ComputeDelay(_retryCount, _retryDelay); + YooLogger.Warning($"Retrying download in {RetryDelay:F1}s."); + } + + /// + /// 推进重试等待计时 + /// + /// + /// 返回 true 表示等待时间已到,可以再次发起请求。 + /// 返回 false 表示仍需继续等待。 + /// + public bool UpdateRetryDelay() + { + _elapsedWaitTime += Time.unscaledDeltaTime; + return _elapsedWaitTime >= _retryDelay; + } + } +} diff --git a/Assets/YooAsset/Runtime/DownloadSystem/DownloadRetry.cs.meta b/Assets/YooAsset/Runtime/DownloadSystem/DownloadRetryController.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/DownloadSystem/DownloadRetry.cs.meta rename to Assets/YooAsset/Runtime/DownloadSystem/DownloadRetryController.cs.meta diff --git a/Assets/YooAsset/Runtime/DownloadSystem/DownloadSystemTools.cs b/Assets/YooAsset/Runtime/DownloadSystem/DownloadSystemTools.cs index 4a87a9e1..85c58a4c 100644 --- a/Assets/YooAsset/Runtime/DownloadSystem/DownloadSystemTools.cs +++ b/Assets/YooAsset/Runtime/DownloadSystem/DownloadSystemTools.cs @@ -10,66 +10,35 @@ namespace YooAsset internal class DownloadSystemTools { /// - /// 转换为本地文件请求地址 + /// 将本地文件路径转换为 UnityWebRequest 可用的 URL /// - /// 本地文件路径 + /// 本地文件路径 /// 可用于 UnityWebRequest 的文件协议 URL - public static string ToLocalUrl(string path) + /// + /// 不支持 content:// 等文档 URI + /// + public static string ToLocalFileUrl(string filePath) { + if (IsLocalFileUrl(filePath)) + return EscapeSpecialCharacters(filePath); + string url; - // 获取对应平台的URL地址 - // 说明:苹果不同设备上操作系统不同。 - // 说明:iPhone和iPod对应的是iOS系统。 - // 说明:iPad对应的是iPadOS系统。 - // 说明:AppleTV对应的是tvOS系统。 - // TODO 安卓平台未考虑外部存储器 - // TODO Linux平台确认路径正确 -#if UNITY_EDITOR_OSX - url = StringUtility.Format("file://{0}", path); -#elif UNITY_EDITOR_WIN - url = StringUtility.Format("file:///{0}", path); -#elif UNITY_WEBGL - url = path; -#elif UNITY_IOS || UNITY_IPHONE - url = StringUtility.Format("file://{0}", path); +#if UNITY_WEBGL + url = filePath; #elif UNITY_ANDROID - if (path.StartsWith("jar:file://")) - url = path; - else - url = StringUtility.Format("jar:file://{0}", path); + url = new System.Uri(filePath).ToString(); #elif UNITY_OPENHARMONY + // 注意:由于鸿蒙系统的特殊性,需要判断双形态 if (UnityEngine.Application.streamingAssetsPath.StartsWith("jar:file://")) - { - if (path.StartsWith("jar:file://")) - url = path; - else - url = StringUtility.Format("jar:file://{0}", path); - } + url = StringUtility.Format("jar:file://{0}", filePath); else - { - if (path.StartsWith("file://")) - url = path; - else - url = StringUtility.Format("file://{0}", path); - } - -#elif UNITY_WSA - url = StringUtility.Format("file:///{0}", path); -#elif UNITY_TVOS - url = StringUtility.Format("file:///{0}", path); -#elif UNITY_STANDALONE_OSX - url = new System.Uri(path).ToString(); -#elif UNITY_STANDALONE_WIN - url = StringUtility.Format("file:///{0}", path); -#elif UNITY_STANDALONE_LINUX - url = StringUtility.Format("file:///root/{0}", path); + url = new System.Uri(filePath).ToString(); #else - throw new System.NotSupportedException($"Platform '{UnityEngine.Application.platform}' is not supported."); + url = new System.Uri(filePath).ToString(); #endif - // 处理特殊字符:用户设备路径可能包含特殊字符导致 URL 无法正确识别 - return url.Replace("+", "%2B").Replace("#", "%23").Replace("?", "%3F"); + return EscapeSpecialCharacters(url); } /// @@ -79,17 +48,19 @@ namespace YooAsset /// 如果是本地文件 URL 返回 true,否则返回 false public static bool IsLocalFileUrl(string url) { - //TODO UNITY_STANDALONE_OSX平台目前无法确定 - - // 本地文件传输协议 - if (url.StartsWith("file:")) + if (url.StartsWith("file://")) return true; - // JAR文件协议 - if (url.StartsWith("jar:file:")) + if (url.StartsWith("jar:file://")) return true; return false; } + + private static string EscapeSpecialCharacters(string url) + { + // 处理特殊字符:用户设备路径可能包含特殊字符导致 URL 无法正确识别 + return url.Replace("+", "%2B").Replace("#", "%23").Replace("?", "%3F"); + } } } diff --git a/Assets/YooAsset/Runtime/DownloadSystem/EDownloadRequestStatus.cs b/Assets/YooAsset/Runtime/DownloadSystem/EDownloadRequestStatus.cs index f3dd334b..83b9d7a2 100644 --- a/Assets/YooAsset/Runtime/DownloadSystem/EDownloadRequestStatus.cs +++ b/Assets/YooAsset/Runtime/DownloadSystem/EDownloadRequestStatus.cs @@ -25,13 +25,5 @@ namespace YooAsset /// 已失败 /// Failed, - - /// - /// 已中止 - /// - /// - /// 可能由用户主动调用 AbortRequest() 或看门狗超时触发。 - /// - Aborted, } } diff --git a/Assets/YooAsset/Runtime/DownloadSystem/Operations/DownloadFileBaseOperation.cs b/Assets/YooAsset/Runtime/DownloadSystem/Operations/DownloadFileBaseOperation.cs index e96b0dad..b672529e 100644 --- a/Assets/YooAsset/Runtime/DownloadSystem/Operations/DownloadFileBaseOperation.cs +++ b/Assets/YooAsset/Runtime/DownloadSystem/Operations/DownloadFileBaseOperation.cs @@ -1,6 +1,9 @@ namespace YooAsset { + /// + /// 文件下载操作的抽象基类 + /// internal abstract class DownloadFileBaseOperation : AsyncOperationBase { /// @@ -16,12 +19,12 @@ namespace YooAsset /// /// 引用计数 /// - public int RefCount { private set; get; } + public int ReferenceCount { private set; get; } /// /// 下载报告 /// - public DownloadReport Report; + public DownloadReport LatestReport; public DownloadFileBaseOperation(PackageBundle bundle, string url) { @@ -30,23 +33,29 @@ namespace YooAsset } internal override string InternalGetDescription() { - return $"RefCount: {RefCount}"; + return $"Reference count: {ReferenceCount}"; } /// - /// 减少引用计数 + /// 释放一次引用 /// + /// + /// 当引用计数降为零时,下载调度器可终止并移除该任务。 + /// public void Release() { - RefCount--; + ReferenceCount--; } /// - /// 增加引用计数 + /// 增加一次引用 /// + /// + /// 当同一资源被多个请求复用时,可通过增加引用计数延长任务生命周期。 + /// public void Reference() { - RefCount++; + ReferenceCount++; } } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/DownloadSystem/Operations/DownloadSchedulerOperation.cs b/Assets/YooAsset/Runtime/DownloadSystem/Operations/DownloadSchedulerOperation.cs index 82a8272e..7a87baa5 100644 --- a/Assets/YooAsset/Runtime/DownloadSystem/Operations/DownloadSchedulerOperation.cs +++ b/Assets/YooAsset/Runtime/DownloadSystem/Operations/DownloadSchedulerOperation.cs @@ -11,15 +11,43 @@ namespace YooAsset /// internal class DownloadSchedulerOperation : AsyncOperationBase { + /// + /// 下载调度器的配置项 + /// public struct SchedulerConfig { + /// + /// 调度器名称 + /// + /// + /// 主要用于调试信息和运行时描述输出。 + /// public string SchedulerName { get; set; } + + /// + /// 下载后端实现 + /// + /// + /// 负责创建和驱动具体的下载请求对象。 + /// public IDownloadBackend DownloadBackend { get; set; } + + /// + /// 最大并发下载数量 + /// public int MaxConcurrency { get; set; } + + /// + /// 每帧最多启动的请求数量 + /// + /// + /// 用于限制单帧内集中创建过多请求,降低瞬时开销。 + /// public int MaxRequestPerFrame { get; set; } } private readonly Dictionary _downloaders = new Dictionary(1000); + private readonly List _updateSnapshot = new List(1000); private readonly List _removeList = new List(1000); private readonly SchedulerConfig _config; @@ -56,22 +84,29 @@ namespace YooAsset // 驱动下载后台 _config.DownloadBackend.Update(); - // 获取可移除的下载器集合 - _removeList.Clear(); - foreach (var valuePair in _downloaders) + // 快照遍历 + _updateSnapshot.Clear(); + foreach (var kvp in _downloaders) { - var downloader = valuePair.Value; + _updateSnapshot.Add(kvp.Value); + } + + // 更新下载器 + _removeList.Clear(); + foreach (var downloader in _updateSnapshot) + { + string bundleGUID = downloader.Bundle.BundleGUID; downloader.UpdateOperation(); if (downloader.IsDone) { - _removeList.Add(valuePair.Key); + _removeList.Add(bundleGUID); continue; } // 注意:主动终止引用计数为零的下载任务 - if (downloader.RefCount <= 0) + if (downloader.ReferenceCount <= 0) { - _removeList.Add(valuePair.Key); + _removeList.Add(bundleGUID); downloader.AbortOperation(); continue; } @@ -87,12 +122,14 @@ namespace YooAsset } } + // 注意:统计始终保持最新 + ActiveDownloadCount = GetActiveOperationCount(); + // 暂停时不启动新任务 if (Paused) return; // 最大并发数检测 - ActiveDownloadCount = GetProcessingOperationCount(); if (ActiveDownloadCount != _downloaders.Count) { int maxConcurrency = _config.MaxConcurrency; @@ -121,38 +158,7 @@ namespace YooAsset { return _config.SchedulerName; } - - /// - /// 尝试获取已经存在的下载器 - /// - public DownloadFileBaseOperation TryGetDownloadFile(PackageBundle bundle) - { - if (_downloaders.TryGetValue(bundle.BundleGUID, out var oldDownloader)) - { - oldDownloader.Reference(); - return oldDownloader; - } - return null; - } - - /// - /// 添加新的下载器到调度中心 - /// - public void AddDownloadFile(DownloadFileBaseOperation downloadFileOp) - { - string bundleGUID = downloadFileOp.Bundle.BundleGUID; - if (_downloaders.ContainsKey(bundleGUID)) - throw new YooInternalException(); - - AddChildOperation(downloadFileOp); - _downloaders.Add(bundleGUID, downloadFileOp); - downloadFileOp.Reference(); - } - - /// - /// 获取正在进行中的下载器总数 - /// - private int GetProcessingOperationCount() + private int GetActiveOperationCount() { int count = 0; foreach (var operationPair in _downloaders) @@ -163,5 +169,41 @@ namespace YooAsset } return count; } + + /// + /// 尝试获取指定资源包对应的下载任务 + /// + /// 目标资源包 + /// + /// 如果下载任务已存在,则返回对应的下载任务并增加一次引用。 + /// 如果不存在,则返回 null。 + /// + public DownloadFileBaseOperation TryAcquireDownloadOperation(PackageBundle bundle) + { + if (_downloaders.TryGetValue(bundle.BundleGUID, out var oldDownloader)) + { + oldDownloader.Reference(); + return oldDownloader; + } + return null; + } + + /// + /// 注册一个新的下载任务 + /// + /// 要注册的下载任务 + /// + /// 注册后该任务会被纳入调度器统一管理,并自动增加一次引用。 + /// + public void RegisterDownloadOperation(DownloadFileBaseOperation downloadFileOp) + { + string bundleGUID = downloadFileOp.Bundle.BundleGUID; + if (_downloaders.ContainsKey(bundleGUID)) + throw new YooInternalException(); + + AddChildOperation(downloadFileOp); + _downloaders.Add(bundleGUID, downloadFileOp); + downloadFileOp.Reference(); + } } } diff --git a/Assets/YooAsset/Runtime/DownloadSystem/Services/DownloadPolicy.meta b/Assets/YooAsset/Runtime/DownloadSystem/Policies.meta similarity index 100% rename from Assets/YooAsset/Runtime/DownloadSystem/Services/DownloadPolicy.meta rename to Assets/YooAsset/Runtime/DownloadSystem/Policies.meta diff --git a/Assets/YooAsset/Runtime/DownloadSystem/Services/DownloadPolicy/DefaultDownloadRetryPolicy.cs b/Assets/YooAsset/Runtime/DownloadSystem/Policies/DefaultDownloadRetryPolicy.cs similarity index 100% rename from Assets/YooAsset/Runtime/DownloadSystem/Services/DownloadPolicy/DefaultDownloadRetryPolicy.cs rename to Assets/YooAsset/Runtime/DownloadSystem/Policies/DefaultDownloadRetryPolicy.cs diff --git a/Assets/YooAsset/Runtime/DownloadSystem/Services/DownloadPolicy/DefaultDownloadRetryPolicy.cs.meta b/Assets/YooAsset/Runtime/DownloadSystem/Policies/DefaultDownloadRetryPolicy.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/DownloadSystem/Services/DownloadPolicy/DefaultDownloadRetryPolicy.cs.meta rename to Assets/YooAsset/Runtime/DownloadSystem/Policies/DefaultDownloadRetryPolicy.cs.meta diff --git a/Assets/YooAsset/Runtime/DownloadSystem/Services/DownloadPolicy/DefaultDownloadURLPolicy.cs b/Assets/YooAsset/Runtime/DownloadSystem/Policies/DefaultDownloadURLPolicy.cs similarity index 61% rename from Assets/YooAsset/Runtime/DownloadSystem/Services/DownloadPolicy/DefaultDownloadURLPolicy.cs rename to Assets/YooAsset/Runtime/DownloadSystem/Policies/DefaultDownloadURLPolicy.cs index d0bc8817..257cef91 100644 --- a/Assets/YooAsset/Runtime/DownloadSystem/Services/DownloadPolicy/DefaultDownloadURLPolicy.cs +++ b/Assets/YooAsset/Runtime/DownloadSystem/Policies/DefaultDownloadURLPolicy.cs @@ -5,15 +5,18 @@ namespace YooAsset /// /// 默认的 URL 选择策略 /// - public class DefaultDownloadURLPolicy : IDownloadURLPolicy + public class DefaultDownloadURLPolicy : IDownloadUrlPolicy { private int _failureCount = 0; /// /// 基于内部失败计数轮转选择 URL /// - public string SelectURL(IReadOnlyList candidateURLs) + public string SelectUrl(IReadOnlyList candidateURLs) { + if (candidateURLs == null || candidateURLs.Count == 0) + throw new YooInternalException("SelectUrl failed: candidateURLs is null or empty."); + int index = _failureCount % candidateURLs.Count; return candidateURLs[index]; } @@ -21,14 +24,14 @@ namespace YooAsset /// /// 请求成功反馈(默认策略不做处理) /// - public void OnSuccess(string url) + public void OnRequestSucceeded(string url) { } /// /// 请求失败反馈,递增失败计数以切换 URL /// - public void OnFailure(string url, long httpCode, string httpError) + public void OnRequestFailed(string url, long httpCode, string httpError) { _failureCount++; } diff --git a/Assets/YooAsset/Runtime/DownloadSystem/Services/DownloadPolicy/DefaultDownloadURLPolicy.cs.meta b/Assets/YooAsset/Runtime/DownloadSystem/Policies/DefaultDownloadURLPolicy.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/DownloadSystem/Services/DownloadPolicy/DefaultDownloadURLPolicy.cs.meta rename to Assets/YooAsset/Runtime/DownloadSystem/Policies/DefaultDownloadURLPolicy.cs.meta diff --git a/Assets/YooAsset/Runtime/DownloadSystem/Services/UnityWebRequest/SimulatedFileRequest.cs b/Assets/YooAsset/Runtime/DownloadSystem/Services/UnityWebRequest/SimulatedFileRequest.cs index fb09c347..347c3432 100644 --- a/Assets/YooAsset/Runtime/DownloadSystem/Services/UnityWebRequest/SimulatedFileRequest.cs +++ b/Assets/YooAsset/Runtime/DownloadSystem/Services/UnityWebRequest/SimulatedFileRequest.cs @@ -19,7 +19,12 @@ namespace YooAsset /// /// 最近一次更新的时间戳(用于计算时间增量) /// - private double _lastestUpdateTime; + private double _lastUpdateTime; + + /// + /// 小数字节总量累积 + /// + private double _bytesAccumulator; /// /// 文件保存路径(模拟下载不需要) @@ -44,8 +49,7 @@ namespace YooAsset { PollRequest(); return Status == EDownloadRequestStatus.Succeeded - || Status == EDownloadRequestStatus.Failed - || Status == EDownloadRequestStatus.Aborted; + || Status == EDownloadRequestStatus.Failed; } } @@ -99,7 +103,7 @@ namespace YooAsset if (Status == EDownloadRequestStatus.None) { Status = EDownloadRequestStatus.Running; - _lastestUpdateTime = TimeUtility.RealtimeSinceStartup; + _lastUpdateTime = TimeUtility.RealtimeSinceStartup; } } @@ -110,7 +114,7 @@ namespace YooAsset { if (Status == EDownloadRequestStatus.None || Status == EDownloadRequestStatus.Running) { - Status = EDownloadRequestStatus.Aborted; + Status = EDownloadRequestStatus.Failed; } } @@ -130,12 +134,12 @@ namespace YooAsset return; double currentTime = TimeUtility.RealtimeSinceStartup; - double deltaTime = currentTime - _lastestUpdateTime; - _lastestUpdateTime = currentTime; + double deltaTime = currentTime - _lastUpdateTime; + _lastUpdateTime = currentTime; - // 计算本帧下载的字节数 - long downloadBytes = (long)(_args.DownloadSpeed * deltaTime); - DownloadedBytes += downloadBytes; + // 注意:累积小数字节后取整,避免低速高帧率时每帧截断为 0 + _bytesAccumulator += _args.DownloadSpeed * deltaTime; + DownloadedBytes = (long)_bytesAccumulator; if (_args.FileSize > 0) DownloadProgress = (float)DownloadedBytes / _args.FileSize; diff --git a/Assets/YooAsset/Runtime/DownloadSystem/Services/UnityWebRequest/UnityWebRequestAssetBundle.cs b/Assets/YooAsset/Runtime/DownloadSystem/Services/UnityWebRequest/UnityWebRequestAssetBundle.cs index f9d9d6c2..40649ae4 100644 --- a/Assets/YooAsset/Runtime/DownloadSystem/Services/UnityWebRequest/UnityWebRequestAssetBundle.cs +++ b/Assets/YooAsset/Runtime/DownloadSystem/Services/UnityWebRequest/UnityWebRequestAssetBundle.cs @@ -60,7 +60,7 @@ namespace YooAsset if (assetBundle == null) { Status = EDownloadRequestStatus.Failed; - Error = $"[{GetType().Name}] Failed to load AssetBundle. URL: {Url}, Error: AssetBundle object is null"; + Error = $"[{GetType().Name}] Failed to load the AssetBundle. URL: {Url}, Error: Received a null AssetBundle."; } else { diff --git a/Assets/YooAsset/Runtime/DownloadSystem/Services/UnityWebRequest/UnityWebRequestBase.cs b/Assets/YooAsset/Runtime/DownloadSystem/Services/UnityWebRequest/UnityWebRequestBase.cs index 4abeda97..c7b848fa 100644 --- a/Assets/YooAsset/Runtime/DownloadSystem/Services/UnityWebRequest/UnityWebRequestBase.cs +++ b/Assets/YooAsset/Runtime/DownloadSystem/Services/UnityWebRequest/UnityWebRequestBase.cs @@ -36,12 +36,12 @@ namespace YooAsset /// /// 最近一次记录的下载字节数 /// - private long _lastestDownloadBytes = -1; + private long _lastDownloadBytes = -1; /// /// 最近一次接收数据的时间 /// - private double _lastestDataReceivedTime; + private double _lastDataReceivedTime; #region 接口实现 /// @@ -50,10 +50,11 @@ namespace YooAsset public string Url { get; } /// - /// 是否完成 + /// 是否已完成 /// /// - /// 每次访问此属性都会自动调用内部方法 UpdateRequest() 进行状态更新。 + /// 每次访问该属性时,都会先调用内部轮询逻辑更新请求状态。 + /// 当状态为 Succeeded、Failed 时返回 true。 /// public bool IsDone { @@ -61,8 +62,7 @@ namespace YooAsset { PollRequest(); return Status == EDownloadRequestStatus.Succeeded - || Status == EDownloadRequestStatus.Failed - || Status == EDownloadRequestStatus.Aborted; + || Status == EDownloadRequestStatus.Failed; } } @@ -92,8 +92,11 @@ namespace YooAsset public string HttpError { get; private set; } /// - /// 错误信息 + /// 请求失败时的错误信息 /// + /// + /// 仅在请求失败时有意义;成功或尚未完成时通常为空。 + /// public string Error { get; protected set; } #endregion @@ -149,13 +152,18 @@ namespace YooAsset /// /// /// 可在任意状态调用,仅当 Status 为 None 或 Running 时生效。 - /// 调用后 Status 变为 Aborted。 /// public void AbortRequest() { - if (Status == EDownloadRequestStatus.None || Status == EDownloadRequestStatus.Running) + if (Status == EDownloadRequestStatus.None) { - Status = EDownloadRequestStatus.Aborted; + Status = EDownloadRequestStatus.Failed; + Error = $"[{GetType().Name}] Request canceled. URL: {Url}"; + } + + if (Status == EDownloadRequestStatus.Running) + { + // 注意:等待引擎底层自行终止网络请求 if (_webRequest != null) _webRequest.Abort(); } @@ -295,18 +303,19 @@ namespace YooAsset return; double realtimeSinceStartup = TimeUtility.RealtimeSinceStartup; - if (DownloadedBytes != _lastestDownloadBytes) + if (DownloadedBytes != _lastDownloadBytes) { - _lastestDownloadBytes = DownloadedBytes; - _lastestDataReceivedTime = realtimeSinceStartup; + _lastDownloadBytes = DownloadedBytes; + _lastDataReceivedTime = realtimeSinceStartup; } else { - double deltaTime = realtimeSinceStartup - _lastestDataReceivedTime; + double deltaTime = realtimeSinceStartup - _lastDataReceivedTime; if (deltaTime > _watchdogTimeout) { _watchdogAborted = true; AbortRequest(); //看门狗终止网络请求 + YooLogger.Warning($"[{GetType().Name}] Watchdog timeout. URL: {Url}"); } } } diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/FCClearCacheOperation.cs b/Assets/YooAsset/Runtime/FileCache/Operations/FCClearCacheOperation.cs deleted file mode 100644 index 265529cd..00000000 --- a/Assets/YooAsset/Runtime/FileCache/Operations/FCClearCacheOperation.cs +++ /dev/null @@ -1,167 +0,0 @@ -using System.Collections.Generic; - -namespace YooAsset -{ - /// - /// 清理缓存操作基类 - /// - internal abstract class FCClearCacheOperation : AsyncOperationBase - { - protected readonly struct ClearResult - { - /// - /// 错误信息 - /// - public readonly string Error; - - /// - /// 需要清理的资源标识符集合 - /// - public readonly List BundleGUIDs; - - /// - /// 是否成功 - /// - public bool Succeeded - { - get { return Error == null; } - } - - public ClearResult(string error) - { - Error = error; - BundleGUIDs = null; - } - public ClearResult(List bundleGUIDs) - { - Error = null; - BundleGUIDs = bundleGUIDs; - } - - public static ClearResult Success(List bundleGUIDs) - { - return new ClearResult(bundleGUIDs); - } - public static ClearResult Failure(string error) - { - return new ClearResult(error); - } - } - - protected ClearResult GetAllCache(IReadOnlyCollection cacheEntries) - { - var bundleGUIDs = new List(cacheEntries.Count); - foreach (var entry in cacheEntries) - { - bundleGUIDs.Add(entry.BundleGUID); - } - return ClearResult.Success(bundleGUIDs); - } - protected ClearResult GetUnusedCache(FCClearCacheOptions options, IReadOnlyCollection cacheEntries) - { - if (options.Manifest == null) - return ClearResult.Failure("Active package manifest not found."); - - var bundleGUIDs = new List(cacheEntries.Count); - foreach (var entry in cacheEntries) - { - if (options.Manifest.IsIncludeBundleFile(entry.BundleGUID) == false) - { - bundleGUIDs.Add(entry.BundleGUID); - } - } - return ClearResult.Success(bundleGUIDs); - } - protected ClearResult GetCacheByLocations(FCClearCacheOptions options, IReadOnlyCollection cacheEntries) - { - if (options.Manifest == null) - return ClearResult.Failure("Active package manifest not found."); - - if (options.ClearParam == null) - return ClearResult.Failure("Clear param is null."); - - string[] locations; - if (options.ClearParam is string str) - locations = new string[] { str }; - else if (options.ClearParam is List list) - locations = list.ToArray(); - else if (options.ClearParam is string[] array) - locations = array; - else - return ClearResult.Failure($"Invalid clear param: {options.ClearParam.GetType().FullName}"); - - var bundleGUIDs = new List(locations.Length); - foreach (var location in locations) - { - string assetPath = options.Manifest.TryMappingToAssetPath(location); - if (options.Manifest.TryGetPackageAsset(assetPath, out PackageAsset packageAsset)) - { - PackageBundle bundle = options.Manifest.GetMainPackageBundle(packageAsset.BundleID); - bundleGUIDs.Add(bundle.BundleGUID); - } - } - return ClearResult.Success(bundleGUIDs); - } - protected ClearResult GetCacheByTags(FCClearCacheOptions options, IReadOnlyCollection cacheEntries) - { - if (options.Manifest == null) - return ClearResult.Failure("Active package manifest not found."); - - if (options.ClearParam == null) - return ClearResult.Failure("Clear param is null."); - - string[] tags; - if (options.ClearParam is string str) - tags = new string[] { str }; - else if (options.ClearParam is List list) - tags = list.ToArray(); - else if (options.ClearParam is string[] array) - tags = array; - else - return ClearResult.Failure($"Invalid clear param: {options.ClearParam.GetType().FullName}"); - - var bundleGUIDs = new List(cacheEntries.Count); - foreach (var entry in cacheEntries) - { - if (options.Manifest.TryGetPackageBundleByBundleGUID(entry.BundleGUID, out PackageBundle bundle)) - { - if (bundle.HasTag(tags)) - bundleGUIDs.Add(bundle.BundleGUID); - } - } - return ClearResult.Success(bundleGUIDs); - } - } - - /// - /// 清理缓存完成操作 - /// - internal class FCClearCacheCompleteOperation : FCClearCacheOperation - { - private readonly string _error; - - public FCClearCacheCompleteOperation() - { - _error = null; - } - public FCClearCacheCompleteOperation(string error) - { - _error = error; - } - internal override void InternalStart() - { - if (string.IsNullOrEmpty(_error)) - { - Status = EOperationStatus.Succeeded; - } - else - { - Status = EOperationStatus.Failed; - Error = _error; - } - } - internal override void InternalUpdate() - { - } - } -} diff --git a/Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/Operations/EFCClearCacheOperation.cs b/Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/Operations/EFCClearCacheOperation.cs deleted file mode 100644 index cc9eb441..00000000 --- a/Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/Operations/EFCClearCacheOperation.cs +++ /dev/null @@ -1,93 +0,0 @@ - -using System.Collections.Generic; - -namespace YooAsset -{ - /// - /// 清理沙盒文件缓存操作 - /// - internal class EFCClearCacheOperation : FCClearCacheOperation - { - private enum ESteps - { - None, - GetResult, - ClearCacheFiles, - Done, - } - - private readonly EditorFileCache _fileCache; - private readonly FCClearCacheOptions _options; - private List _bundleGUIDs; - private ESteps _steps = ESteps.None; - - internal EFCClearCacheOperation(EditorFileCache fileCache, FCClearCacheOptions options) - { - _fileCache = fileCache; - _options = options; - } - internal override void InternalStart() - { - _steps = ESteps.GetResult; - } - internal override void InternalUpdate() - { - if (_steps == ESteps.None || _steps == ESteps.Done) - return; - - if (_steps == ESteps.GetResult) - { - ClearResult clearResult; - if (_options.ClearMode == EFileClearMode.ClearAllBundleFiles.ToString()) - { - clearResult = GetAllCache(_fileCache.GetAllEntries()); - } - else if (_options.ClearMode == EFileClearMode.ClearUnusedBundleFiles.ToString()) - { - clearResult = GetUnusedCache(_options, _fileCache.GetAllEntries()); - } - else if (_options.ClearMode == EFileClearMode.ClearBundleFilesByLocations.ToString()) - { - clearResult = GetCacheByLocations(_options, _fileCache.GetAllEntries()); - } - else if (_options.ClearMode == EFileClearMode.ClearBundleFilesByTags.ToString()) - { - clearResult = GetCacheByTags(_options, _fileCache.GetAllEntries()); - } - else - { - _steps = ESteps.Done; - Status = EOperationStatus.Failed; - Error = $"Invalid clear mode: {_options.ClearMode}"; - return; - } - - if (clearResult.Succeeded == false) - { - _steps = ESteps.Done; - Status = EOperationStatus.Failed; - Error = clearResult.Error; - return; - } - - _bundleGUIDs = clearResult.BundleGUIDs; - _steps = ESteps.ClearCacheFiles; - } - - if (_steps == ESteps.ClearCacheFiles) - { - foreach(var bundleGUID in _bundleGUIDs) - { - _fileCache.RemoveEntry(bundleGUID); - } - - _steps = ESteps.Done; - Status = EOperationStatus.Succeeded; - } - } - internal override void InternalWaitForCompletion() - { - ExecuteBatch(); - } - } -} diff --git a/Assets/YooAsset/Runtime/FileSystem/FileSystemConsts.cs b/Assets/YooAsset/Runtime/FileSystem/FileSystemConsts.cs index 22a5b9c8..305c2f8c 100644 --- a/Assets/YooAsset/Runtime/FileSystem/FileSystemConsts.cs +++ b/Assets/YooAsset/Runtime/FileSystem/FileSystemConsts.cs @@ -132,7 +132,7 @@ namespace YooAsset public const string DOWNLOAD_RETRY_POLICY = "DOWNLOAD_RETRY_POLICY"; /// - /// URL 选择策略 + /// URL 选择策略 /// public const string DOWNLOAD_URL_POLICY = "DOWNLOAD_URL_POLICY"; } diff --git a/Assets/YooAsset/Runtime/FileSystem/Operations/Common/LoadWebPackageManifestOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Operations/Common/LoadWebPackageManifestOperation.cs index 242dd1bb..8bf5ae7a 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Operations/Common/LoadWebPackageManifestOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Operations/Common/LoadWebPackageManifestOperation.cs @@ -62,7 +62,7 @@ namespace YooAsset _steps = ESteps.Done; Status = EOperationStatus.Failed; Error = _downloadBytesRequest.Error; - _options.URLPolicy.OnFailure(_downloadBytesRequest.Url, _downloadBytesRequest.HttpCode, _downloadBytesRequest.HttpError); + _options.URLPolicy.OnRequestFailed(_downloadBytesRequest.Url, _downloadBytesRequest.HttpCode, _downloadBytesRequest.HttpError); } } @@ -124,7 +124,7 @@ namespace YooAsset private string GetRequestURL(string fileName) { var urls = _options.RemoteServices.GetRemoteURLs(fileName); - return _options.URLPolicy.SelectURL(urls); + return _options.URLPolicy.SelectUrl(urls); } } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/FileSystem/Operations/Common/LoadWebPackageManifestOptions.cs b/Assets/YooAsset/Runtime/FileSystem/Operations/Common/LoadWebPackageManifestOptions.cs index b5db96ad..34054886 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Operations/Common/LoadWebPackageManifestOptions.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Operations/Common/LoadWebPackageManifestOptions.cs @@ -10,6 +10,6 @@ namespace YooAsset public IRemoteServices RemoteServices { get; set; } public IManifestDecryptor ManifestDecryptor { get; set; } public IDownloadBackend DownloadBackend { get; set; } - public IDownloadURLPolicy URLPolicy { get; set; } + public IDownloadUrlPolicy URLPolicy { get; set; } } } diff --git a/Assets/YooAsset/Runtime/FileSystem/Operations/Common/RequestWebPackageHashOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Operations/Common/RequestWebPackageHashOperation.cs index 5972b3ab..6b1427d0 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Operations/Common/RequestWebPackageHashOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Operations/Common/RequestWebPackageHashOperation.cs @@ -70,7 +70,7 @@ namespace YooAsset _steps = ESteps.Done; Status = EOperationStatus.Failed; Error = _downloadTextRequest.Error; - _options.URLPolicy.OnFailure(_downloadTextRequest.Url, _downloadTextRequest.HttpCode, _downloadTextRequest.HttpError); + _options.URLPolicy.OnRequestFailed(_downloadTextRequest.Url, _downloadTextRequest.HttpCode, _downloadTextRequest.HttpError); } } } @@ -86,7 +86,7 @@ namespace YooAsset private string GetRequestURL(string fileName) { var urls = _options.RemoteServices.GetRemoteURLs(fileName); - return _options.URLPolicy.SelectURL(urls); + return _options.URLPolicy.SelectUrl(urls); } } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/FileSystem/Operations/Common/RequestWebPackageHashOptions.cs b/Assets/YooAsset/Runtime/FileSystem/Operations/Common/RequestWebPackageHashOptions.cs index 2bca92ee..85f2a41b 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Operations/Common/RequestWebPackageHashOptions.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Operations/Common/RequestWebPackageHashOptions.cs @@ -8,6 +8,6 @@ namespace YooAsset public IRemoteServices RemoteServices { get; set; } public IDownloadBackend DownloadBackend { get; set; } - public IDownloadURLPolicy URLPolicy { get; set; } + public IDownloadUrlPolicy URLPolicy { get; set; } } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/FileSystem/Operations/Common/RequestWebPackageVersionOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Operations/Common/RequestWebPackageVersionOperation.cs index 6a98ff5b..fc538cf9 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Operations/Common/RequestWebPackageVersionOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Operations/Common/RequestWebPackageVersionOperation.cs @@ -70,7 +70,7 @@ namespace YooAsset _steps = ESteps.Done; Status = EOperationStatus.Failed; Error = _downloadTextRequest.Error; - _options.URLPolicy.OnFailure(_downloadTextRequest.Url, _downloadTextRequest.HttpCode, _downloadTextRequest.HttpError); + _options.URLPolicy.OnRequestFailed(_downloadTextRequest.Url, _downloadTextRequest.HttpCode, _downloadTextRequest.HttpError); } } } @@ -86,7 +86,7 @@ namespace YooAsset private string GetRequestURL(string fileName) { var urls = _options.RemoteServices.GetRemoteURLs(fileName); - string url = _options.URLPolicy.SelectURL(urls); + string url = _options.URLPolicy.SelectUrl(urls); // 在URL末尾添加时间戳 if (_options.AppendTimeTicks) diff --git a/Assets/YooAsset/Runtime/FileSystem/Operations/Common/RequestWebPackageVersionOptions.cs b/Assets/YooAsset/Runtime/FileSystem/Operations/Common/RequestWebPackageVersionOptions.cs index 22c2f6f2..d0e6d849 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Operations/Common/RequestWebPackageVersionOptions.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Operations/Common/RequestWebPackageVersionOptions.cs @@ -8,6 +8,6 @@ namespace YooAsset public IRemoteServices RemoteServices { get; set; } public IDownloadBackend DownloadBackend { get; set; } - public IDownloadURLPolicy URLPolicy { get; set; } + public IDownloadUrlPolicy URLPolicy { get; set; } } } diff --git a/Assets/YooAsset/Runtime/FileSystem/Operations/FSClearCacheOptions.cs b/Assets/YooAsset/Runtime/FileSystem/Operations/FSClearCacheOptions.cs index 0d0cff73..44cc9572 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Operations/FSClearCacheOptions.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Operations/FSClearCacheOptions.cs @@ -22,11 +22,11 @@ namespace YooAsset public PackageManifest Manifest { get; set; } /// - /// 转换为 FileCache 的清理选项 + /// 转换为 BundleCache 的清理选项 /// - public FCClearCacheOptions ConvertTo() + public BCClearCacheOptions ConvertTo() { - var options = new FCClearCacheOptions(); + var options = new BCClearCacheOptions(); options.ClearMode = ClearMode; options.ClearParam = ClearParam; options.Manifest = Manifest; diff --git a/Assets/YooAsset/Runtime/FileSystem/Operations/FSLoadPackageBundleOptions.cs b/Assets/YooAsset/Runtime/FileSystem/Operations/FSLoadPackageBundleOptions.cs index ab23ffa0..1ec52f44 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Operations/FSLoadPackageBundleOptions.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Operations/FSLoadPackageBundleOptions.cs @@ -17,11 +17,11 @@ namespace YooAsset } /// - /// 转换为 FileCache 的加载选项 + /// 转换为 BundleCache 的加载选项 /// - public FCLoadBundleOptions ConvertTo() + public BCLoadBundleOptions ConvertTo() { - return new FCLoadBundleOptions(Bundle); + return new BCLoadBundleOptions(Bundle); } } } diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/BuiltinFileSystem.cs b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/BuiltinFileSystem.cs index 80bd8f30..0da4dc78 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/BuiltinFileSystem.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/BuiltinFileSystem.cs @@ -18,14 +18,14 @@ namespace YooAsset protected string _unpackBundleFilesRoot; /// - /// 内置文件缓存系统 + /// 内置Bundle缓存系统 /// - public IFileCache BuiltinFileCache { get; private set; } + public IBundleCache BuiltinBundleCache { get; private set; } /// - /// 沙盒文件缓存系统 + /// 解压Bundle缓存系统 /// - public IFileCache UnpackFileCache { get; private set; } + public IBundleCache UnpackBundleCache { get; private set; } /// /// 解压调度器 @@ -266,36 +266,36 @@ namespace YooAsset // 创建内置文件缓存系统 { - var cacheConfig = new BuiltinFileCache.CacheConfig(); + var cacheConfig = new BuiltinBundleCache.CacheConfig(); cacheConfig.AssetBundleDecryptor = AssetBundleDecryptor; cacheConfig.RawBundleDecryptor = RawBundleDecryptor; cacheConfig.DownloadBackend = DownloadBackend; - BuiltinFileCache = new BuiltinFileCache(packageName, _packageRoot, cacheConfig); + BuiltinBundleCache = new BuiltinBundleCache(packageName, _packageRoot, cacheConfig); } // 创建沙盒文件缓存系统 { - var cacheConfig = new SandboxFileCache.CacheConfig(); + var cacheConfig = new SandboxBundleCache.CacheConfig(); cacheConfig.FileVerifyMaxConcurrency = FileVerifyMaxConcurrency; cacheConfig.FileVerifyLevel = FileVerifyLevel; cacheConfig.AssetBundleDecryptor = AssetBundleDecryptor; cacheConfig.RawBundleDecryptor = RawBundleDecryptor; cacheConfig.AssetBundleFallbackDecryptor = AssetBundleFallbackDecryptor; - UnpackFileCache = new SandboxFileCache(packageName, _unpackBundleFilesRoot, cacheConfig); + UnpackBundleCache = new SandboxBundleCache(packageName, _unpackBundleFilesRoot, cacheConfig); } } public virtual void OnDestroy() { - if (BuiltinFileCache != null) + if (BuiltinBundleCache != null) { - BuiltinFileCache.Dispose(); - BuiltinFileCache = null; + BuiltinBundleCache.Dispose(); + BuiltinBundleCache = null; } - if (UnpackFileCache != null) + if (UnpackBundleCache != null) { - UnpackFileCache.Dispose(); - UnpackFileCache = null; + UnpackBundleCache.Dispose(); + UnpackBundleCache = null; } if (UnpackScheduler != null) @@ -313,7 +313,7 @@ namespace YooAsset public virtual bool Belong(PackageBundle bundle) { - return BuiltinFileCache.IsCached(bundle.BundleGUID); + return BuiltinBundleCache.IsCached(bundle.BundleGUID); } public virtual bool NeedDownload(PackageBundle bundle) { @@ -323,7 +323,7 @@ namespace YooAsset { if (IsUnpackBundleFile(bundle)) { - return UnpackFileCache.IsCached(bundle.BundleGUID) == false; + return UnpackBundleCache.IsCached(bundle.BundleGUID) == false; } else { diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/BFSClearCacheOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/BFSClearCacheOperation.cs index d4ebe6a5..a453b043 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/BFSClearCacheOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/BFSClearCacheOperation.cs @@ -9,13 +9,14 @@ namespace YooAsset private enum ESteps { None, + CheckReadOnly, ClearCache, Done, } private readonly BuiltinFileSystem _fileSystem; private readonly FSClearCacheOptions _options; - private FCClearCacheOperation _clearCacheOp; + private BCClearCacheOperation _clearCacheOp; private ESteps _steps = ESteps.None; internal BFSClearCacheOperation(BuiltinFileSystem fileSystem, FSClearCacheOptions options) @@ -25,18 +26,30 @@ namespace YooAsset } internal override void InternalStart() { - _steps = ESteps.ClearCache; + _steps = ESteps.CheckReadOnly; } internal override void InternalUpdate() { if (_steps == ESteps.None || _steps == ESteps.Done) return; + if (_steps == ESteps.CheckReadOnly) + { + if (_fileSystem.UnpackBundleCache.IsReadOnly) + { + _steps = ESteps.Done; + Status = EOperationStatus.Succeeded; + return; + } + + _steps = ESteps.ClearCache; + } + if (_steps == ESteps.ClearCache) { if (_clearCacheOp == null) { - _clearCacheOp = _fileSystem.UnpackFileCache.ClearCacheAsync(_options.ConvertTo()); + _clearCacheOp = _fileSystem.UnpackBundleCache.ClearCacheAsync(_options.ConvertTo()); _clearCacheOp.StartOperation(); AddChildOperation(_clearCacheOp); } diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/BFSDownloadFileOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/BFSDownloadFileOperation.cs index 2614e771..8a65f023 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/BFSDownloadFileOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/BFSDownloadFileOperation.cs @@ -37,7 +37,7 @@ namespace YooAsset // 检测文件是否存在 if (_steps == ESteps.CheckExists) { - if (_fileSystem.UnpackFileCache.IsCached(Bundle.BundleGUID)) + if (_fileSystem.UnpackBundleCache.IsCached(Bundle.BundleGUID)) { _steps = ESteps.Done; Status = EOperationStatus.Succeeded; @@ -51,12 +51,12 @@ namespace YooAsset // 创建解压器 if (_steps == ESteps.CreateUnpack) { - _downloadFileOp = _fileSystem.UnpackScheduler.TryGetDownloadFile(Bundle); + _downloadFileOp = _fileSystem.UnpackScheduler.TryAcquireDownloadOperation(Bundle); if (_downloadFileOp == null) { string builtinFilePath = _fileSystem.GetBuiltinBundleFilePath(Bundle); _downloadFileOp = new UnpackAndCacheFileOperation(_fileSystem, Bundle, builtinFilePath); - _fileSystem.UnpackScheduler.AddDownloadFile(_downloadFileOp); + _fileSystem.UnpackScheduler.RegisterDownloadOperation(_downloadFileOp); } _steps = ESteps.CheckUnpack; @@ -70,7 +70,7 @@ namespace YooAsset _downloadFileOp.UpdateOperation(); Progress = _downloadFileOp.Progress; - Report = _downloadFileOp.Report; + Report = _downloadFileOp.LatestReport; if (_downloadFileOp.IsDone == false) return; diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/BFSInitializeOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/BFSInitializeOperation.cs index a50f3af2..778a7820 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/BFSInitializeOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/BFSInitializeOperation.cs @@ -12,15 +12,15 @@ namespace YooAsset CheckPlatform, CheckAppFootprint, CopyPackageManifest, - InitializeBuiltinFileCache, - InitializeUnpackFileCache, + InitializeBuiltinBundleCache, + InitializeUnpackBundleCache, CreateScheduler, Done, } private readonly BuiltinFileSystem _fileSystem; - private FCInitializeOperation _initializeBuiltinFileCacheOp; - private FCInitializeOperation _initializeUnpackFileCacheOp; + private BCInitializeOperation _initializeBuiltinBundleCacheOp; + private BCInitializeOperation _initializeUnpackBundleCacheOp; private CopyBuiltinPackageManifestOperation _copyBuiltinPackageManifestOp; private ESteps _steps = ESteps.None; @@ -106,7 +106,7 @@ namespace YooAsset if (_copyBuiltinPackageManifestOp.Status == EOperationStatus.Succeeded) { - _steps = ESteps.InitializeBuiltinFileCache; + _steps = ESteps.InitializeBuiltinBundleCache; } else { @@ -117,51 +117,51 @@ namespace YooAsset } else { - _steps = ESteps.InitializeBuiltinFileCache; + _steps = ESteps.InitializeBuiltinBundleCache; } } - if (_steps == ESteps.InitializeBuiltinFileCache) + if (_steps == ESteps.InitializeBuiltinBundleCache) { - if (_initializeBuiltinFileCacheOp == null) + if (_initializeBuiltinBundleCacheOp == null) { - _initializeBuiltinFileCacheOp = _fileSystem.BuiltinFileCache.InitializeAsync(); - _initializeBuiltinFileCacheOp.StartOperation(); - AddChildOperation(_initializeBuiltinFileCacheOp); + _initializeBuiltinBundleCacheOp = _fileSystem.BuiltinBundleCache.InitializeAsync(); + _initializeBuiltinBundleCacheOp.StartOperation(); + AddChildOperation(_initializeBuiltinBundleCacheOp); } - _initializeBuiltinFileCacheOp.UpdateOperation(); - Progress = _initializeBuiltinFileCacheOp.Progress; - if (_initializeBuiltinFileCacheOp.IsDone == false) + _initializeBuiltinBundleCacheOp.UpdateOperation(); + Progress = _initializeBuiltinBundleCacheOp.Progress; + if (_initializeBuiltinBundleCacheOp.IsDone == false) return; - if (_initializeBuiltinFileCacheOp.Status == EOperationStatus.Succeeded) + if (_initializeBuiltinBundleCacheOp.Status == EOperationStatus.Succeeded) { - _steps = ESteps.InitializeUnpackFileCache; + _steps = ESteps.InitializeUnpackBundleCache; } else { _steps = ESteps.Done; Status = EOperationStatus.Failed; - Error = _initializeBuiltinFileCacheOp.Error; + Error = _initializeBuiltinBundleCacheOp.Error; } } - if (_steps == ESteps.InitializeUnpackFileCache) + if (_steps == ESteps.InitializeUnpackBundleCache) { - if (_initializeUnpackFileCacheOp == null) + if (_initializeUnpackBundleCacheOp == null) { - _initializeUnpackFileCacheOp = _fileSystem.UnpackFileCache.InitializeAsync(); - _initializeUnpackFileCacheOp.StartOperation(); - AddChildOperation(_initializeUnpackFileCacheOp); + _initializeUnpackBundleCacheOp = _fileSystem.UnpackBundleCache.InitializeAsync(); + _initializeUnpackBundleCacheOp.StartOperation(); + AddChildOperation(_initializeUnpackBundleCacheOp); } - _initializeUnpackFileCacheOp.UpdateOperation(); - Progress = _initializeUnpackFileCacheOp.Progress; - if (_initializeUnpackFileCacheOp.IsDone == false) + _initializeUnpackBundleCacheOp.UpdateOperation(); + Progress = _initializeUnpackBundleCacheOp.Progress; + if (_initializeUnpackBundleCacheOp.IsDone == false) return; - if (_initializeUnpackFileCacheOp.Status == EOperationStatus.Succeeded) + if (_initializeUnpackBundleCacheOp.Status == EOperationStatus.Succeeded) { _steps = ESteps.CreateScheduler; } @@ -169,7 +169,7 @@ namespace YooAsset { _steps = ESteps.Done; Status = EOperationStatus.Failed; - Error = _initializeUnpackFileCacheOp.Error; + Error = _initializeUnpackBundleCacheOp.Error; } } diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/BFSLoadPackageBundleOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/BFSLoadPackageBundleOperation.cs index 1700d560..11688875 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/BFSLoadPackageBundleOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/BFSLoadPackageBundleOperation.cs @@ -21,7 +21,7 @@ namespace YooAsset private readonly BuiltinFileSystem _fileSystem; private readonly FSLoadPackageBundleOptions _options; private FSDownloadFileOperation _unpackFileOp; - private FCLoadBundleOperation _loadBundleOp; + private BCLoadBundleOperation _loadBundleOp; private ESteps _steps = ESteps.None; internal BFSLoadPackageBundleOperation(BuiltinFileSystem fileSystem, FSLoadPackageBundleOptions options) @@ -42,7 +42,7 @@ namespace YooAsset { if (_fileSystem.IsUnpackBundleFile(_options.Bundle)) { - if (_fileSystem.UnpackFileCache.IsCached(_options.Bundle.BundleGUID)) + if (_fileSystem.UnpackBundleCache.IsCached(_options.Bundle.BundleGUID)) _steps = ESteps.LoadUnpackBundle; else _steps = ESteps.UnpackFile; @@ -113,7 +113,7 @@ namespace YooAsset if (_steps == ESteps.LoadUnpackBundle) { - _loadBundleOp = _fileSystem.UnpackFileCache.LoadBundleAsync(_options.ConvertTo()); + _loadBundleOp = _fileSystem.UnpackBundleCache.LoadBundleAsync(_options.ConvertTo()); _loadBundleOp.StartOperation(); AddChildOperation(_loadBundleOp); _steps = ESteps.CheckResult; @@ -121,7 +121,7 @@ namespace YooAsset if (_steps == ESteps.LoadBundle) { - _loadBundleOp = _fileSystem.BuiltinFileCache.LoadBundleAsync(_options.ConvertTo()); + _loadBundleOp = _fileSystem.BuiltinBundleCache.LoadBundleAsync(_options.ConvertTo()); _loadBundleOp.StartOperation(); AddChildOperation(_loadBundleOp); _steps = ESteps.CheckResult; 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 165aca10..e97c6514 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/internal/CopyBuiltinFileOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/internal/CopyBuiltinFileOperation.cs @@ -81,7 +81,7 @@ namespace YooAsset if (_downloadFileRequest == null) { //TODO 团结引擎,在某些安卓机型(红米),通过UnityWebRequest拷贝包内文件会小概率失败!需要借助其它方式来拷贝包内文件。 - string url = DownloadSystemTools.ToLocalUrl(_sourceFilePath); + string url = DownloadSystemTools.ToLocalFileUrl(_sourceFilePath); var args = new DownloadFileRequestArgs(url, _destFilePath, 60, 0); _downloadFileRequest = _fileSystem.DownloadBackend.CreateFileRequest(args); _downloadFileRequest.SendRequest(); 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 d5e01e3f..fa67b574 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/internal/LoadBuiltinPackageManifestOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/internal/LoadBuiltinPackageManifestOperation.cs @@ -65,7 +65,7 @@ namespace YooAsset if (_downloadBytesRequest == null) { string filePath = _fileSystem.GetBuiltinPackageManifestFilePath(_packageVersion); - string url = DownloadSystemTools.ToLocalUrl(filePath); + string url = DownloadSystemTools.ToLocalFileUrl(filePath); var args = new DownloadDataRequestArgs(url, 60, 0); _downloadBytesRequest = _fileSystem.DownloadBackend.CreateBytesRequest(args); _downloadBytesRequest.SendRequest(); 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 7a383ceb..50a0ae7c 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/internal/RequestBuiltinPackageHashOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/internal/RequestBuiltinPackageHashOperation.cs @@ -60,7 +60,7 @@ namespace YooAsset if (_downloadTextRequest == null) { string filePath = _fileSystem.GetBuiltinPackageHashFilePath(_packageVersion); - string url = DownloadSystemTools.ToLocalUrl(filePath); + string url = DownloadSystemTools.ToLocalFileUrl(filePath); var args = new DownloadDataRequestArgs(url, 60, 0); _downloadTextRequest = _fileSystem.DownloadBackend.CreateTextRequest(args); _downloadTextRequest.SendRequest(); 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 b4069837..88b580e8 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/internal/RequestBuiltinPackageVersionOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/internal/RequestBuiltinPackageVersionOperation.cs @@ -58,7 +58,7 @@ namespace YooAsset if (_downloadTextRequest == null) { string filePath = _fileSystem.GetBuiltinPackageVersionFilePath(); - string url = DownloadSystemTools.ToLocalUrl(filePath); + string url = DownloadSystemTools.ToLocalFileUrl(filePath); var args = new DownloadDataRequestArgs(url, 60, 0); _downloadTextRequest = _fileSystem.DownloadBackend.CreateTextRequest(args); _downloadTextRequest.SendRequest(); 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 6d2fa64d..8ce934c0 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/internal/UnpackAndCacheFileOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/internal/UnpackAndCacheFileOperation.cs @@ -22,7 +22,7 @@ namespace YooAsset private readonly string _builtinFilePath; private readonly string _tempFilePath; private CopyBuiltinFileOperation _copyBuiltinFileOp; - private FCWriteCacheOperation _writeCacheOp; + private BCWriteCacheOperation _writeCacheOp; private ESteps _steps = ESteps.None; internal UnpackAndCacheFileOperation(BuiltinFileSystem fileSystem, PackageBundle bundle, string builtinFilePath) : base(bundle, builtinFilePath) @@ -69,8 +69,8 @@ namespace YooAsset return; // 更新下载报告 - Report.DownloadedBytes = Bundle.FileSize; - Report.DownloadProgress = 1f; + LatestReport.DownloadedBytes = Bundle.FileSize; + LatestReport.DownloadProgress = 1f; if (_copyBuiltinFileOp.Status == EOperationStatus.Succeeded) { @@ -89,10 +89,10 @@ namespace YooAsset { if (_writeCacheOp == null) { - var options = new FCWriteCacheOptions(); + var options = new BCWriteCacheOptions(); options.Bundle = Bundle; options.FilePath = _tempFilePath; - _writeCacheOp = _fileSystem.UnpackFileCache.WriteCacheAsync(options); + _writeCacheOp = _fileSystem.UnpackBundleCache.WriteCacheAsync(options); _writeCacheOp.StartOperation(); AddChildOperation(_writeCacheOp); } diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/EditorFileSystem.cs b/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/EditorFileSystem.cs index 3e4e1dde..f03a7581 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/EditorFileSystem.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/EditorFileSystem.cs @@ -13,7 +13,7 @@ namespace YooAsset /// /// 虚拟文件缓存系统 /// - public IFileCache FileCache { get; private set; } + public IBundleCache BundleCache { get; private set; } /// /// 下载调度器 @@ -199,19 +199,19 @@ namespace YooAsset // 创建编辑器文件缓存系统 if (AsyncSimulateMinFrame > AsyncSimulateMaxFrame) AsyncSimulateMinFrame = AsyncSimulateMaxFrame; - var cacheConfig = new EditorFileCache.CacheConfig(); + var cacheConfig = new EditorBundleCache.CacheConfig(); cacheConfig.VirtualDownloadMode = VirtualDownloadMode; cacheConfig.VirtualWebGLMode = VirtualWebGLMode; cacheConfig.AsyncSimulateMinFrame = AsyncSimulateMinFrame; cacheConfig.AsyncSimulateMaxFrame = AsyncSimulateMaxFrame; - FileCache = new EditorFileCache(packageName, _packageRoot, cacheConfig); + BundleCache = new EditorBundleCache(packageName, _packageRoot, cacheConfig); } public virtual void OnDestroy() { - if (FileCache != null) + if (BundleCache != null) { - FileCache.Dispose(); - FileCache = null; + BundleCache.Dispose(); + BundleCache = null; } if (DownloadScheduler != null) @@ -236,7 +236,7 @@ namespace YooAsset if (Belong(bundle) == false) return false; - return FileCache.IsCached(bundle.BundleGUID) == false; + return BundleCache.IsCached(bundle.BundleGUID) == false; } public virtual bool NeedUnpack(PackageBundle bundle) { diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/Operations/EFSClearCacheOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/Operations/EFSClearCacheOperation.cs index 9e6c7f4a..aa5c41f7 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/Operations/EFSClearCacheOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/Operations/EFSClearCacheOperation.cs @@ -9,13 +9,14 @@ namespace YooAsset private enum ESteps { None, + CheckReadOnly, ClearCache, Done, } private readonly EditorFileSystem _fileSystem; private readonly FSClearCacheOptions _options; - private FCClearCacheOperation _clearCacheOp; + private BCClearCacheOperation _clearCacheOp; private ESteps _steps = ESteps.None; internal EFSClearCacheOperation(EditorFileSystem fileSystem, FSClearCacheOptions options) @@ -25,18 +26,30 @@ namespace YooAsset } internal override void InternalStart() { - _steps = ESteps.ClearCache; + _steps = ESteps.CheckReadOnly; } internal override void InternalUpdate() { if (_steps == ESteps.None || _steps == ESteps.Done) return; + if (_steps == ESteps.CheckReadOnly) + { + if (_fileSystem.BundleCache.IsReadOnly) + { + _steps = ESteps.Done; + Status = EOperationStatus.Succeeded; + return; + } + + _steps = ESteps.ClearCache; + } + if (_steps == ESteps.ClearCache) { if (_clearCacheOp == null) { - _clearCacheOp = _fileSystem.FileCache.ClearCacheAsync(_options.ConvertTo()); + _clearCacheOp = _fileSystem.BundleCache.ClearCacheAsync(_options.ConvertTo()); _clearCacheOp.StartOperation(); AddChildOperation(_clearCacheOp); } diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/Operations/EFSDownloadFileOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/Operations/EFSDownloadFileOperation.cs index 9c9a3a58..c7272633 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/Operations/EFSDownloadFileOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/Operations/EFSDownloadFileOperation.cs @@ -37,7 +37,7 @@ namespace YooAsset // 检测文件是否存在 if (_steps == ESteps.CheckExists) { - if (_fileSystem.FileCache.IsCached(_options.Bundle.BundleGUID)) + if (_fileSystem.BundleCache.IsCached(_options.Bundle.BundleGUID)) { _steps = ESteps.Done; Status = EOperationStatus.Succeeded; @@ -51,12 +51,12 @@ namespace YooAsset // 创建下载器 if (_steps == ESteps.CreateDownload) { - _downloadFileOp = _fileSystem.DownloadScheduler.TryGetDownloadFile(Bundle); + _downloadFileOp = _fileSystem.DownloadScheduler.TryAcquireDownloadOperation(Bundle); if (_downloadFileOp == null) { string editorFilePath = EditorFileSystemTools.GetEditorFilePath(Bundle); _downloadFileOp = new SimulateAndCacheFileOperation(_fileSystem, Bundle, editorFilePath); - _fileSystem.DownloadScheduler.AddDownloadFile(_downloadFileOp); + _fileSystem.DownloadScheduler.RegisterDownloadOperation(_downloadFileOp); } _steps = ESteps.CheckDownload; @@ -70,7 +70,7 @@ namespace YooAsset _downloadFileOp.UpdateOperation(); Progress = _downloadFileOp.Progress; - Report = _downloadFileOp.Report; + Report = _downloadFileOp.LatestReport; if (_downloadFileOp.IsDone == false) return; diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/Operations/EFSInitializeOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/Operations/EFSInitializeOperation.cs index 7e95701e..88341ffb 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/Operations/EFSInitializeOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/Operations/EFSInitializeOperation.cs @@ -10,13 +10,13 @@ namespace YooAsset { None, CheckPlatform, - InitializeFileCache, + InitializeBundleCache, CreateScheduler, Done, } private readonly EditorFileSystem _fileSystem; - private FCInitializeOperation _initializeFileCacheOp; + private BCInitializeOperation _initializeBundleCacheOp; private ESteps _steps = ESteps.None; internal EFSInitializeOperation(EditorFileSystem fileSystem) @@ -39,25 +39,25 @@ namespace YooAsset Status = EOperationStatus.Failed; Error = $"{nameof(EditorFileSystem)} only support the Unity Editor."; #else - _steps = ESteps.InitializeFileCache; + _steps = ESteps.InitializeBundleCache; #endif } - if (_steps == ESteps.InitializeFileCache) + if (_steps == ESteps.InitializeBundleCache) { - if (_initializeFileCacheOp == null) + if (_initializeBundleCacheOp == null) { - _initializeFileCacheOp = _fileSystem.FileCache.InitializeAsync(); - _initializeFileCacheOp.StartOperation(); - AddChildOperation(_initializeFileCacheOp); + _initializeBundleCacheOp = _fileSystem.BundleCache.InitializeAsync(); + _initializeBundleCacheOp.StartOperation(); + AddChildOperation(_initializeBundleCacheOp); } - _initializeFileCacheOp.UpdateOperation(); - Progress = _initializeFileCacheOp.Progress; - if (_initializeFileCacheOp.IsDone == false) + _initializeBundleCacheOp.UpdateOperation(); + Progress = _initializeBundleCacheOp.Progress; + if (_initializeBundleCacheOp.IsDone == false) return; - if (_initializeFileCacheOp.Status == EOperationStatus.Succeeded) + if (_initializeBundleCacheOp.Status == EOperationStatus.Succeeded) { _steps = ESteps.CreateScheduler; } @@ -65,7 +65,7 @@ namespace YooAsset { _steps = ESteps.Done; Status = EOperationStatus.Failed; - Error = _initializeFileCacheOp.Error; + Error = _initializeBundleCacheOp.Error; } } diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/Operations/EFSLoadPackageBundleOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/Operations/EFSLoadPackageBundleOperation.cs index c5fe0a2e..aa4e2d96 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/Operations/EFSLoadPackageBundleOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/Operations/EFSLoadPackageBundleOperation.cs @@ -20,7 +20,7 @@ namespace YooAsset private readonly EditorFileSystem _fileSystem; private readonly FSLoadPackageBundleOptions _options; private FSDownloadFileOperation _downloadFileOp; - private FCLoadBundleOperation _loadBundleOp; + private BCLoadBundleOperation _loadBundleOp; private ESteps _steps = ESteps.None; internal EFSLoadPackageBundleOperation(EditorFileSystem fileSystem, FSLoadPackageBundleOptions options) @@ -39,7 +39,7 @@ namespace YooAsset if (_steps == ESteps.Prepare) { - if (_fileSystem.FileCache.IsCached(_options.Bundle.BundleGUID)) + if (_fileSystem.BundleCache.IsCached(_options.Bundle.BundleGUID)) _steps = ESteps.LoadBundle; else _steps = ESteps.DownloadFile; @@ -105,7 +105,7 @@ namespace YooAsset if (_steps == ESteps.LoadBundle) { - _loadBundleOp = _fileSystem.FileCache.LoadBundleAsync(_options.ConvertTo()); + _loadBundleOp = _fileSystem.BundleCache.LoadBundleAsync(_options.ConvertTo()); _loadBundleOp.StartOperation(); AddChildOperation(_loadBundleOp); _steps = ESteps.CheckResult; 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 49a6ce3a..d712178d 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/Operations/internal/SimulateAndCacheFileOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/Operations/internal/SimulateAndCacheFileOperation.cs @@ -17,7 +17,7 @@ namespace YooAsset protected readonly EditorFileSystem _fileSystem; protected IDownloadRequest _downloadRequest; - private FCWriteCacheOperation _writeCacheOp; + private BCWriteCacheOperation _writeCacheOp; private ESteps _steps = ESteps.None; internal SimulateAndCacheFileOperation(EditorFileSystem fileSystem, PackageBundle bundle, string filePath) : base(bundle, filePath) @@ -46,17 +46,17 @@ namespace YooAsset // 检测下载结果 if (_steps == ESteps.CheckRequest) { - Report.DownloadedBytes = _downloadRequest.DownloadedBytes; - Report.DownloadProgress = _downloadRequest.DownloadProgress; + LatestReport.DownloadedBytes = _downloadRequest.DownloadedBytes; + LatestReport.DownloadProgress = _downloadRequest.DownloadProgress; Progress = _downloadRequest.DownloadProgress; if (_downloadRequest.IsDone == false) return; // 更新下载报告 - Report.DownloadedBytes = _downloadRequest.DownloadedBytes; - Report.DownloadProgress = _downloadRequest.DownloadProgress; - Report.HttpCode = _downloadRequest.HttpCode; - Report.HttpError = _downloadRequest.HttpError; + LatestReport.DownloadedBytes = _downloadRequest.DownloadedBytes; + LatestReport.DownloadProgress = _downloadRequest.DownloadProgress; + LatestReport.HttpCode = _downloadRequest.HttpCode; + LatestReport.HttpError = _downloadRequest.HttpError; // 检查网络错误 if (_downloadRequest.Status == EDownloadRequestStatus.Succeeded) @@ -76,10 +76,10 @@ namespace YooAsset { if (_writeCacheOp == null) { - var options = new FCWriteCacheOptions(); + var options = new BCWriteCacheOptions(); options.Bundle = Bundle; options.FilePath = Url; - _writeCacheOp = _fileSystem.FileCache.WriteCacheAsync(options); + _writeCacheOp = _fileSystem.BundleCache.WriteCacheAsync(options); _writeCacheOp.StartOperation(); AddChildOperation(_writeCacheOp); } 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 d2daa285..d72e3919 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/DownloadAndCacheFileOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/DownloadAndCacheFileOperation.cs @@ -19,7 +19,7 @@ namespace YooAsset private readonly SandboxFileSystem _fileSystem; private readonly string _tempFilePath; private IDownloadFileRequest _downloadFileRequest; - private FCWriteCacheOperation _writeCacheOp; + private BCWriteCacheOperation _writeCacheOp; private bool _enableResume; private long _fileOriginLength = 0; private ESteps _steps = ESteps.None; @@ -63,22 +63,22 @@ namespace YooAsset bool isDone = _downloadFileRequest.IsDone; if (_enableResume) { - Report.DownloadedBytes = _fileOriginLength + _downloadFileRequest.DownloadedBytes; - Report.DownloadProgress = (float)((double)Report.DownloadedBytes / Bundle.FileSize); - Progress = Report.DownloadProgress; + LatestReport.DownloadedBytes = _fileOriginLength + _downloadFileRequest.DownloadedBytes; + LatestReport.DownloadProgress = (float)((double)LatestReport.DownloadedBytes / Bundle.FileSize); + Progress = LatestReport.DownloadProgress; } else { - Report.DownloadedBytes = _downloadFileRequest.DownloadedBytes; - Report.DownloadProgress = _downloadFileRequest.DownloadProgress; - Progress = Report.DownloadProgress; + LatestReport.DownloadedBytes = _downloadFileRequest.DownloadedBytes; + LatestReport.DownloadProgress = _downloadFileRequest.DownloadProgress; + Progress = LatestReport.DownloadProgress; } if (isDone == false) return; // 更新下载报告 - Report.HttpCode = _downloadFileRequest.HttpCode; - Report.HttpError = _downloadFileRequest.HttpError; + LatestReport.HttpCode = _downloadFileRequest.HttpCode; + LatestReport.HttpError = _downloadFileRequest.HttpError; // 检查网络错误 if (_downloadFileRequest.Status == EDownloadRequestStatus.Succeeded) @@ -109,10 +109,10 @@ namespace YooAsset { if (_writeCacheOp == null) { - var options = new FCWriteCacheOptions(); + var options = new BCWriteCacheOptions(); options.Bundle = Bundle; options.FilePath = _tempFilePath; - _writeCacheOp = _fileSystem.FileCache.WriteCacheAsync(options); + _writeCacheOp = _fileSystem.BundleCache.WriteCacheAsync(options); _writeCacheOp.StartOperation(); AddChildOperation(_writeCacheOp); } 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 be24ece7..cc37fc96 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/DownloadPackageHashOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/DownloadPackageHashOperation.cs @@ -83,7 +83,7 @@ namespace YooAsset _steps = ESteps.Done; Status = EOperationStatus.Failed; Error = _downloadFileRequest.Error; - _fileSystem.DownloadURLPolicy.OnFailure(_downloadFileRequest.Url, _downloadFileRequest.HttpCode, _downloadFileRequest.HttpError); + _fileSystem.DownloadURLPolicy.OnRequestFailed(_downloadFileRequest.Url, _downloadFileRequest.HttpCode, _downloadFileRequest.HttpError); DeleteTempFile(); } } @@ -136,7 +136,7 @@ namespace YooAsset private string GetWebRequestURL(string fileName) { var urls = _fileSystem.RemoteServices.GetRemoteURLs(fileName); - return _fileSystem.DownloadURLPolicy.SelectURL(urls); + return _fileSystem.DownloadURLPolicy.SelectUrl(urls); } } } \ No newline at end of file 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 659d3ab8..858b4ca1 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/DownloadPackageManifestOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/DownloadPackageManifestOperation.cs @@ -83,7 +83,7 @@ namespace YooAsset _steps = ESteps.Done; Status = EOperationStatus.Failed; Error = _downloadFileRequest.Error; - _fileSystem.DownloadURLPolicy.OnFailure(_downloadFileRequest.Url, _downloadFileRequest.HttpCode, _downloadFileRequest.HttpError); + _fileSystem.DownloadURLPolicy.OnRequestFailed(_downloadFileRequest.Url, _downloadFileRequest.HttpCode, _downloadFileRequest.HttpError); DeleteTempFile(); } } @@ -136,7 +136,7 @@ namespace YooAsset private string GetDownloadRequestURL(string fileName) { var urls = _fileSystem.RemoteServices.GetRemoteURLs(fileName); - return _fileSystem.DownloadURLPolicy.SelectURL(urls); + return _fileSystem.DownloadURLPolicy.SelectUrl(urls); } } } \ No newline at end of file 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 f3d8e6da..6da8147a 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/ImportAndCacheFileOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/ImportAndCacheFileOperation.cs @@ -19,7 +19,7 @@ namespace YooAsset private readonly SandboxFileSystem _fileSystem; private readonly string _sourceFilePath; private readonly string _tempFilePath; - private FCWriteCacheOperation _bundleCacheOp; + private BCWriteCacheOperation _bundleCacheOp; private ESteps _steps = ESteps.None; internal ImportAndCacheFileOperation(SandboxFileSystem fileSystem, PackageBundle bundle, string sourceFilePath) : base(bundle, sourceFilePath) @@ -56,8 +56,8 @@ namespace YooAsset File.Copy(_sourceFilePath, _tempFilePath, true); // 更新下载报告 - Report.DownloadedBytes = Bundle.FileSize; - Report.DownloadProgress = 1f; + LatestReport.DownloadedBytes = Bundle.FileSize; + LatestReport.DownloadProgress = 1f; _steps = ESteps.CacheFile; } catch (System.Exception ex) @@ -73,10 +73,10 @@ namespace YooAsset { if (_bundleCacheOp == null) { - var options = new FCWriteCacheOptions(); + var options = new BCWriteCacheOptions(); options.Bundle = Bundle; options.FilePath = _tempFilePath; - _bundleCacheOp = _fileSystem.FileCache.WriteCacheAsync(options); + _bundleCacheOp = _fileSystem.BundleCache.WriteCacheAsync(options); _bundleCacheOp.StartOperation(); AddChildOperation(_bundleCacheOp); } 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 5bdd85a7..a5f591b3 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/RequestRemotePackageVersionOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/RequestRemotePackageVersionOperation.cs @@ -76,7 +76,7 @@ namespace YooAsset _steps = ESteps.Done; Status = EOperationStatus.Failed; Error = _downloadTextRequest.Error; - _fileSystem.DownloadURLPolicy.OnFailure(_downloadTextRequest.Url, _downloadTextRequest.HttpCode, _downloadTextRequest.HttpError); + _fileSystem.DownloadURLPolicy.OnRequestFailed(_downloadTextRequest.Url, _downloadTextRequest.HttpCode, _downloadTextRequest.HttpError); } } } @@ -92,7 +92,7 @@ namespace YooAsset private string GetWebRequestURL(string fileName) { var urls = _fileSystem.RemoteServices.GetRemoteURLs(fileName); - string url = _fileSystem.DownloadURLPolicy.SelectURL(urls); + string url = _fileSystem.DownloadURLPolicy.SelectUrl(urls); // 在URL末尾添加时间戳 if (_appendTimeTicks) diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSClearCacheOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSClearCacheOperation.cs index 1ac6cd01..b3fbf65a 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSClearCacheOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSClearCacheOperation.cs @@ -11,13 +11,14 @@ namespace YooAsset private enum ESteps { None, + CheckReadOnly, ClearCache, Done, } private readonly SandboxFileSystem _fileSystem; private readonly FSClearCacheOptions _options; - private FCClearCacheOperation _clearCacheOp; + private BCClearCacheOperation _clearCacheOp; private ESteps _steps = ESteps.None; internal SFSClearCacheOperation(SandboxFileSystem fileSystem, FSClearCacheOptions options) @@ -27,18 +28,30 @@ namespace YooAsset } internal override void InternalStart() { - _steps = ESteps.ClearCache; + _steps = ESteps.CheckReadOnly; } internal override void InternalUpdate() { if (_steps == ESteps.None || _steps == ESteps.Done) return; + if (_steps == ESteps.CheckReadOnly) + { + if (_fileSystem.BundleCache.IsReadOnly) + { + _steps = ESteps.Done; + Status = EOperationStatus.Succeeded; + return; + } + + _steps = ESteps.ClearCache; + } + if (_steps == ESteps.ClearCache) { if (_clearCacheOp == null) { - _clearCacheOp = _fileSystem.FileCache.ClearCacheAsync(_options.ConvertTo()); + _clearCacheOp = _fileSystem.BundleCache.ClearCacheAsync(_options.ConvertTo()); _clearCacheOp.StartOperation(); AddChildOperation(_clearCacheOp); } diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSDownloadFileOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSDownloadFileOperation.cs index 00cb79b0..e77d54d4 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSDownloadFileOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSDownloadFileOperation.cs @@ -19,7 +19,7 @@ namespace YooAsset private readonly SandboxFileSystem _fileSystem; private readonly FSDownloadFileOptions _options; - private readonly DownloadRetry _downloadRetry; + private readonly DownloadRetryController _downloadRetryController; private DownloadFileBaseOperation _downloadFileOp; private ESteps _steps = ESteps.None; @@ -27,7 +27,7 @@ namespace YooAsset { _fileSystem = fileSystem; _options = options; - _downloadRetry = new DownloadRetry(options.RetryCount, _fileSystem.DownloadRetryPolicy); + _downloadRetryController = new DownloadRetryController(options.RetryCount, _fileSystem.DownloadRetryPolicy); } internal override void InternalStart() { @@ -41,7 +41,7 @@ namespace YooAsset // 检测文件是否存在 if (_steps == ESteps.CheckExists) { - if (_fileSystem.FileCache.IsCached(Bundle.BundleGUID)) + if (_fileSystem.BundleCache.IsCached(Bundle.BundleGUID)) { _steps = ESteps.Done; Status = EOperationStatus.Succeeded; @@ -55,7 +55,7 @@ namespace YooAsset // 创建下载器 if (_steps == ESteps.CreateDownload) { - _downloadFileOp = _fileSystem.DownloadScheduler.TryGetDownloadFile(Bundle); + _downloadFileOp = _fileSystem.DownloadScheduler.TryAcquireDownloadOperation(Bundle); if (_downloadFileOp == null) { if (string.IsNullOrEmpty(_options.ImportFilePath)) @@ -63,13 +63,13 @@ namespace YooAsset // 下载远端文件 string url = GetRequestURL(Bundle.FileName); _downloadFileOp = new DownloadAndCacheFileOperation(_fileSystem, Bundle, url); - _fileSystem.DownloadScheduler.AddDownloadFile(_downloadFileOp); + _fileSystem.DownloadScheduler.RegisterDownloadOperation(_downloadFileOp); } else { // 导入本地文件 _downloadFileOp = new ImportAndCacheFileOperation(_fileSystem, Bundle, _options.ImportFilePath); - _fileSystem.DownloadScheduler.AddDownloadFile(_downloadFileOp); + _fileSystem.DownloadScheduler.RegisterDownloadOperation(_downloadFileOp); } } @@ -84,25 +84,25 @@ namespace YooAsset _downloadFileOp.UpdateOperation(); Progress = _downloadFileOp.Progress; - Report = _downloadFileOp.Report; + Report = _downloadFileOp.LatestReport; if (_downloadFileOp.IsDone == false) return; if (_downloadFileOp.Status == EOperationStatus.Succeeded) { - _fileSystem.DownloadURLPolicy.OnSuccess(_downloadFileOp.Url); + _fileSystem.DownloadURLPolicy.OnRequestSucceeded(_downloadFileOp.Url); _steps = ESteps.Done; Status = EOperationStatus.Succeeded; } else { string url = _downloadFileOp.Url; - long httpCode = _downloadFileOp.Report.HttpCode; - string httpError = _downloadFileOp.Report.HttpError; - _fileSystem.DownloadURLPolicy.OnFailure(url, httpCode, httpError); - if (IsWaitForCompletion == false && _downloadRetry.CanRetry(url, httpCode, httpError)) + long httpCode = _downloadFileOp.LatestReport.HttpCode; + string httpError = _downloadFileOp.LatestReport.HttpError; + _fileSystem.DownloadURLPolicy.OnRequestFailed(url, httpCode, httpError); + if (IsWaitForCompletion == false && _downloadRetryController.CanRetryRequest(url, httpCode, httpError)) { - _downloadRetry.BeginWait(); + _downloadRetryController.StartRetryDelay(); _steps = ESteps.TryAgain; } else @@ -118,7 +118,7 @@ namespace YooAsset // 重新尝试下载 if (_steps == ESteps.TryAgain) { - if (_downloadRetry.Tick()) + if (_downloadRetryController.UpdateRetryDelay()) { Progress = 0f; Report = DownloadReport.Default; @@ -148,7 +148,7 @@ namespace YooAsset private string GetRequestURL(string fileName) { var urls = _fileSystem.RemoteServices.GetRemoteURLs(fileName); - return _fileSystem.DownloadURLPolicy.SelectURL(urls); + return _fileSystem.DownloadURLPolicy.SelectUrl(urls); } } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSInitializeOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSInitializeOperation.cs index 7070607c..d0caaabf 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSInitializeOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSInitializeOperation.cs @@ -12,13 +12,13 @@ namespace YooAsset CheckPlatform, CheckParameter, CheckAppFootprint, - InitializeFileCache, + InitializeBundleCache, CreateScheduler, Done, } private readonly SandboxFileSystem _fileSystem; - private FCInitializeOperation _initializeFileCacheOp; + private BCInitializeOperation _initializeBundleCacheOp; private ESteps _steps = ESteps.None; @@ -97,24 +97,24 @@ namespace YooAsset appFootprint.Overwrite(_fileSystem.PackageName); } - _steps = ESteps.InitializeFileCache; + _steps = ESteps.InitializeBundleCache; } - if (_steps == ESteps.InitializeFileCache) + if (_steps == ESteps.InitializeBundleCache) { - if (_initializeFileCacheOp == null) + if (_initializeBundleCacheOp == null) { - _initializeFileCacheOp = _fileSystem.FileCache.InitializeAsync(); - _initializeFileCacheOp.StartOperation(); - AddChildOperation(_initializeFileCacheOp); + _initializeBundleCacheOp = _fileSystem.BundleCache.InitializeAsync(); + _initializeBundleCacheOp.StartOperation(); + AddChildOperation(_initializeBundleCacheOp); } - _initializeFileCacheOp.UpdateOperation(); - Progress = _initializeFileCacheOp.Progress; - if (_initializeFileCacheOp.IsDone == false) + _initializeBundleCacheOp.UpdateOperation(); + Progress = _initializeBundleCacheOp.Progress; + if (_initializeBundleCacheOp.IsDone == false) return; - if (_initializeFileCacheOp.Status == EOperationStatus.Succeeded) + if (_initializeBundleCacheOp.Status == EOperationStatus.Succeeded) { _steps = ESteps.CreateScheduler; } @@ -122,7 +122,7 @@ namespace YooAsset { _steps = ESteps.Done; Status = EOperationStatus.Failed; - Error = _initializeFileCacheOp.Error; + Error = _initializeBundleCacheOp.Error; } } diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSLoadPackageBundleOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSLoadPackageBundleOperation.cs index b84ce9ae..8d805f0e 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSLoadPackageBundleOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSLoadPackageBundleOperation.cs @@ -20,7 +20,7 @@ namespace YooAsset private readonly SandboxFileSystem _fileSystem; private readonly FSLoadPackageBundleOptions _options; private FSDownloadFileOperation _downloadFileOp; - private FCLoadBundleOperation _loadBundleOp; + private BCLoadBundleOperation _loadBundleOp; private ESteps _steps = ESteps.None; internal SFSLoadPackageBundleOperation(SandboxFileSystem fileSystem, FSLoadPackageBundleOptions options) @@ -39,7 +39,7 @@ namespace YooAsset if (_steps == ESteps.Prepare) { - if (_fileSystem.FileCache.IsCached(_options.Bundle.BundleGUID)) + if (_fileSystem.BundleCache.IsCached(_options.Bundle.BundleGUID)) { _steps = ESteps.LoadBundle; } @@ -119,7 +119,7 @@ namespace YooAsset if (_steps == ESteps.LoadBundle) { - _loadBundleOp = _fileSystem.FileCache.LoadBundleAsync(_options.ConvertTo()); + _loadBundleOp = _fileSystem.BundleCache.LoadBundleAsync(_options.ConvertTo()); _loadBundleOp.StartOperation(); AddChildOperation(_loadBundleOp); _steps = ESteps.CheckResult; diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/SandboxFileSystem.cs b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/SandboxFileSystem.cs index 8ac13622..4abbe0ac 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/SandboxFileSystem.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/SandboxFileSystem.cs @@ -18,9 +18,9 @@ namespace YooAsset protected string _cacheBundleFilesRoot; /// - /// 沙盒文件缓存系统 + /// 沙盒Bundle缓存系统 /// - public IFileCache FileCache { get; private set; } + public IBundleCache BundleCache { get; private set; } /// /// 下载调度器 @@ -122,7 +122,7 @@ namespace YooAsset /// /// 自定义参数:URL 选择策略 /// - public IDownloadURLPolicy DownloadURLPolicy { get; private set; } + public IDownloadUrlPolicy DownloadURLPolicy { get; private set; } #endregion public SandboxFileSystem() @@ -262,7 +262,7 @@ namespace YooAsset } else if (name == FileSystemConsts.DOWNLOAD_URL_POLICY) { - DownloadURLPolicy = (IDownloadURLPolicy)value; + DownloadURLPolicy = (IDownloadUrlPolicy)value; } else { @@ -296,21 +296,21 @@ namespace YooAsset // 创建文件缓存系统 { - var cacheConfig = new SandboxFileCache.CacheConfig(); + var cacheConfig = new SandboxBundleCache.CacheConfig(); cacheConfig.FileVerifyMaxConcurrency = FileVerifyMaxConcurrency; cacheConfig.FileVerifyLevel = FileVerifyLevel; cacheConfig.AssetBundleDecryptor = AssetBundleDecryptor; cacheConfig.RawBundleDecryptor = RawBundleDecryptor; cacheConfig.AssetBundleFallbackDecryptor = AssetBundleFallbackDecryptor; - FileCache = new SandboxFileCache(PackageName, _cacheBundleFilesRoot, cacheConfig); + BundleCache = new SandboxBundleCache(PackageName, _cacheBundleFilesRoot, cacheConfig); } } public virtual void OnDestroy() { - if (FileCache != null) + if (BundleCache != null) { - FileCache.Dispose(); - FileCache = null; + BundleCache.Dispose(); + BundleCache = null; } if (DownloadScheduler != null) @@ -336,7 +336,7 @@ namespace YooAsset if (Belong(bundle) == false) return false; - return FileCache.IsCached(bundle.BundleGUID) == false; + return BundleCache.IsCached(bundle.BundleGUID) == false; } public virtual bool NeedUnpack(PackageBundle bundle) { @@ -347,7 +347,7 @@ namespace YooAsset if (Belong(bundle) == false) return false; - return FileCache.IsCached(bundle.BundleGUID) == false; + return BundleCache.IsCached(bundle.BundleGUID) == false; } #region 内部方法 diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/WRFSInitializeOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/WRFSInitializeOperation.cs index 2cf0ede2..89e1dc97 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/WRFSInitializeOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/WRFSInitializeOperation.cs @@ -11,12 +11,12 @@ namespace YooAsset None, CheckPlatform, CheckParameter, - InitializeFileCache, + InitializeBundleCache, Done, } private readonly WebRemoteFileSystem _fileSystem; - private FCInitializeOperation _initializeFileCacheOp; + private BCInitializeOperation _initializeBundleCacheOp; private ESteps _steps = ESteps.None; public WRFSInitializeOperation(WebRemoteFileSystem fileSystem) @@ -53,24 +53,24 @@ namespace YooAsset return; } - _steps = ESteps.InitializeFileCache; + _steps = ESteps.InitializeBundleCache; } - if (_steps == ESteps.InitializeFileCache) + if (_steps == ESteps.InitializeBundleCache) { - if (_initializeFileCacheOp == null) + if (_initializeBundleCacheOp == null) { - _initializeFileCacheOp = _fileSystem.FileCache.InitializeAsync(); - _initializeFileCacheOp.StartOperation(); - AddChildOperation(_initializeFileCacheOp); + _initializeBundleCacheOp = _fileSystem.BundleCache.InitializeAsync(); + _initializeBundleCacheOp.StartOperation(); + AddChildOperation(_initializeBundleCacheOp); } - _initializeFileCacheOp.UpdateOperation(); - Progress = _initializeFileCacheOp.Progress; - if (_initializeFileCacheOp.IsDone == false) + _initializeBundleCacheOp.UpdateOperation(); + Progress = _initializeBundleCacheOp.Progress; + if (_initializeBundleCacheOp.IsDone == false) return; - if (_initializeFileCacheOp.Status == EOperationStatus.Succeeded) + if (_initializeBundleCacheOp.Status == EOperationStatus.Succeeded) { _steps = ESteps.Done; Status = EOperationStatus.Succeeded; @@ -79,7 +79,7 @@ namespace YooAsset { _steps = ESteps.Done; Status = EOperationStatus.Failed; - Error = _initializeFileCacheOp.Error; + Error = _initializeBundleCacheOp.Error; } } } diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/WRFSLoadPackageBundleOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/WRFSLoadPackageBundleOperation.cs index dc17c99b..60a29b16 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/WRFSLoadPackageBundleOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/WRFSLoadPackageBundleOperation.cs @@ -15,7 +15,7 @@ namespace YooAsset private readonly WebRemoteFileSystem _fileSystem; private readonly FSLoadPackageBundleOptions _options; - private FCLoadBundleOperation _loadBundleOp; + private BCLoadBundleOperation _loadBundleOp; private ESteps _steps = ESteps.None; internal WRFSLoadPackageBundleOperation(WebRemoteFileSystem fileSystem, FSLoadPackageBundleOptions options) @@ -36,7 +36,7 @@ namespace YooAsset { if (_loadBundleOp == null) { - _loadBundleOp = _fileSystem.FileCache.LoadBundleAsync(_options.ConvertTo()); + _loadBundleOp = _fileSystem.BundleCache.LoadBundleAsync(_options.ConvertTo()); _loadBundleOp.StartOperation(); AddChildOperation(_loadBundleOp); } diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/WebRemoteFileSystem.cs b/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/WebRemoteFileSystem.cs index 146d4584..2b70b587 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/WebRemoteFileSystem.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/WebRemoteFileSystem.cs @@ -12,7 +12,7 @@ namespace YooAsset /// /// Web文件缓存系统 /// - public IFileCache FileCache { get; private set; } + public IBundleCache BundleCache { get; private set; } /// /// 下载后台接口 @@ -68,7 +68,7 @@ namespace YooAsset /// /// 自定义参数:URL 选择策略 /// - public IDownloadURLPolicy DownloadURLPolicy { get; private set; } + public IDownloadUrlPolicy DownloadURLPolicy { get; private set; } #endregion @@ -146,7 +146,7 @@ namespace YooAsset } else if (name == FileSystemConsts.DOWNLOAD_URL_POLICY) { - DownloadURLPolicy = (IDownloadURLPolicy)value; + DownloadURLPolicy = (IDownloadUrlPolicy)value; } else { @@ -170,7 +170,7 @@ namespace YooAsset DownloadURLPolicy = new DefaultDownloadURLPolicy(); // 创建Web文件缓存系统 - var cacheConfig = new WebRemoteFileCache.CacheConfig(); + var cacheConfig = new WebRemoteBundleCache.CacheConfig(); cacheConfig.WatchdogTimeout = DownloadWatchdogTimeout; cacheConfig.DisableUnityWebCache = DisableUnityWebCache; cacheConfig.DownloadVerifyLevel = DownloadVerifyLevel; @@ -179,14 +179,14 @@ namespace YooAsset cacheConfig.DownloadBackend = DownloadBackend; cacheConfig.RetryPolicy = DownloadRetryPolicy; cacheConfig.URLPolicy = DownloadURLPolicy; - FileCache = new WebRemoteFileCache(packageName, packageRoot, cacheConfig); + BundleCache = new WebRemoteBundleCache(packageName, packageRoot, cacheConfig); } public virtual void OnDestroy() { - if (FileCache != null) + if (BundleCache != null) { - FileCache.Dispose(); - FileCache = null; + BundleCache.Dispose(); + BundleCache = null; } if (DownloadBackend != null) diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/Operations/WSFSInitializeOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/Operations/WSFSInitializeOperation.cs index f0edebff..02bd7993 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/Operations/WSFSInitializeOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/Operations/WSFSInitializeOperation.cs @@ -10,12 +10,12 @@ namespace YooAsset { None, CheckPlatform, - InitializeFileCache, + InitializeBundleCache, Done, } private readonly WebServerFileSystem _fileSystem; - private FCInitializeOperation _initializeFileCacheOp; + private BCInitializeOperation _initializeBundleCacheOp; private ESteps _steps = ESteps.None; public WSFSInitializeOperation(WebServerFileSystem fileSystem) @@ -38,25 +38,25 @@ namespace YooAsset Status = EOperationStatus.Failed; Error = $"{nameof(WebServerFileSystem)} only support the WebGL platform."; #else - _steps = ESteps.InitializeFileCache; + _steps = ESteps.InitializeBundleCache; #endif } - if (_steps == ESteps.InitializeFileCache) + if (_steps == ESteps.InitializeBundleCache) { - if (_initializeFileCacheOp == null) + if (_initializeBundleCacheOp == null) { - _initializeFileCacheOp = _fileSystem.FileCache.InitializeAsync(); - _initializeFileCacheOp.StartOperation(); - AddChildOperation(_initializeFileCacheOp); + _initializeBundleCacheOp = _fileSystem.BundleCache.InitializeAsync(); + _initializeBundleCacheOp.StartOperation(); + AddChildOperation(_initializeBundleCacheOp); } - _initializeFileCacheOp.UpdateOperation(); - Progress = _initializeFileCacheOp.Progress; - if (_initializeFileCacheOp.IsDone == false) + _initializeBundleCacheOp.UpdateOperation(); + Progress = _initializeBundleCacheOp.Progress; + if (_initializeBundleCacheOp.IsDone == false) return; - if (_initializeFileCacheOp.Status == EOperationStatus.Succeeded) + if (_initializeBundleCacheOp.Status == EOperationStatus.Succeeded) { _steps = ESteps.Done; Status = EOperationStatus.Succeeded; @@ -65,7 +65,7 @@ namespace YooAsset { _steps = ESteps.Done; Status = EOperationStatus.Failed; - Error = _initializeFileCacheOp.Error; + Error = _initializeBundleCacheOp.Error; } } } diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/Operations/WSFSLoadPackageBundleOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/Operations/WSFSLoadPackageBundleOperation.cs index b784590d..909801f1 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/Operations/WSFSLoadPackageBundleOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/Operations/WSFSLoadPackageBundleOperation.cs @@ -15,7 +15,7 @@ namespace YooAsset private readonly WebServerFileSystem _fileSystem; private readonly FSLoadPackageBundleOptions _options; - private FCLoadBundleOperation _loadBundleOp; + private BCLoadBundleOperation _loadBundleOp; private ESteps _steps = ESteps.None; internal WSFSLoadPackageBundleOperation(WebServerFileSystem fileSystem, FSLoadPackageBundleOptions options) @@ -36,7 +36,7 @@ namespace YooAsset { if (_loadBundleOp == null) { - _loadBundleOp = _fileSystem.FileCache.LoadBundleAsync(_options.ConvertTo()); + _loadBundleOp = _fileSystem.BundleCache.LoadBundleAsync(_options.ConvertTo()); _loadBundleOp.StartOperation(); AddChildOperation(_loadBundleOp); } 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 951d9661..297c535f 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/Operations/internal/LoadWebServerPackageManifestOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/Operations/internal/LoadWebServerPackageManifestOperation.cs @@ -50,7 +50,7 @@ namespace YooAsset if (_downloadBytesRequest == null) { string filePath = _fileSystem.GetWebPackageManifestFilePath(_packageVersion); - string url = DownloadSystemTools.ToLocalUrl(filePath); + string url = DownloadSystemTools.ToLocalFileUrl(filePath); var args = new DownloadDataRequestArgs(url, _timeout, 0); _downloadBytesRequest = _fileSystem.DownloadBackend.CreateBytesRequest(args); _downloadBytesRequest.SendRequest(); 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 837df98a..9101b196 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/Operations/internal/RequestWebServerPackageHashOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/Operations/internal/RequestWebServerPackageHashOperation.cs @@ -45,7 +45,7 @@ namespace YooAsset if (_downloadTextRequest == null) { string filePath = _fileSystem.GetWebPackageHashFilePath(_packageVersion); - string url = DownloadSystemTools.ToLocalUrl(filePath); + string url = DownloadSystemTools.ToLocalFileUrl(filePath); var args = new DownloadDataRequestArgs(url, _timeout, 0); _downloadTextRequest = _fileSystem.DownloadBackend.CreateTextRequest(args); _downloadTextRequest.SendRequest(); 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 a5212ae0..f753d2bb 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/Operations/internal/RequestWebServerPackageVersionOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/Operations/internal/RequestWebServerPackageVersionOperation.cs @@ -43,7 +43,7 @@ namespace YooAsset if (_downloadTextRequest == null) { string filePath = _fileSystem.GetWebPackageVersionFilePath(); - string url = DownloadSystemTools.ToLocalUrl(filePath); + string url = DownloadSystemTools.ToLocalFileUrl(filePath); var args = new DownloadDataRequestArgs(url, _timeout, 0); _downloadTextRequest = _fileSystem.DownloadBackend.CreateTextRequest(args); _downloadTextRequest.SendRequest(); diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/WebServerFileSystem.cs b/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/WebServerFileSystem.cs index 4925d5aa..463b14d4 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/WebServerFileSystem.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/WebServerFileSystem.cs @@ -14,9 +14,9 @@ namespace YooAsset protected string _packageRoot = string.Empty; /// - /// Web文件缓存系统 + /// WebBundle缓存系统 /// - public IFileCache FileCache { get; private set; } + public IBundleCache BundleCache { get; private set; } /// /// 下载后台接口 @@ -67,7 +67,7 @@ namespace YooAsset /// /// 自定义参数:URL 选择策略 /// - public IDownloadURLPolicy DownloadURLPolicy { get; private set; } + public IDownloadUrlPolicy DownloadURLPolicy { get; private set; } #endregion @@ -141,7 +141,7 @@ namespace YooAsset } else if (name == FileSystemConsts.DOWNLOAD_URL_POLICY) { - DownloadURLPolicy = (IDownloadURLPolicy)value; + DownloadURLPolicy = (IDownloadUrlPolicy)value; } else { @@ -170,7 +170,7 @@ namespace YooAsset DownloadURLPolicy = new DefaultDownloadURLPolicy(); // 创建Web文件缓存系统 - var cacheConfig = new WebServerFileCache.CacheConfig(); + var cacheConfig = new WebServerBundleCache.CacheConfig(); cacheConfig.WatchdogTimeout = DownloadWatchdogTimeout; cacheConfig.DisableUnityWebCache = DisableUnityWebCache; cacheConfig.DownloadVerifyLevel = DownloadVerifyLevel; @@ -178,14 +178,14 @@ namespace YooAsset cacheConfig.DownloadBackend = DownloadBackend; cacheConfig.RetryPolicy = DownloadRetryPolicy; cacheConfig.URLPolicy = DownloadURLPolicy; - FileCache = new WebServerFileCache(packageName, _packageRoot, cacheConfig); + BundleCache = new WebServerBundleCache(packageName, _packageRoot, cacheConfig); } public virtual void OnDestroy() { - if (FileCache != null) + if (BundleCache != null) { - FileCache.Dispose(); - FileCache = null; + BundleCache.Dispose(); + BundleCache = null; } if (DownloadBackend != null) @@ -197,7 +197,7 @@ namespace YooAsset public virtual bool Belong(PackageBundle bundle) { - return FileCache.IsCached(bundle.BundleGUID); + return BundleCache.IsCached(bundle.BundleGUID); } public virtual bool NeedDownload(PackageBundle bundle) { diff --git a/Assets/YooAsset/Runtime/Interfaces/IDownloadURLPolicy.cs b/Assets/YooAsset/Runtime/Interfaces/IDownloadURLPolicy.cs index 16562fcc..c720fbe8 100644 --- a/Assets/YooAsset/Runtime/Interfaces/IDownloadURLPolicy.cs +++ b/Assets/YooAsset/Runtime/Interfaces/IDownloadURLPolicy.cs @@ -5,20 +5,20 @@ namespace YooAsset /// /// URL 选择策略接口 /// - public interface IDownloadURLPolicy + public interface IDownloadUrlPolicy { /// /// 基于内部状态从候选列表中选择本次请求应使用的 URL。 /// - /// 候选 URL 列表(至少包含一个) + /// 候选 URL 列表(至少包含一个) /// 选中的 URL - string SelectURL(IReadOnlyList candidateURLs); + string SelectUrl(IReadOnlyList candidateUrls); /// /// 反馈请求成功,策略可据此更新内部状态。 /// /// 实际使用的 URL - void OnSuccess(string url); + void OnRequestSucceeded(string url); /// /// 反馈请求失败,策略可据此更新内部状态。 @@ -26,6 +26,6 @@ namespace YooAsset /// 实际使用的 URL /// HTTP 状态码(0 表示网络中断或非 HTTP 错误) /// HTTP 错误信息 - void OnFailure(string url, long httpCode, string httpError); + void OnRequestFailed(string url, long httpCode, string httpError); } } diff --git a/Assets/YooAsset/Runtime/ResourceManager/Handles/RawFileHandle.cs b/Assets/YooAsset/Runtime/ResourceManager/Handles/RawFileHandle.cs index 19f67f4e..98ea3e9e 100644 --- a/Assets/YooAsset/Runtime/ResourceManager/Handles/RawFileHandle.cs +++ b/Assets/YooAsset/Runtime/ResourceManager/Handles/RawFileHandle.cs @@ -55,7 +55,7 @@ namespace YooAsset { if (IsValidWithWarning == false) return string.Empty; - return Provider.LoadedBundleHandle.GetBundleFilePath(); + return Provider.LoadedBundleHandle.BundleFilePath; } } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/ResourceManager/Handles/SceneHandle.cs b/Assets/YooAsset/Runtime/ResourceManager/Handles/SceneHandle.cs index 08644b11..c0484e80 100644 --- a/Assets/YooAsset/Runtime/ResourceManager/Handles/SceneHandle.cs +++ b/Assets/YooAsset/Runtime/ResourceManager/Handles/SceneHandle.cs @@ -100,9 +100,9 @@ namespace YooAsset } /// - /// 解除场景加载挂起操作 + /// 允许场景激活 /// - public bool UnSuspend() + public bool AllowSceneActivation() { if (IsValidWithWarning == false) return false; @@ -110,7 +110,7 @@ namespace YooAsset if (Provider is SceneProvider) { var provider = Provider as SceneProvider; - provider.UnSuspendLoad(); + provider.AllowSceneActivation(); } else { diff --git a/Assets/YooAsset/Runtime/ResourceManager/Operations/Internal/LoadBundleOperation.cs b/Assets/YooAsset/Runtime/ResourceManager/Operations/Internal/LoadBundleOperation.cs index 199d938b..43999779 100644 --- a/Assets/YooAsset/Runtime/ResourceManager/Operations/Internal/LoadBundleOperation.cs +++ b/Assets/YooAsset/Runtime/ResourceManager/Operations/Internal/LoadBundleOperation.cs @@ -155,7 +155,7 @@ namespace YooAsset throw new YooInternalException($"Cannot destroy loader with non-zero ref count {RefCount}: {LoadBundleInfo.Bundle.BundleName}"); if (BundleHandle != null) - BundleHandle.UnloadBundleFile(); + BundleHandle.UnloadBundle(); if (IsDone == false) { diff --git a/Assets/YooAsset/Runtime/ResourceManager/Operations/UnloadSceneOperation.cs b/Assets/YooAsset/Runtime/ResourceManager/Operations/UnloadSceneOperation.cs index 1006ccec..b2cc3018 100644 --- a/Assets/YooAsset/Runtime/ResourceManager/Operations/UnloadSceneOperation.cs +++ b/Assets/YooAsset/Runtime/ResourceManager/Operations/UnloadSceneOperation.cs @@ -31,11 +31,11 @@ namespace YooAsset _error = null; _provider = provider; - // 注意:卸载场景前必须先解除挂起操作 + // 注意:卸载场景前必须先允许场景激活 if (provider is SceneProvider) { var temp = provider as SceneProvider; - temp.UnSuspendLoad(); + temp.AllowSceneActivation(); } else { diff --git a/Assets/YooAsset/Runtime/ResourceManager/Providers/SceneProvider.cs b/Assets/YooAsset/Runtime/ResourceManager/Providers/SceneProvider.cs index d0cff18a..c52412ad 100644 --- a/Assets/YooAsset/Runtime/ResourceManager/Providers/SceneProvider.cs +++ b/Assets/YooAsset/Runtime/ResourceManager/Providers/SceneProvider.cs @@ -12,20 +12,20 @@ namespace YooAsset internal sealed class SceneProvider : ProviderBase { private readonly LoadSceneParameters _loadSceneParams; - private bool _suspendLoad; + private bool _allowSceneActivation; private BHLoadSceneOperation _loadSceneOp; - public SceneProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo, LoadSceneParameters loadSceneParams, bool suspendLoad) : base(manager, providerGUID, assetInfo) + public SceneProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo, LoadSceneParameters loadSceneParams, bool allowSceneActivation) : base(manager, providerGUID, assetInfo) { _loadSceneParams = loadSceneParams; - _suspendLoad = suspendLoad; + _allowSceneActivation = allowSceneActivation; LoadedSceneName = Path.GetFileNameWithoutExtension(assetInfo.AssetPath); } protected override void ProcessBundleHandle() { if (_loadSceneOp == null) { - _loadSceneOp = LoadedBundleHandle.LoadSceneAsync(MainAssetInfo, _loadSceneParams, _suspendLoad); + _loadSceneOp = LoadedBundleHandle.LoadSceneAsync(MainAssetInfo, _loadSceneParams, _allowSceneActivation); _loadSceneOp.StartOperation(); AddChildOperation(_loadSceneOp); } @@ -33,9 +33,8 @@ namespace YooAsset if (IsWaitForCompletion) _loadSceneOp.WaitForCompletion(); - // 注意:场景加载中途可以取消挂起 - if (_suspendLoad == false) - _loadSceneOp.ResumeLoad(); + if (_allowSceneActivation) + _loadSceneOp.AllowSceneActivation(); _loadSceneOp.UpdateOperation(); Progress = _loadSceneOp.Progress; @@ -54,11 +53,11 @@ namespace YooAsset } /// - /// 解除场景加载挂起操作 + /// 允许场景激活 /// - public void UnSuspendLoad() + public void AllowSceneActivation() { - _suspendLoad = false; + _allowSceneActivation = true; } } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/ResourceManager/ResourceManager.cs b/Assets/YooAsset/Runtime/ResourceManager/ResourceManager.cs index c2424c81..3631fec0 100644 --- a/Assets/YooAsset/Runtime/ResourceManager/ResourceManager.cs +++ b/Assets/YooAsset/Runtime/ResourceManager/ResourceManager.cs @@ -148,7 +148,7 @@ namespace YooAsset /// 注意:返回的场景句柄是唯一的,每个场景句柄对应自己的场景提供者对象。 /// 注意:业务逻辑层应该避免同时加载一个子场景。 /// - public SceneHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneParameters loadSceneParams, bool suspendLoad, uint priority) + public SceneHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneParameters loadSceneParams, bool allowSceneActivation, uint priority) { if (LockLoadOperation) { @@ -171,7 +171,7 @@ namespace YooAsset string providerGUID = $"{assetInfo.GUID}-{++_sceneInstanceCounter}"; ProviderBase provider; { - provider = new SceneProvider(this, providerGUID, assetInfo, loadSceneParams, suspendLoad); + provider = new SceneProvider(this, providerGUID, assetInfo, loadSceneParams, allowSceneActivation); provider.InitProviderDebugInfo(); ProviderDict.Add(providerGUID, provider); AsyncOperationSystem.StartOperation(PackageName, provider); diff --git a/Assets/YooAsset/Runtime/ResourcePackage/Operations/DestroyPackageOperation.cs b/Assets/YooAsset/Runtime/ResourcePackage/Operations/DestroyPackageOperation.cs index df743fd6..59d20f59 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/Operations/DestroyPackageOperation.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage/Operations/DestroyPackageOperation.cs @@ -42,7 +42,6 @@ namespace YooAsset { case EOperationStatus.None: case EOperationStatus.Failed: - case EOperationStatus.Aborted: _steps = ESteps.DestroyPackage; break; diff --git a/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs b/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs index 0152fa73..df70c31b 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs @@ -464,7 +464,7 @@ namespace YooAsset { CheckInitialized(); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null); - return LoadSceneInternal(assetInfo, true, sceneMode, physicsMode, false, 0); + return LoadSceneInternal(assetInfo, true, sceneMode, physicsMode, true, 0); } /// @@ -476,7 +476,7 @@ namespace YooAsset public SceneHandle LoadSceneSync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single, LocalPhysicsMode physicsMode = LocalPhysicsMode.None) { CheckInitialized(); - return LoadSceneInternal(assetInfo, true, sceneMode, physicsMode, false, 0); + return LoadSceneInternal(assetInfo, true, sceneMode, physicsMode, true, 0); } /// @@ -485,13 +485,13 @@ namespace YooAsset /// 场景的定位地址 /// 场景加载模式 /// 场景物理模式 - /// 场景加载到90%自动挂起 + /// 是否允许场景激活 /// 加载的优先级 - public SceneHandle LoadSceneAsync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, LocalPhysicsMode physicsMode = LocalPhysicsMode.None, bool suspendLoad = false, uint priority = 0) + public SceneHandle LoadSceneAsync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, LocalPhysicsMode physicsMode = LocalPhysicsMode.None, bool allowSceneActivation = true, uint priority = 0) { CheckInitialized(); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null); - return LoadSceneInternal(assetInfo, false, sceneMode, physicsMode, suspendLoad, priority); + return LoadSceneInternal(assetInfo, false, sceneMode, physicsMode, allowSceneActivation, priority); } /// @@ -500,20 +500,20 @@ namespace YooAsset /// 场景的资源信息 /// 场景加载模式 /// 场景物理模式 - /// 场景加载到90%自动挂起 + /// 是否允许场景激活 /// 加载的优先级 - public SceneHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single, LocalPhysicsMode physicsMode = LocalPhysicsMode.None, bool suspendLoad = false, uint priority = 0) + public SceneHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single, LocalPhysicsMode physicsMode = LocalPhysicsMode.None, bool allowSceneActivation = true, uint priority = 0) { CheckInitialized(); - return LoadSceneInternal(assetInfo, false, sceneMode, physicsMode, suspendLoad, priority); + return LoadSceneInternal(assetInfo, false, sceneMode, physicsMode, allowSceneActivation, priority); } - private SceneHandle LoadSceneInternal(AssetInfo assetInfo, bool waitForAsyncComplete, LoadSceneMode sceneMode, LocalPhysicsMode physicsMode, bool suspendLoad, uint priority) + private SceneHandle LoadSceneInternal(AssetInfo assetInfo, bool waitForAsyncComplete, LoadSceneMode sceneMode, LocalPhysicsMode physicsMode, bool allowSceneActivation, uint priority) { DebugCheckAssetType(assetInfo.AssetType); assetInfo.LoadMethod = AssetInfo.ELoadMethod.LoadScene; var loadSceneParams = new LoadSceneParameters(sceneMode, physicsMode); - var handle = _resourceManager.LoadSceneAsync(assetInfo, loadSceneParams, suspendLoad, priority); + var handle = _resourceManager.LoadSceneAsync(assetInfo, loadSceneParams, allowSceneActivation, priority); if (waitForAsyncComplete) handle.WaitForAsyncComplete(); return handle; @@ -913,9 +913,6 @@ namespace YooAsset case EOperationStatus.Failed: string error = _initializeOp == null ? string.Empty : _initializeOp.Error; throw new YooPackageException(PackageName, $"Resource package initialization failed. Error: {error}"); - - case EOperationStatus.Aborted: - throw new YooPackageException(PackageName, "Resource package initialization was aborted."); } } diff --git a/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionOperation/CopyBuildinManifestOperation.cs b/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionOperation/CopyBuildinManifestOperation.cs index fd604ce6..ae2500db 100644 --- a/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionOperation/CopyBuildinManifestOperation.cs +++ b/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionOperation/CopyBuildinManifestOperation.cs @@ -59,7 +59,7 @@ public class CopyBuildinManifestOperation : AsyncOperationBase { string sourcePath = GetBuildinHashFilePath(); string destPath = GetCacheHashFilePath(); - string url = DownloadSystemTools.ToLocalUrl(sourcePath); + string url = DownloadSystemTools.ToLocalFileUrl(sourcePath); var args = new DownloadFileRequestArgs(url, destPath, 60, 0); _hashFileRequest = _backend.CreateFileRequest(args); _hashFileRequest.SendRequest(); @@ -99,7 +99,7 @@ public class CopyBuildinManifestOperation : AsyncOperationBase { string sourcePath = GetBuildinManifestFilePath(); string destPath = GetCacheManifestFilePath(); - string url = DownloadSystemTools.ToLocalUrl(sourcePath); + string url = DownloadSystemTools.ToLocalFileUrl(sourcePath); var args = new DownloadFileRequestArgs(url, destPath, 60, 0); _manifestFileRequest = _backend.CreateFileRequest(args); _manifestFileRequest.SendRequest(); diff --git a/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionOperation/GetBuildinPackageVersionOperation.cs b/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionOperation/GetBuildinPackageVersionOperation.cs index fd253394..f870ca9c 100644 --- a/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionOperation/GetBuildinPackageVersionOperation.cs +++ b/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionOperation/GetBuildinPackageVersionOperation.cs @@ -45,7 +45,7 @@ public class GetBuildinPackageVersionOperation : AsyncOperationBase if (_downloadTextRequest == null) { string filePath = GetBuildinPackageVersionFilePath(); - string url = DownloadSystemTools.ToLocalUrl(filePath); + string url = DownloadSystemTools.ToLocalFileUrl(filePath); var args = new DownloadDataRequestArgs(url, 60, 0); _downloadTextRequest = _backend.CreateTextRequest(args); _downloadTextRequest.SendRequest(); diff --git a/Assets/YooAsset/Samples~/Mini Game/Runtime/MiniGameTest/FileSystemTester.cs b/Assets/YooAsset/Samples~/Mini Game/Runtime/MiniGameTest/FileSystemTester.cs index 451e3689..75f38073 100644 --- a/Assets/YooAsset/Samples~/Mini Game/Runtime/MiniGameTest/FileSystemTester.cs +++ b/Assets/YooAsset/Samples~/Mini Game/Runtime/MiniGameTest/FileSystemTester.cs @@ -85,7 +85,7 @@ namespace YooAsset } // 卸载资源包 - loadBundleFileOp.BundleHandle.UnloadBundleFile(); + loadBundleFileOp.BundleHandle.UnloadBundle(); } Debug.Log("完整测试成功!");