From fe95b8ec5d5e65b91a8c3211c1368c3af8927962 Mon Sep 17 00:00:00 2001 From: hevinci Date: Wed, 3 Aug 2022 15:37:01 +0800 Subject: [PATCH] Update AssetBundleCollector --- .../AssetBundleCollector.cs | 29 ++++++------------- .../AssetBundleCollectorConfig.cs | 15 ---------- .../AssetBundleCollectorSetting.cs | 10 ------- .../AssetBundleCollectorSettingData.cs | 11 +------ .../AssetBundleCollectorWindow.cs | 16 ---------- .../AssetBundleCollectorWindow.uxml | 2 -- .../AssetBundleCollector/DefaultFilterRule.cs | 11 +++++++ .../AssetBundleCollector/DefaultPackRule.cs | 11 +++++++ 8 files changed, 32 insertions(+), 73 deletions(-) diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollector.cs b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollector.cs index cd0d742..0cef4e3 100644 --- a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollector.cs +++ b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollector.cs @@ -214,13 +214,9 @@ namespace YooAsset.Editor } private bool IsCollectAsset(string assetPath) { - // 如果收集全路径着色器 - if (AssetBundleCollectorSettingData.Setting.AutoCollectShaders) - { - Type assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath); - if (assetType == typeof(UnityEngine.Shader)) - return true; - } + Type assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath); + if (assetType == typeof(UnityEngine.Shader)) + return true; // 根据规则设置过滤资源文件 IFilterRule filterRuleInstance = AssetBundleCollectorSettingData.GetFilterRuleInstance(FilterRuleName); @@ -237,23 +233,16 @@ namespace YooAsset.Editor } private string GetBundleName(AssetBundleCollectorGroup group, string assetPath) { - // 如果自动收集所有的着色器 - if (AssetBundleCollectorSettingData.Setting.AutoCollectShaders) + System.Type assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath); + if (assetType == typeof(UnityEngine.Shader)) { - System.Type assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath); - if (assetType == typeof(UnityEngine.Shader)) - { - string bundleName = AssetBundleCollectorSettingData.Setting.ShadersBundleName; - return EditorTools.GetRegularPath(bundleName).ToLower(); - } + return EditorTools.GetRegularPath(YooAssetSettings.UnityShadersBundleName).ToLower(); } // 根据规则设置获取资源包名称 - { - IPackRule packRuleInstance = AssetBundleCollectorSettingData.GetPackRuleInstance(PackRuleName); - string bundleName = packRuleInstance.GetBundleName(new PackRuleData(assetPath, CollectPath, group.GroupName)); - return EditorTools.GetRegularPath(bundleName).ToLower(); - } + IPackRule packRuleInstance = AssetBundleCollectorSettingData.GetPackRuleInstance(PackRuleName); + string bundleName = packRuleInstance.GetBundleName(new PackRuleData(assetPath, CollectPath, group.GroupName)); + return EditorTools.GetRegularPath(bundleName).ToLower(); } private List GetAssetTags(AssetBundleCollectorGroup group) { diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorConfig.cs b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorConfig.cs index c9577cd..58b9159 100644 --- a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorConfig.cs +++ b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorConfig.cs @@ -15,8 +15,6 @@ namespace YooAsset.Editor public const string XmlVersion = "Version"; public const string XmlCommon = "Common"; public const string XmlEnableAddressable = "AutoAddressable"; - public const string XmlAutoCollectShader = "AutoCollectShader"; - public const string XmlShaderBundleName = "ShaderBundleName"; public const string XmlGroup = "Group"; public const string XmlGroupName = "GroupName"; public const string XmlGroupDesc = "GroupDesc"; @@ -53,22 +51,13 @@ namespace YooAsset.Editor // 读取公共配置 bool enableAddressable = false; - bool autoCollectShaders = false; - string shaderBundleName = string.Empty; var commonNodeList = root.GetElementsByTagName(XmlCommon); if (commonNodeList.Count > 0) { XmlElement commonElement = commonNodeList[0] as XmlElement; if (commonElement.HasAttribute(XmlEnableAddressable) == false) throw new Exception($"Not found attribute {XmlEnableAddressable} in {XmlCommon}"); - if (commonElement.HasAttribute(XmlAutoCollectShader) == false) - throw new Exception($"Not found attribute {XmlAutoCollectShader} in {XmlCommon}"); - if (commonElement.HasAttribute(XmlShaderBundleName) == false) - throw new Exception($"Not found attribute {XmlShaderBundleName} in {XmlCommon}"); - enableAddressable = commonElement.GetAttribute(XmlEnableAddressable) == "True" ? true : false; - autoCollectShaders = commonElement.GetAttribute(XmlAutoCollectShader) == "True" ? true : false; - shaderBundleName = commonElement.GetAttribute(XmlShaderBundleName); } // 读取分组配置 @@ -122,8 +111,6 @@ namespace YooAsset.Editor // 保存配置数据 AssetBundleCollectorSettingData.ClearAll(); AssetBundleCollectorSettingData.Setting.EnableAddressable = enableAddressable; - AssetBundleCollectorSettingData.Setting.AutoCollectShaders = autoCollectShaders; - AssetBundleCollectorSettingData.Setting.ShadersBundleName = shaderBundleName; AssetBundleCollectorSettingData.Setting.Groups.AddRange(groupTemper); AssetBundleCollectorSettingData.SaveFile(); Debug.Log($"导入配置完毕!"); @@ -152,8 +139,6 @@ namespace YooAsset.Editor // 设置公共配置 var commonElement = xmlDoc.CreateElement(XmlCommon); commonElement.SetAttribute(XmlEnableAddressable, AssetBundleCollectorSettingData.Setting.EnableAddressable.ToString()); - commonElement.SetAttribute(XmlAutoCollectShader, AssetBundleCollectorSettingData.Setting.AutoCollectShaders.ToString()); - commonElement.SetAttribute(XmlShaderBundleName, AssetBundleCollectorSettingData.Setting.ShadersBundleName); root.AppendChild(commonElement); // 设置分组配置 diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSetting.cs b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSetting.cs index 853a450..bb37e7b 100644 --- a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSetting.cs +++ b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSetting.cs @@ -13,16 +13,6 @@ namespace YooAsset.Editor /// public bool EnableAddressable = false; - /// - /// 自动收集着色器 - /// - public bool AutoCollectShaders = true; - - /// - /// 自动收集的着色器资源包名称 - /// - public string ShadersBundleName = "myshaders"; - /// /// 分组列表 /// diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSettingData.cs b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSettingData.cs index 2e6ad8a..d063390 100644 --- a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSettingData.cs +++ b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSettingData.cs @@ -250,8 +250,7 @@ namespace YooAsset.Editor /// public static void ClearAll() { - Setting.AutoCollectShaders = false; - Setting.ShadersBundleName = string.Empty; + Setting.EnableAddressable = false; Setting.Groups.Clear(); SaveFile(); } @@ -333,14 +332,6 @@ namespace YooAsset.Editor IsDirty = true; } - // 着色器编辑相关 - public static void ModifyShader(bool isCollectAllShaders, string shadersBundleName) - { - Setting.AutoCollectShaders = isCollectAllShaders; - Setting.ShadersBundleName = shadersBundleName; - IsDirty = true; - } - // 资源分组编辑相关 public static void CreateGroup(string groupName) { diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorWindow.cs b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorWindow.cs index 7565a0c..088e824 100644 --- a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorWindow.cs +++ b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorWindow.cs @@ -28,8 +28,6 @@ namespace YooAsset.Editor private ScrollView _collectorScrollView; private PopupField _activeRulePopupField; private Toggle _enableAddressableToogle; - private Toggle _autoCollectShaderToogle; - private TextField _shaderBundleNameTxt; private TextField _groupNameTxt; private TextField _groupDescTxt; private TextField _groupAssetTagsTxt; @@ -81,17 +79,6 @@ namespace YooAsset.Editor AssetBundleCollectorSettingData.ModifyAddressable(evt.newValue); RefreshWindow(); }); - _autoCollectShaderToogle = root.Q("AutoCollectShader"); - _autoCollectShaderToogle.RegisterValueChangedCallback(evt => - { - AssetBundleCollectorSettingData.ModifyShader(evt.newValue, _shaderBundleNameTxt.value); - _shaderBundleNameTxt.SetEnabled(evt.newValue); - }); - _shaderBundleNameTxt = root.Q("ShaderBundleName"); - _shaderBundleNameTxt.RegisterValueChangedCallback(evt => - { - AssetBundleCollectorSettingData.ModifyShader(_autoCollectShaderToogle.value, evt.newValue); - }); // 分组列表相关 _groupListView = root.Q("GroupListView"); @@ -218,9 +205,6 @@ namespace YooAsset.Editor private void RefreshWindow() { _enableAddressableToogle.SetValueWithoutNotify(AssetBundleCollectorSettingData.Setting.EnableAddressable); - _autoCollectShaderToogle.SetValueWithoutNotify(AssetBundleCollectorSettingData.Setting.AutoCollectShaders); - _shaderBundleNameTxt.SetEnabled(AssetBundleCollectorSettingData.Setting.AutoCollectShaders); - _shaderBundleNameTxt.SetValueWithoutNotify(AssetBundleCollectorSettingData.Setting.ShadersBundleName); _groupContainer.visible = false; FillGroupViewData(); diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorWindow.uxml b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorWindow.uxml index 5e56fad..87c5d3c 100644 --- a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorWindow.uxml +++ b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorWindow.uxml @@ -15,8 +15,6 @@ - - diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/DefaultFilterRule.cs b/Assets/YooAsset/Editor/AssetBundleCollector/DefaultFilterRule.cs index 24e80a7..916698b 100644 --- a/Assets/YooAsset/Editor/AssetBundleCollector/DefaultFilterRule.cs +++ b/Assets/YooAsset/Editor/AssetBundleCollector/DefaultFilterRule.cs @@ -59,4 +59,15 @@ namespace YooAsset.Editor } } } + + /// + /// 只收集着色器变种收集文件 + /// + public class CollectShaderVariants : IFilterRule + { + public bool IsCollectAsset(FilterRuleData data) + { + return Path.GetExtension(data.AssetPath) == ".shadervariants"; + } + } } \ No newline at end of file diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/DefaultPackRule.cs b/Assets/YooAsset/Editor/AssetBundleCollector/DefaultPackRule.cs index d081c58..bd34ff3 100644 --- a/Assets/YooAsset/Editor/AssetBundleCollector/DefaultPackRule.cs +++ b/Assets/YooAsset/Editor/AssetBundleCollector/DefaultPackRule.cs @@ -113,4 +113,15 @@ namespace YooAsset.Editor return StringUtility.RemoveExtension(data.AssetPath); } } + + /// + /// 着色器变种收集文件 + /// + public class PackShaderVariants : IPackRule + { + public string GetBundleName(PackRuleData data) + { + return YooAssetSettings.UnityShadersBundleName; + } + } } \ No newline at end of file