diff --git a/Assets/YooAsset/Runtime/BundleCache/Interfaces/EvictionResult.cs b/Assets/YooAsset/Runtime/BundleCache/Interfaces/EvictionResult.cs
deleted file mode 100644
index 802ddbaa..00000000
--- a/Assets/YooAsset/Runtime/BundleCache/Interfaces/EvictionResult.cs
+++ /dev/null
@@ -1,57 +0,0 @@
-using System.Collections.Generic;
-
-namespace YooAsset
-{
- ///
- /// 淘汰策略执行结果
- ///
- internal readonly struct EvictionResult
- {
- private readonly bool _initialized;
-
- ///
- /// 错误信息
- ///
- public string Error { get; }
-
- ///
- /// 需要清理的资源标识符集合
- ///
- public IReadOnlyList BundleGuids { get; }
-
- ///
- /// 是否执行成功
- ///
- public bool Succeeded
- {
- get { return _initialized && Error == null; }
- }
-
- private EvictionResult(string error, IReadOnlyList bundleGuids)
- {
- _initialized = true;
- Error = error;
- BundleGuids = bundleGuids;
- }
-
- ///
- /// 创建表示执行成功的淘汰结果
- ///
- /// 需要清理的资源包标识符列表
- /// 携带待清理列表的成功结果
- public static EvictionResult CreateSuccess(IReadOnlyList bundleGuids)
- {
- return new EvictionResult(null, bundleGuids);
- }
-
- ///
- /// 创建表示执行失败的淘汰结果
- ///
- /// 描述失败原因的错误信息
- /// 携带错误信息的失败结果
- public static EvictionResult CreateFailure(string error)
- {
- return new EvictionResult(error, null);
- }
- }
-}
diff --git a/Assets/YooAsset/Runtime/BundleCache/Interfaces/ICacheEvictionPolicy.cs b/Assets/YooAsset/Runtime/BundleCache/Interfaces/ICacheEvictionPolicy.cs
index 4ddf7e52..a4723f0f 100644
--- a/Assets/YooAsset/Runtime/BundleCache/Interfaces/ICacheEvictionPolicy.cs
+++ b/Assets/YooAsset/Runtime/BundleCache/Interfaces/ICacheEvictionPolicy.cs
@@ -2,6 +2,59 @@ using System.Collections.Generic;
namespace YooAsset
{
+ ///
+ /// 淘汰策略执行结果
+ ///
+ internal readonly struct EvictionResult
+ {
+ private readonly bool _initialized;
+
+ ///
+ /// 错误信息
+ ///
+ public string Error { get; }
+
+ ///
+ /// 需要清理的资源标识符集合
+ ///
+ public IReadOnlyList BundleGuids { get; }
+
+ ///
+ /// 是否执行成功
+ ///
+ public bool Succeeded
+ {
+ get { return _initialized && Error == null; }
+ }
+
+ private EvictionResult(string error, IReadOnlyList bundleGuids)
+ {
+ _initialized = true;
+ Error = error;
+ BundleGuids = bundleGuids;
+ }
+
+ ///
+ /// 创建表示执行成功的淘汰结果
+ ///
+ /// 需要清理的资源包标识符列表
+ /// 携带待清理列表的成功结果
+ public static EvictionResult CreateSuccess(IReadOnlyList bundleGuids)
+ {
+ return new EvictionResult(null, bundleGuids);
+ }
+
+ ///
+ /// 创建表示执行失败的淘汰结果
+ ///
+ /// 描述失败原因的错误信息
+ /// 携带错误信息的失败结果
+ public static EvictionResult CreateFailure(string error)
+ {
+ return new EvictionResult(error, null);
+ }
+ }
+
///
/// 缓存淘汰策略接口
///
diff --git a/Assets/YooAsset/Runtime/FileSystem/EFileSystemParameter.cs b/Assets/YooAsset/Runtime/FileSystem/EFileSystemParameter.cs
index 4554806c..717948bd 100644
--- a/Assets/YooAsset/Runtime/FileSystem/EFileSystemParameter.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/EFileSystemParameter.cs
@@ -140,5 +140,10 @@ namespace YooAsset
/// WebGL 平台策略
///
WebPlatformStrategy,
+
+ ///
+ /// 内置资源包解包策略
+ ///
+ BundleUnpackPolicy,
}
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/FileSystem/Policies.meta b/Assets/YooAsset/Runtime/FileSystem/Policies.meta
new file mode 100644
index 00000000..38bf0502
--- /dev/null
+++ b/Assets/YooAsset/Runtime/FileSystem/Policies.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: fddffc84672187546a9661cf642c60eb
+folderAsset: yes
+DefaultImporter:
+ externalObjects: {}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/YooAsset/Runtime/FileSystem/Policies/DefaultBundleUnpackPolicy.cs b/Assets/YooAsset/Runtime/FileSystem/Policies/DefaultBundleUnpackPolicy.cs
new file mode 100644
index 00000000..ed1ca86b
--- /dev/null
+++ b/Assets/YooAsset/Runtime/FileSystem/Policies/DefaultBundleUnpackPolicy.cs
@@ -0,0 +1,21 @@
+
+namespace YooAsset
+{
+ internal sealed class DefaultBundleUnpackPolicy : IBundleUnpackPolicy
+ {
+ public bool IsUnpackBundle(BundleUnpackInfo unpackInfo)
+ {
+#if UNITY_ANDROID || UNITY_OPENHARMONY
+ if (unpackInfo.IsEncrypted)
+ return true;
+ if (unpackInfo.BundleType == (int)EBundleType.RawBundle)
+ return true;
+ if (unpackInfo.BundleType == (int)EBundleType.ArchiveBundle)
+ return true;
+ return false;
+#else
+ return false;
+#endif
+ }
+ }
+}
diff --git a/Assets/YooAsset/Runtime/BundleCache/Interfaces/EvictionResult.cs.meta b/Assets/YooAsset/Runtime/FileSystem/Policies/DefaultBundleUnpackPolicy.cs.meta
similarity index 83%
rename from Assets/YooAsset/Runtime/BundleCache/Interfaces/EvictionResult.cs.meta
rename to Assets/YooAsset/Runtime/FileSystem/Policies/DefaultBundleUnpackPolicy.cs.meta
index 93201b1c..a60dfcad 100644
--- a/Assets/YooAsset/Runtime/BundleCache/Interfaces/EvictionResult.cs.meta
+++ b/Assets/YooAsset/Runtime/FileSystem/Policies/DefaultBundleUnpackPolicy.cs.meta
@@ -1,5 +1,5 @@
fileFormatVersion: 2
-guid: 1cfc5979929f8cd43b58e1fcc541eaa8
+guid: 76f39715fe286bd43b87ebab22ff1c9f
MonoImporter:
externalObjects: {}
serializedVersion: 2
diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/BuiltinFileSystem.cs b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/BuiltinFileSystem.cs
index 1deb8eff..270b443e 100644
--- a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/BuiltinFileSystem.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/BuiltinFileSystem.cs
@@ -60,9 +60,7 @@ namespace YooAsset
///
public IDownloadBackend DownloadBackend { get; private set; }
- ///
- /// 包裹名称
- ///
+ ///
public string PackageName { get; private set; }
#region 自定义参数
@@ -142,6 +140,11 @@ namespace YooAsset
/// 自定义参数:资源清单解密器
///
public IManifestDecryptor ManifestDecryptor { get; private set; }
+
+ ///
+ /// 自定义参数:内置资源包解包策略
+ ///
+ internal IBundleUnpackPolicy BundleUnpackPolicy { get; private set; }
#endregion
///
@@ -286,6 +289,10 @@ namespace YooAsset
{
ManifestDecryptor = FileSystemHelper.CastParameter(paramName, value);
}
+ else if (paramName == nameof(EFileSystemParameter.BundleUnpackPolicy))
+ {
+ BundleUnpackPolicy = FileSystemHelper.CastParameter(paramName, value);
+ }
else
{
throw new ArgumentException($"Unrecognized parameter name: '{paramName}'.", nameof(paramName));
@@ -311,6 +318,10 @@ namespace YooAsset
_unpackBundleFilesRoot = PathUtility.Combine(unpackRoot, BuiltinFileSystemConsts.UnpackBundleFilesFolderName);
_tempFilesRoot = PathUtility.Combine(unpackRoot, BuiltinFileSystemConsts.UnpackTempFilesFolderName);
+ // 创建默认的解包策略
+ if (BundleUnpackPolicy == null)
+ BundleUnpackPolicy = new DefaultBundleUnpackPolicy();
+
// 创建默认的下载后台接口
if (DownloadBackend == null)
DownloadBackend = new UnityWebRequestBackend(WebRequestCreator);
@@ -376,14 +387,13 @@ namespace YooAsset
///
public bool IsUnpackRequired(PackageBundle bundle)
{
- if (IsUnpackBundleFile(bundle))
- {
- return UnpackBundleCache.IsCached(bundle.BundleGuid) == false;
- }
- else
- {
+ if (CanAcceptBundle(bundle) == false)
return false;
- }
+
+ if (IsUnpackBundle(bundle) == false)
+ return false;
+
+ return UnpackBundleCache.IsCached(bundle.BundleGuid) == false;
}
///
public bool IsImportRequired(PackageBundle bundle)
@@ -391,31 +401,16 @@ namespace YooAsset
return false;
}
+ #region 内部方法
///
- /// 是否属于解压资源包文件
+ /// 通过策略判定指定资源包是否为需要解包的类型
///
- public bool IsUnpackBundleFile(PackageBundle bundle)
+ internal bool IsUnpackBundle(PackageBundle bundle)
{
- if (CanAcceptBundle(bundle) == false)
- return false;
-
-#if UNITY_ANDROID || UNITY_OPENHARMONY
- if (bundle.IsEncrypted)
- return true;
-
- if (bundle.GetBundleType() == (int)EBundleType.RawBundle)
- return true;
-
- if (bundle.GetBundleType() == (int)EBundleType.ArchiveBundle)
- return true;
-
- return false;
-#else
- return false;
-#endif
+ var unpackInfo = new BundleUnpackInfo(bundle);
+ return BundleUnpackPolicy.IsUnpackBundle(unpackInfo);
}
- #region 内部方法
///
/// 获取默认的内置包裹根目录
///
diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/BFSEnsurePackageBundleOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/BFSEnsurePackageBundleOperation.cs
index ef418ae5..02a9ca0e 100644
--- a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/BFSEnsurePackageBundleOperation.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/BFSEnsurePackageBundleOperation.cs
@@ -33,7 +33,7 @@ namespace YooAsset
if (_steps == ESteps.CheckUnpack)
{
- if (_fileSystem.IsUnpackBundleFile(_options.Bundle))
+ if (_fileSystem.IsUnpackBundle(_options.Bundle))
{
if (_fileSystem.UnpackBundleCache.IsCached(_options.Bundle.BundleGuid))
{
diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/BFSLoadPackageBundleOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/BFSLoadPackageBundleOperation.cs
index 80859ecb..cd502523 100644
--- a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/BFSLoadPackageBundleOperation.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/BFSLoadPackageBundleOperation.cs
@@ -40,7 +40,7 @@ namespace YooAsset
if (_steps == ESteps.Prepare)
{
- if (_fileSystem.IsUnpackBundleFile(_options.Bundle))
+ if (_fileSystem.IsUnpackBundle(_options.Bundle))
{
if (_fileSystem.UnpackBundleCache.IsCached(_options.Bundle.BundleGuid))
_steps = ESteps.LoadUnpackBundle;
diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/EditorFileSystem.cs b/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/EditorFileSystem.cs
index 7d71dbc1..4864857f 100644
--- a/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/EditorFileSystem.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/EditorFileSystem.cs
@@ -28,9 +28,7 @@ namespace YooAsset
///
public IDownloadBackend DownloadBackend { get; private set; }
- ///
- /// 包裹名称
- ///
+ ///
public string PackageName { get; private set; }
#region 自定义参数
diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/SandboxFileSystem.cs b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/SandboxFileSystem.cs
index 554bbba8..9913920b 100644
--- a/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/SandboxFileSystem.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/SandboxFileSystem.cs
@@ -50,9 +50,7 @@ namespace YooAsset
///
public IDownloadBackend DownloadBackend { get; private set; }
- ///
- /// 包裹名称
- ///
+ ///
public string PackageName { get; private set; }
#region 自定义参数
diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/WebNetworkFileSystem/WebNetworkFileSystem.cs b/Assets/YooAsset/Runtime/FileSystem/Services/WebNetworkFileSystem/WebNetworkFileSystem.cs
index eb5c3148..5dab0f82 100644
--- a/Assets/YooAsset/Runtime/FileSystem/Services/WebNetworkFileSystem/WebNetworkFileSystem.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/Services/WebNetworkFileSystem/WebNetworkFileSystem.cs
@@ -8,11 +8,6 @@ namespace YooAsset
///
internal class WebNetworkFileSystem : IFileSystem
{
- ///
- /// 包裹名称
- ///
- public string PackageName { get; private set; }
-
///
/// Web 文件缓存系统
///
@@ -28,6 +23,9 @@ namespace YooAsset
///
public IWebPlatformStrategy PlatformStrategy { get; private set; }
+ ///
+ public string PackageName { get; private set; }
+
#region 自定义参数
///
/// 自定义参数:UnityWebRequest 创建委托
diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/WebServerFileSystem.cs b/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/WebServerFileSystem.cs
index 24784383..22bed762 100644
--- a/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/WebServerFileSystem.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/WebServerFileSystem.cs
@@ -35,9 +35,7 @@ namespace YooAsset
///
public IWebPlatformStrategy PlatformStrategy { get; private set; }
- ///
- /// 包裹名称
- ///
+ ///
public string PackageName { get; private set; }
#region 自定义参数
diff --git a/Assets/YooAsset/Runtime/Interfaces/IBundleUnpackPolicy.cs b/Assets/YooAsset/Runtime/Interfaces/IBundleUnpackPolicy.cs
new file mode 100644
index 00000000..016aa893
--- /dev/null
+++ b/Assets/YooAsset/Runtime/Interfaces/IBundleUnpackPolicy.cs
@@ -0,0 +1,82 @@
+
+namespace YooAsset
+{
+ ///
+ /// 资源包解包判定信息
+ ///
+ public readonly struct BundleUnpackInfo
+ {
+ private readonly PackageBundle _bundle;
+
+ ///
+ /// 资源包名称
+ ///
+ public string BundleName => _bundle.BundleName;
+
+ ///
+ /// 资源包文件名称
+ ///
+ public string FileName => _bundle.GetFileName();
+
+ ///
+ /// 资源包类型
+ ///
+ public int BundleType => _bundle.GetBundleType();
+
+ ///
+ /// 是否为加密资源包
+ ///
+ public bool IsEncrypted => _bundle.IsEncrypted;
+
+ ///
+ /// 分类标签数量
+ ///
+ public int TagCount
+ {
+ get
+ {
+ return _bundle.Tags == null ? 0 : _bundle.Tags.Length;
+ }
+ }
+
+ internal BundleUnpackInfo(PackageBundle bundle)
+ {
+ _bundle = bundle;
+ }
+
+ ///
+ /// 获取指定索引的分类标签
+ ///
+ public string GetTag(int index)
+ {
+ return _bundle.Tags[index];
+ }
+
+ ///
+ /// 是否包含指定的单个标签
+ ///
+ public bool HasTag(string tag)
+ {
+ return _bundle.HasTag(tag);
+ }
+
+ ///
+ /// 是否包含指定标签数组中的任意一个
+ ///
+ public bool HasAnyTag(string[] tags)
+ {
+ return _bundle.HasAnyTag(tags);
+ }
+ }
+
+ ///
+ /// 内置资源包解包策略接口
+ ///
+ public interface IBundleUnpackPolicy
+ {
+ ///
+ /// 判定指定资源包是否为需要解包的类型
+ ///
+ bool IsUnpackBundle(BundleUnpackInfo unpackInfo);
+ }
+}
diff --git a/Assets/YooAsset/Runtime/Interfaces/IBundleUnpackPolicy.cs.meta b/Assets/YooAsset/Runtime/Interfaces/IBundleUnpackPolicy.cs.meta
new file mode 100644
index 00000000..39acc8dd
--- /dev/null
+++ b/Assets/YooAsset/Runtime/Interfaces/IBundleUnpackPolicy.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: f33376471ec6d354cb760a8f6be9897a
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/YooAsset/Runtime/ResourcePackage/PackageBundle.cs b/Assets/YooAsset/Runtime/ResourcePackage/PackageBundle.cs
index 90590c4c..5aa9b613 100644
--- a/Assets/YooAsset/Runtime/ResourcePackage/PackageBundle.cs
+++ b/Assets/YooAsset/Runtime/ResourcePackage/PackageBundle.cs
@@ -1,5 +1,4 @@
using System;
-using System.Linq;
using System.Collections.Generic;
namespace YooAsset
@@ -142,10 +141,24 @@ namespace YooAsset
}
///
- /// 是否包含指定的标签
+ /// 是否包含指定的单个标签
+ ///
+ public bool HasTag(string tag)
+ {
+ if (Tags == null || Tags.Length == 0)
+ return false;
+
+ for (int i = 0; i < Tags.Length; i++)
+ {
+ if (Tags[i] == tag)
+ return true;
+ }
+ return false;
+ }
+
+ ///
+ /// 是否包含指定标签数组中的任意一个
///
- /// 要检查的标签数组
- /// 如果包含任意一个标签返回true,否则返回false。
public bool HasAnyTag(string[] tags)
{
if (tags == null || tags.Length == 0)
@@ -153,9 +166,9 @@ namespace YooAsset
if (Tags == null || Tags.Length == 0)
return false;
- foreach (var tag in tags)
+ for (int i = 0; i < tags.Length; i++)
{
- if (Tags.Contains(tag))
+ if (HasTag(tags[i]))
return true;
}
return false;