diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.cs index 54c325f..4f259c2 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.cs @@ -29,7 +29,7 @@ namespace YooAsset.Editor private PopupField _encryptionField; private EnumField _compressionField; private Toggle _appendExtensionToggle; - + public void CreateGUI() { try @@ -40,7 +40,7 @@ namespace YooAsset.Editor var visualAsset = EditorHelper.LoadWindowUXML(); if (visualAsset == null) return; - + visualAsset.CloneTree(root); _buildTarget = EditorUserBuildSettings.activeBuildTarget; @@ -107,7 +107,7 @@ namespace YooAsset.Editor _compressionField = root.Q("Compression"); _compressionField.Init(AssetBundleBuilderSettingData.Setting.CompressOption); _compressionField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.CompressOption); - _compressionField.style.width = 300; + _compressionField.style.width = 300; _compressionField.RegisterValueChangedCallback(evt => { AssetBundleBuilderSettingData.Setting.CompressOption = (ECompressOption)_compressionField.value; @@ -183,11 +183,10 @@ namespace YooAsset.Editor AssetBundleBuilder builder = new AssetBundleBuilder(); bool succeed = builder.Run(buildParameters); - if (succeed) { EditorUtility.RevealInFinder($"{buildParameters.OutputRoot}/{buildParameters.BuildTarget}/{buildParameters.BuildVersion}"); - } + } } // 加密类相关 diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorGroup.cs b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorGroup.cs index 324ba5c..8e19d22 100644 --- a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorGroup.cs +++ b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorGroup.cs @@ -25,6 +25,11 @@ namespace YooAsset.Editor /// public string AssetTags = string.Empty; + /// + /// 分组激活规则 + /// + public string ActiveRuleName = nameof(EnableGroup); + /// /// 分组的收集器列表 /// @@ -36,6 +41,9 @@ namespace YooAsset.Editor /// public void CheckConfigError() { + if (AssetBundleCollectorSettingData.HasActiveRuleName(ActiveRuleName) == false) + throw new Exception($"Invalid {nameof(IActiveRule)} class type : {ActiveRuleName} in group : {GroupName}"); + foreach (var collector in Collectors) { collector.CheckConfigError(); @@ -49,6 +57,13 @@ namespace YooAsset.Editor { Dictionary result = new Dictionary(10000); + // 检测分组是否激活 + IActiveRule activeRule = AssetBundleCollectorSettingData.GetActiveRuleInstance(ActiveRuleName); + if (activeRule.IsActiveGroup() == false) + { + return new List(); + } + // 收集打包资源 foreach (var collector in Collectors) { diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSettingData.cs b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSettingData.cs index 6d1d158..29e851d 100644 --- a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSettingData.cs +++ b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSettingData.cs @@ -9,6 +9,9 @@ namespace YooAsset.Editor { public class AssetBundleCollectorSettingData { + private static readonly Dictionary _cacheActiveRuleTypes = new Dictionary(); + private static readonly Dictionary _cacheActiveRuleInstance = new Dictionary(); + private static readonly Dictionary _cacheAddressRuleTypes = new Dictionary(); private static readonly Dictionary _cacheAddressRuleInstance = new Dictionary(); @@ -35,6 +38,18 @@ namespace YooAsset.Editor } } + public static List GetActiveRuleNames() + { + if (_setting == null) + LoadSettingData(); + + List names = new List(); + foreach (var pair in _cacheActiveRuleTypes) + { + names.Add(pair.Key); + } + return names; + } public static List GetAddressRuleNames() { if (_setting == null) @@ -71,6 +86,15 @@ namespace YooAsset.Editor } return names; } + public static bool HasActiveRuleName(string ruleName) + { + foreach (var pair in _cacheActiveRuleTypes) + { + if (pair.Key == ruleName) + return true; + } + return false; + } public static bool HasAddressRuleName(string ruleName) { foreach (var pair in _cacheAddressRuleTypes) @@ -182,6 +206,29 @@ namespace YooAsset.Editor _cacheAddressRuleTypes.Add(type.Name, type); } } + + // IActiveRule + { + // 清空缓存集合 + _cacheActiveRuleTypes.Clear(); + _cacheActiveRuleInstance.Clear(); + + // 获取所有类型 + List types = new List(100) + { + typeof(EnableGroup), + typeof(DisableGroup), + }; + + var customTypes = EditorTools.GetAssignableTypes(typeof(IActiveRule)); + types.AddRange(customTypes); + for (int i = 0; i < types.Count; i++) + { + Type type = types[i]; + if (_cacheActiveRuleTypes.ContainsKey(type.Name) == false) + _cacheActiveRuleTypes.Add(type.Name, type); + } + } } /// @@ -210,6 +257,23 @@ namespace YooAsset.Editor } // 实例类相关 + public static IActiveRule GetActiveRuleInstance(string ruleName) + { + if (_cacheActiveRuleInstance.TryGetValue(ruleName, out IActiveRule instance)) + return instance; + + // 如果不存在创建类的实例 + if (_cacheActiveRuleTypes.TryGetValue(ruleName, out Type type)) + { + instance = (IActiveRule)Activator.CreateInstance(type); + _cacheActiveRuleInstance.Add(ruleName, instance); + return instance; + } + else + { + throw new Exception($"{nameof(IActiveRule)}类型无效:{ruleName}"); + } + } public static IAddressRule GetAddressRuleInstance(string ruleName) { if (_cacheAddressRuleInstance.TryGetValue(ruleName, out IAddressRule instance)) diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorWindow.cs b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorWindow.cs index 1dfc72f..07177fb 100644 --- a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorWindow.cs +++ b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorWindow.cs @@ -19,11 +19,13 @@ namespace YooAsset.Editor } private List _collectorTypeList; + private List _activeRuleList; private List _addressRuleList; private List _packRuleList; private List _filterRuleList; private ListView _groupListView; private ScrollView _collectorScrollView; + private PopupField _activeRulePopupField; private Toggle _enableAddressableToogle; private Toggle _autoCollectShaderToogle; private TextField _shaderBundleNameTxt; @@ -47,6 +49,7 @@ namespace YooAsset.Editor $"{nameof(ECollectorType.StaticAssetCollector)}", $"{nameof(ECollectorType.DependAssetCollector)}" }; + _activeRuleList = AssetBundleCollectorSettingData.GetActiveRuleNames(); _addressRuleList = AssetBundleCollectorSettingData.GetAddressRuleNames(); _packRuleList = AssetBundleCollectorSettingData.GetPackRuleNames(); _filterRuleList = AssetBundleCollectorSettingData.GetFilterRuleNames(); @@ -57,7 +60,7 @@ namespace YooAsset.Editor var visualAsset = EditorHelper.LoadWindowUXML(); if (visualAsset == null) return; - + visualAsset.CloneTree(root); // 导入导出按钮 @@ -155,6 +158,25 @@ namespace YooAsset.Editor addBtn.clicked += AddCollectorBtn_clicked; } + // 分组激活规则 + var activeRuleContainer = root.Q("ActiveRuleContainer"); + { + _activeRulePopupField = new PopupField("Active Rule", _activeRuleList, 0); + _activeRulePopupField.name = "ActiveRuleMaskField"; + _activeRulePopupField.style.unityTextAlign = TextAnchor.MiddleLeft; + activeRuleContainer.Add(_activeRulePopupField); + _activeRulePopupField.RegisterValueChangedCallback(evt => + { + var selectGroup = _groupListView.selectedItem as AssetBundleCollectorGroup; + if (selectGroup != null) + { + selectGroup.ActiveRuleName = evt.newValue; + AssetBundleCollectorSettingData.ModifyGroup(selectGroup); + FillGroupViewData(); + } + }); + } + // 刷新窗体 RefreshWindow(); } @@ -243,6 +265,11 @@ namespace YooAsset.Editor textField1.text = group.GroupName; else textField1.text = $"{group.GroupName} ({group.GroupDesc})"; + + // 激活状态 + IActiveRule activeRule = AssetBundleCollectorSettingData.GetActiveRuleInstance(group.ActiveRuleName); + bool isActive = activeRule.IsActiveGroup(); + textField1.SetEnabled(isActive); } private void GroupListView_onSelectionChange(IEnumerable objs) { @@ -277,6 +304,7 @@ namespace YooAsset.Editor _lastModifyGroup = selectGroup.GroupName; _groupContainer.visible = true; + _activeRulePopupField.SetValueWithoutNotify(selectGroup.ActiveRuleName); _groupNameTxt.SetValueWithoutNotify(selectGroup.GroupName); _groupDescTxt.SetValueWithoutNotify(selectGroup.GroupDesc); _groupAssetTagsTxt.SetValueWithoutNotify(selectGroup.AssetTags); diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorWindow.uxml b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorWindow.uxml index 03394fc..8db2028 100644 --- a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorWindow.uxml +++ b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorWindow.uxml @@ -18,6 +18,7 @@ + diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/DefaultActiveRule.cs b/Assets/YooAsset/Editor/AssetBundleCollector/DefaultActiveRule.cs new file mode 100644 index 0000000..9a6b6a6 --- /dev/null +++ b/Assets/YooAsset/Editor/AssetBundleCollector/DefaultActiveRule.cs @@ -0,0 +1,25 @@ + +namespace YooAsset.Editor +{ + /// + /// 启用分组 + /// + public class EnableGroup : IActiveRule + { + public bool IsActiveGroup() + { + return true; + } + } + + /// + /// 禁用分组 + /// + public class DisableGroup : IActiveRule + { + public bool IsActiveGroup() + { + return false; + } + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/DefaultActiveRule.cs.meta b/Assets/YooAsset/Editor/AssetBundleCollector/DefaultActiveRule.cs.meta new file mode 100644 index 0000000..5214d34 --- /dev/null +++ b/Assets/YooAsset/Editor/AssetBundleCollector/DefaultActiveRule.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2cfd65b3b7663b247b2df16077f4ef17 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/IActiveRule.cs b/Assets/YooAsset/Editor/AssetBundleCollector/IActiveRule.cs new file mode 100644 index 0000000..daba439 --- /dev/null +++ b/Assets/YooAsset/Editor/AssetBundleCollector/IActiveRule.cs @@ -0,0 +1,14 @@ + +namespace YooAsset.Editor +{ + /// + /// 资源分组激活规则接口 + /// + public interface IActiveRule + { + /// + /// 是否激活分组 + /// + bool IsActiveGroup(); + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/IActiveRule.cs.meta b/Assets/YooAsset/Editor/AssetBundleCollector/IActiveRule.cs.meta new file mode 100644 index 0000000..39822f6 --- /dev/null +++ b/Assets/YooAsset/Editor/AssetBundleCollector/IActiveRule.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: aed5a1a6733b7d44ca4f6149ed5a2bb8 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: