diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.cs
index cfdf5da..9fe3019 100644
--- a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.cs
+++ b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.cs
@@ -275,6 +275,7 @@ namespace YooAsset.Editor
buildParameters.PackageName = AssetBundleBuilderSettingData.Setting.BuildPackage;
buildParameters.PackageVersion = _buildVersionField.value;
buildParameters.VerifyBuildingResult = true;
+ buildParameters.ShareAssetPackRule = new DefaultShareAssetPackRule();
buildParameters.EncryptionServices = CreateEncryptionServicesInstance();
buildParameters.CompressOption = AssetBundleBuilderSettingData.Setting.CompressOption;
buildParameters.OutputNameStyle = AssetBundleBuilderSettingData.Setting.OutputNameStyle;
diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildAssetInfo.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildAssetInfo.cs
index 7999f92..6802035 100644
--- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildAssetInfo.cs
+++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildAssetInfo.cs
@@ -157,7 +157,7 @@ namespace YooAsset.Editor
///
/// 计算共享资源包的完整包名
///
- public void CalculateShareBundleName(bool uniqueBundleName, string packageName, string shadersBundleName)
+ public void CalculateShareBundleName(IShareAssetPackRule packRule, bool uniqueBundleName, string packageName, string shadersBundleName)
{
if (CollectorType != ECollectorType.None)
return;
@@ -173,8 +173,7 @@ namespace YooAsset.Editor
{
if (_referenceBundleNames.Count > 1)
{
- IPackRule packRule = PackDirectory.StaticPackRule;
- PackRuleResult packRuleResult = packRule.GetPackRuleResult(new PackRuleData(AssetPath));
+ PackRuleResult packRuleResult = packRule.GetPackRuleResult(AssetPath);
BundleName = packRuleResult.GetShareBundleName(packageName, uniqueBundleName);
}
else
diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildParameters.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildParameters.cs
index 3c324c7..a593523 100644
--- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildParameters.cs
+++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildParameters.cs
@@ -76,9 +76,14 @@ namespace YooAsset.Editor
/// 验证构建结果
///
public bool VerifyBuildingResult = false;
-
+
///
- /// 加密类
+ /// 共享资源的打包规则
+ ///
+ public IShareAssetPackRule ShareAssetPackRule = null;
+
+ ///
+ /// 资源的加密接口
///
public IEncryptionServices EncryptionServices = null;
diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskGetBuildMap.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskGetBuildMap.cs
index f3cd9a8..709318f 100644
--- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskGetBuildMap.cs
+++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskGetBuildMap.cs
@@ -13,7 +13,8 @@ namespace YooAsset.Editor
void IBuildTask.Run(BuildContext context)
{
var buildParametersContext = context.GetContextObject();
- var buildMapContext = CreateBuildMap(buildParametersContext.Parameters.BuildMode, buildParametersContext.Parameters.PackageName);
+ var buildParameters = buildParametersContext.Parameters;
+ var buildMapContext = CreateBuildMap(buildParameters.BuildMode, buildParameters.ShareAssetPackRule, buildParameters.PackageName);
context.SetContextObject(buildMapContext);
BuildLogger.Log("构建内容准备完毕!");
@@ -24,7 +25,7 @@ namespace YooAsset.Editor
///
/// 资源构建上下文
///
- public BuildMapContext CreateBuildMap(EBuildMode buildMode, string packageName)
+ public BuildMapContext CreateBuildMap(EBuildMode buildMode, IShareAssetPackRule packRule, string packageName)
{
Dictionary allBuildAssetInfoDic = new Dictionary(1000);
@@ -101,7 +102,7 @@ namespace YooAsset.Editor
var command = collectResult.Command;
foreach (var buildAssetInfo in allBuildAssetInfoDic.Values)
{
- buildAssetInfo.CalculateShareBundleName(command.UniqueBundleName, command.PackageName, command.ShadersBundleName);
+ buildAssetInfo.CalculateShareBundleName(packRule, command.UniqueBundleName, command.PackageName, command.ShadersBundleName);
}
// 9. 移除不参与构建的资源
diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskPrepare.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskPrepare.cs
index 664ac91..738149a 100644
--- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskPrepare.cs
+++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskPrepare.cs
@@ -40,6 +40,10 @@ namespace YooAsset.Editor
throw new Exception("首包资源标签不能为空!");
}
+ // 检测共享资源打包规则
+ if (buildParameters.ShareAssetPackRule == null)
+ throw new Exception("共享资源打包规则不能为空!");
+
#if UNITY_WEBGL
if (buildParameters.EncryptionServices != null)
{
diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/DefaultPackRule.cs b/Assets/YooAsset/Editor/AssetBundleCollector/DefaultPackRule.cs
index 563d1e9..72eef45 100644
--- a/Assets/YooAsset/Editor/AssetBundleCollector/DefaultPackRule.cs
+++ b/Assets/YooAsset/Editor/AssetBundleCollector/DefaultPackRule.cs
@@ -60,8 +60,6 @@ namespace YooAsset.Editor
[DisplayName("资源包名: 父类文件夹路径")]
public class PackDirectory : IPackRule
{
- public static PackDirectory StaticPackRule = new PackDirectory();
-
PackRuleResult IPackRule.GetPackRuleResult(PackRuleData data)
{
string bundleName = Path.GetDirectoryName(data.AssetPath);
diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/DefaultShareAssetPackRule.cs b/Assets/YooAsset/Editor/AssetBundleCollector/DefaultShareAssetPackRule.cs
new file mode 100644
index 0000000..c861e6f
--- /dev/null
+++ b/Assets/YooAsset/Editor/AssetBundleCollector/DefaultShareAssetPackRule.cs
@@ -0,0 +1,16 @@
+using System;
+using System.IO;
+using UnityEditor;
+
+namespace YooAsset.Editor
+{
+ public class DefaultShareAssetPackRule : IShareAssetPackRule
+ {
+ public PackRuleResult GetPackRuleResult(string assetPath)
+ {
+ string bundleName = Path.GetDirectoryName(assetPath);
+ PackRuleResult result = new PackRuleResult(bundleName, DefaultPackRule.AssetBundleFileExtension);
+ return result;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/DefaultShareAssetPackRule.cs.meta b/Assets/YooAsset/Editor/AssetBundleCollector/DefaultShareAssetPackRule.cs.meta
new file mode 100644
index 0000000..61e38b2
--- /dev/null
+++ b/Assets/YooAsset/Editor/AssetBundleCollector/DefaultShareAssetPackRule.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 3b8606481370397489cb3aa21e726d9a
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/IShareAssetPackRule.cs b/Assets/YooAsset/Editor/AssetBundleCollector/IShareAssetPackRule.cs
new file mode 100644
index 0000000..548bc5e
--- /dev/null
+++ b/Assets/YooAsset/Editor/AssetBundleCollector/IShareAssetPackRule.cs
@@ -0,0 +1,14 @@
+
+namespace YooAsset.Editor
+{
+ ///
+ /// 共享资源的打包规则
+ ///
+ public interface IShareAssetPackRule
+ {
+ ///
+ /// 获取打包规则结果
+ ///
+ PackRuleResult GetPackRuleResult(string assetPath);
+ }
+}
\ No newline at end of file
diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/IShareAssetPackRule.cs.meta b/Assets/YooAsset/Editor/AssetBundleCollector/IShareAssetPackRule.cs.meta
new file mode 100644
index 0000000..4fa1990
--- /dev/null
+++ b/Assets/YooAsset/Editor/AssetBundleCollector/IShareAssetPackRule.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 1ed930b0cc1db1742b0a131ca476bd82
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant: