diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskCreateReport.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskCreateReport.cs
index 56051f5..dccf608 100644
--- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskCreateReport.cs
+++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskCreateReport.cs
@@ -37,7 +37,7 @@ namespace YooAsset.Editor
buildReport.Summary.EnableAddressable = buildMapContext.Command.EnableAddressable;
buildReport.Summary.LocationToLower = buildMapContext.Command.LocationToLower;
buildReport.Summary.IncludeAssetGUID = buildMapContext.Command.IncludeAssetGUID;
- buildReport.Summary.IgnoreDefaultType = buildMapContext.Command.IgnoreDefaultType;
+ buildReport.Summary.IgnoreRuleName = buildMapContext.Command.IgnoreRule.GetType().FullName;
buildReport.Summary.AutoCollectShaders = buildMapContext.Command.AutoCollectShaders;
// 构建参数
diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollector.cs b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollector.cs
index dbf9612..8737488 100644
--- a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollector.cs
+++ b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollector.cs
@@ -166,7 +166,7 @@ namespace YooAsset.Editor
foreach (string assetPath in findAssets)
{
var assetInfo = new AssetInfo(assetPath);
- if (IsValidateAsset(command, assetInfo) && IsCollectAsset(group, assetInfo))
+ if (command.IgnoreRule.IsIgnore(assetInfo) == false && IsCollectAsset(group, assetInfo))
{
if (result.ContainsKey(assetPath) == false)
{
@@ -228,37 +228,6 @@ namespace YooAsset.Editor
return collectAssetInfo;
}
- private bool IsValidateAsset(CollectCommand command, AssetInfo assetInfo)
- {
- if (assetInfo.AssetPath.StartsWith("Assets/") == false && assetInfo.AssetPath.StartsWith("Packages/") == false)
- {
- UnityEngine.Debug.LogError($"Invalid asset path : {assetInfo.AssetPath}");
- return false;
- }
-
- // 忽略文件夹
- if (AssetDatabase.IsValidFolder(assetInfo.AssetPath))
- return false;
-
- // 忽略编辑器下的类型资源
- if (assetInfo.AssetType == typeof(LightingDataAsset))
- return false;
-
- // 忽略Unity引擎无法识别的文件
- if (command.IgnoreDefaultType)
- {
- if (assetInfo.AssetType == typeof(UnityEditor.DefaultAsset))
- {
- UnityEngine.Debug.LogWarning($"Cannot pack default asset : {assetInfo.AssetPath}");
- return false;
- }
- }
-
- if (DefaultFilterRule.IsIgnoreFile(assetInfo.FileExtension))
- return false;
-
- return true;
- }
private bool IsCollectAsset(AssetBundleCollectorGroup group, AssetInfo assetInfo)
{
// 根据规则设置过滤资源文件
@@ -312,7 +281,7 @@ namespace YooAsset.Editor
continue;
AssetInfo assetInfo = new AssetInfo(assetPath);
- if (IsValidateAsset(command, assetInfo))
+ if (command.IgnoreRule.IsIgnore(assetInfo) == false)
result.Add(assetInfo);
}
return result;
diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorConfig.cs b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorConfig.cs
index 234286f..25fef53 100644
--- a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorConfig.cs
+++ b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorConfig.cs
@@ -25,7 +25,7 @@ namespace YooAsset.Editor
public const string XmlEnableAddressable = "AutoAddressable";
public const string XmlLocationToLower = "LocationToLower";
public const string XmlIncludeAssetGUID = "IncludeAssetGUID";
- public const string XmlIgnoreDefaultType = "IgnoreDefaultType";
+ public const string XmlIgnoreRuleName = "IgnoreRuleName";
public const string XmlGroup = "Group";
public const string XmlGroupActiveRule = "GroupActiveRule";
@@ -101,7 +101,7 @@ namespace YooAsset.Editor
package.EnableAddressable = packageElement.GetAttribute(XmlEnableAddressable) == "True" ? true : false;
package.LocationToLower = packageElement.GetAttribute(XmlLocationToLower) == "True" ? true : false;
package.IncludeAssetGUID = packageElement.GetAttribute(XmlIncludeAssetGUID) == "True" ? true : false;
- package.IgnoreDefaultType = packageElement.GetAttribute(XmlIgnoreDefaultType) == "True" ? true : false;
+ package.IgnoreRuleName = packageElement.GetAttribute(XmlIgnoreRuleName);
packages.Add(package);
// 读取分组配置
@@ -213,7 +213,7 @@ namespace YooAsset.Editor
packageElement.SetAttribute(XmlEnableAddressable, package.EnableAddressable.ToString());
packageElement.SetAttribute(XmlLocationToLower, package.LocationToLower.ToString());
packageElement.SetAttribute(XmlIncludeAssetGUID, package.IncludeAssetGUID.ToString());
- packageElement.SetAttribute(XmlIgnoreDefaultType, package.IgnoreDefaultType.ToString());
+ packageElement.SetAttribute(XmlIgnoreRuleName, package.IgnoreRuleName);
root.AppendChild(packageElement);
// 设置分组配置
diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorPackage.cs b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorPackage.cs
index 702cfba..a62cffb 100644
--- a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorPackage.cs
+++ b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorPackage.cs
@@ -35,16 +35,16 @@ namespace YooAsset.Editor
///
public bool IncludeAssetGUID = false;
- ///
- /// 忽略Unity引擎无法识别的文件
- ///
- public bool IgnoreDefaultType = true;
-
///
/// 自动收集所有着色器(所有着色器存储在一个资源包内)
///
public bool AutoCollectShaders = true;
+ ///
+ /// 资源忽略规则名
+ ///
+ public string IgnoreRuleName = nameof(NormalIgnoreRule);
+
///
/// 分组列表
///
diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSetting.cs b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSetting.cs
index df00a1e..2e46822 100644
--- a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSetting.cs
+++ b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSetting.cs
@@ -24,7 +24,6 @@ namespace YooAsset.Editor
///
public bool UniqueBundleName = false;
-
///
/// 包裹列表
///
@@ -100,13 +99,13 @@ namespace YooAsset.Editor
package.CheckConfigError();
// 创建资源收集命令
+ IIgnoreRule ignoreRule = AssetBundleCollectorSettingData.GetIgnoreRuleInstance(package.IgnoreRuleName);
CollectCommand command = new CollectCommand(buildMode, packageName,
package.EnableAddressable,
package.LocationToLower,
package.IncludeAssetGUID,
- package.IgnoreDefaultType,
package.AutoCollectShaders,
- UniqueBundleName);
+ UniqueBundleName, ignoreRule);
// 获取收集的资源集合
CollectResult collectResult = new CollectResult(command);
diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSettingData.cs b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSettingData.cs
index ace3cfe..e8f4fe4 100644
--- a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSettingData.cs
+++ b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSettingData.cs
@@ -21,6 +21,9 @@ namespace YooAsset.Editor
private static readonly Dictionary _cacheFilterRuleTypes = new Dictionary();
private static readonly Dictionary _cacheFilterRuleInstance = new Dictionary();
+ private static readonly Dictionary _cacheIgnoreRuleTypes = new Dictionary();
+ private static readonly Dictionary _cacheIgnoreRuleInstance = new Dictionary();
+
///
/// 配置数据是否被修改
///
@@ -129,6 +132,29 @@ namespace YooAsset.Editor
_cacheActiveRuleTypes.Add(type.Name, type);
}
}
+
+ // IIgnoreRule
+ {
+ // 清空缓存集合
+ _cacheIgnoreRuleTypes.Clear();
+ _cacheIgnoreRuleInstance.Clear();
+
+ // 获取所有类型
+ List types = new List(100)
+ {
+ typeof(NormalIgnoreRule),
+ typeof(RawFileIgnoreRule),
+ };
+
+ var customTypes = EditorTools.GetAssignableTypes(typeof(IIgnoreRule));
+ types.AddRange(customTypes);
+ for (int i = 0; i < types.Count; i++)
+ {
+ Type type = types[i];
+ if (_cacheIgnoreRuleTypes.ContainsKey(type.Name) == false)
+ _cacheIgnoreRuleTypes.Add(type.Name, type);
+ }
+ }
}
private static AssetBundleCollectorSetting _setting = null;
@@ -225,6 +251,18 @@ namespace YooAsset.Editor
}
return names;
}
+ public static List GetIgnoreRuleNames()
+ {
+ List names = new List();
+ foreach (var pair in _cacheIgnoreRuleTypes)
+ {
+ RuleDisplayName ruleName = new RuleDisplayName();
+ ruleName.ClassName = pair.Key;
+ ruleName.DisplayName = GetRuleDisplayName(pair.Key, pair.Value);
+ names.Add(ruleName);
+ }
+ return names;
+ }
private static string GetRuleDisplayName(string name, Type type)
{
var attribute = DisplayNameAttributeHelper.GetAttribute(type);
@@ -250,6 +288,10 @@ namespace YooAsset.Editor
{
return _cacheFilterRuleTypes.Keys.Contains(ruleName);
}
+ public static bool HasIgnoreRuleName(string ruleName)
+ {
+ return _cacheIgnoreRuleTypes.Keys.Contains(ruleName);
+ }
public static IActiveRule GetActiveRuleInstance(string ruleName)
{
@@ -319,6 +361,23 @@ namespace YooAsset.Editor
throw new Exception($"{nameof(IFilterRule)} is invalid:{ruleName}");
}
}
+ public static IIgnoreRule GetIgnoreRuleInstance(string ruleName)
+ {
+ if (_cacheIgnoreRuleInstance.TryGetValue(ruleName, out IIgnoreRule instance))
+ return instance;
+
+ // 如果不存在创建类的实例
+ if (_cacheIgnoreRuleTypes.TryGetValue(ruleName, out Type type))
+ {
+ instance = (IIgnoreRule)Activator.CreateInstance(type);
+ _cacheIgnoreRuleInstance.Add(ruleName, instance);
+ return instance;
+ }
+ else
+ {
+ throw new Exception($"{nameof(IIgnoreRule)} is invalid:{ruleName}");
+ }
+ }
// 公共参数编辑相关
public static void ModifyShowPackageView(bool showPackageView)
diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorWindow.cs b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorWindow.cs
index f9e44b5..f469172 100644
--- a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorWindow.cs
+++ b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorWindow.cs
@@ -24,6 +24,7 @@ namespace YooAsset.Editor
private List _addressRuleList;
private List _packRuleList;
private List _filterRuleList;
+ private List _ignoreRuleList;
private VisualElement _helpBoxContainer;
@@ -39,9 +40,9 @@ namespace YooAsset.Editor
private Toggle _enableAddressableToogle;
private Toggle _locationToLowerToogle;
private Toggle _includeAssetGUIDToogle;
- private Toggle _ignoreDefaultTypeToogle;
private Toggle _autoCollectShadersToogle;
-
+ private PopupField _ignoreRulePopupField;
+
private VisualElement _packageContainer;
private ListView _packageListView;
private TextField _packageNameTxt;
@@ -77,6 +78,7 @@ namespace YooAsset.Editor
_addressRuleList = AssetBundleCollectorSettingData.GetAddressRuleNames();
_packRuleList = AssetBundleCollectorSettingData.GetPackRuleNames();
_filterRuleList = AssetBundleCollectorSettingData.GetFilterRuleNames();
+ _ignoreRuleList = AssetBundleCollectorSettingData.GetIgnoreRuleNames();
VisualElement root = this.rootVisualElement;
@@ -151,17 +153,6 @@ namespace YooAsset.Editor
RefreshWindow();
}
});
- _ignoreDefaultTypeToogle = root.Q("IgnoreDefaultType");
- _ignoreDefaultTypeToogle.RegisterValueChangedCallback(evt =>
- {
- var selectPackage = _packageListView.selectedItem as AssetBundleCollectorPackage;
- if (selectPackage != null)
- {
- selectPackage.IgnoreDefaultType = evt.newValue;
- AssetBundleCollectorSettingData.ModifyPackage(selectPackage);
- RefreshWindow();
- }
- });
_autoCollectShadersToogle = root.Q("AutoCollectShaders");
_autoCollectShadersToogle.RegisterValueChangedCallback(evt =>
{
@@ -173,6 +164,25 @@ namespace YooAsset.Editor
RefreshWindow();
}
});
+ {
+ _ignoreRulePopupField = new PopupField(_ignoreRuleList, 0);
+ _ignoreRulePopupField.label = "File Ignore Rule";
+ _ignoreRulePopupField.name = "IgnoreRulePopupField";
+ _ignoreRulePopupField.style.unityTextAlign = TextAnchor.MiddleLeft;
+ _ignoreRulePopupField.style.width = 300;
+ _ignoreRulePopupField.formatListItemCallback = FormatListItemCallback;
+ _ignoreRulePopupField.formatSelectedValueCallback = FormatSelectedValueCallback;
+ _ignoreRulePopupField.RegisterValueChangedCallback(evt =>
+ {
+ var selectPackage = _packageListView.selectedItem as AssetBundleCollectorPackage;
+ if(selectPackage != null)
+ {
+ selectPackage.IgnoreRuleName = evt.newValue.ClassName;
+ AssetBundleCollectorSettingData.ModifyPackage(selectPackage);
+ }
+ });
+ _setting2Container.Add(_ignoreRulePopupField);
+ }
// 配置修复按钮
var fixBtn = root.Q