diff --git a/Assets/YooAsset/Editor/EditorDefine.cs b/Assets/YooAsset/Editor/EditorDefine.cs index 2fed369..79b729b 100644 --- a/Assets/YooAsset/Editor/EditorDefine.cs +++ b/Assets/YooAsset/Editor/EditorDefine.cs @@ -14,8 +14,16 @@ namespace YooAsset.Editor /// 资源包分组工具的配置文件存储路径 /// public const string AssetBundleGrouperSettingFilePath = "Assets/YooAssetSetting/AssetBundleGrouperSetting.asset"; - - public static readonly Type[] DockedWindowTypes = { typeof(AssetBundleBuilderWindow), typeof(AssetBundleGrouperWindow), typeof(AssetBundleDebuggerWindow), typeof(AssetBundleReporterWindow) , typeof(ShaderVariantCollectionWindow)}; + + /// + /// 着色器变种收集工具的配置文件存储路径 + /// + public const string ShaderVariantCollectorSettingFilePath = "Assets/YooAssetSetting/ShaderVariantCollectorSetting.asset"; + + /// + /// 停靠窗口类型集合 + /// + public static readonly Type[] DockedWindowTypes = { typeof(AssetBundleBuilderWindow), typeof(AssetBundleGrouperWindow), typeof(AssetBundleDebuggerWindow), typeof(AssetBundleReporterWindow)}; } /// diff --git a/Assets/YooAsset/Editor/ShaderVariantCollector/ShaderVariantCollectorSetting.cs b/Assets/YooAsset/Editor/ShaderVariantCollector/ShaderVariantCollectorSetting.cs new file mode 100644 index 0000000..d7e9851 --- /dev/null +++ b/Assets/YooAsset/Editor/ShaderVariantCollector/ShaderVariantCollectorSetting.cs @@ -0,0 +1,12 @@ +using UnityEngine; + +namespace YooAsset.Editor +{ + public class ShaderVariantCollectorSetting : ScriptableObject + { + /// + /// 文件存储路径 + /// + public string SavePath = "Assets/MyShaderVariants.shadervariants"; + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Editor/ShaderVariantCollector/ShaderVariantCollectorSetting.cs.meta b/Assets/YooAsset/Editor/ShaderVariantCollector/ShaderVariantCollectorSetting.cs.meta new file mode 100644 index 0000000..b9566a8 --- /dev/null +++ b/Assets/YooAsset/Editor/ShaderVariantCollector/ShaderVariantCollectorSetting.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 44454e58a49818040a1aef5799e71b30 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Editor/ShaderVariantCollector/ShaderVariantCollectorSettingData.cs b/Assets/YooAsset/Editor/ShaderVariantCollector/ShaderVariantCollectorSettingData.cs new file mode 100644 index 0000000..62a740d --- /dev/null +++ b/Assets/YooAsset/Editor/ShaderVariantCollector/ShaderVariantCollectorSettingData.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using UnityEngine; +using UnityEditor; + +namespace YooAsset.Editor +{ + public class ShaderVariantCollectorSettingData + { + private static ShaderVariantCollectorSetting _setting = null; + public static ShaderVariantCollectorSetting Setting + { + get + { + if (_setting == null) + LoadSettingData(); + return _setting; + } + } + + /// + /// 加载配置文件 + /// + private static void LoadSettingData() + { + // 加载配置文件 + _setting = AssetDatabase.LoadAssetAtPath(EditorDefine.ShaderVariantCollectorSettingFilePath); + if (_setting == null) + { + Debug.LogWarning($"Create new {nameof(ShaderVariantCollectorSetting)}.asset : {EditorDefine.ShaderVariantCollectorSettingFilePath}"); + _setting = ScriptableObject.CreateInstance(); + EditorTools.CreateFileDirectory(EditorDefine.ShaderVariantCollectorSettingFilePath); + AssetDatabase.CreateAsset(Setting, EditorDefine.ShaderVariantCollectorSettingFilePath); + AssetDatabase.SaveAssets(); + AssetDatabase.Refresh(); + } + else + { + Debug.Log($"Load {nameof(ShaderVariantCollectorSetting)}.asset ok"); + } + } + + /// + /// 存储文件 + /// + public static void SaveFile() + { + if (Setting != null) + { + EditorUtility.SetDirty(Setting); + AssetDatabase.SaveAssets(); + Debug.Log($"{nameof(ShaderVariantCollectorSetting)}.asset is saved!"); + } + } + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Editor/ShaderVariantCollector/ShaderVariantCollectorSettingData.cs.meta b/Assets/YooAsset/Editor/ShaderVariantCollector/ShaderVariantCollectorSettingData.cs.meta new file mode 100644 index 0000000..cfd2f74 --- /dev/null +++ b/Assets/YooAsset/Editor/ShaderVariantCollector/ShaderVariantCollectorSettingData.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b3043e89ff35bd346b268c0e8d460067 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Editor/ShaderVariantCollector/ShaderVariantCollectorWindow.cs b/Assets/YooAsset/Editor/ShaderVariantCollector/ShaderVariantCollectorWindow.cs index a34b33b..1652885 100644 --- a/Assets/YooAsset/Editor/ShaderVariantCollector/ShaderVariantCollectorWindow.cs +++ b/Assets/YooAsset/Editor/ShaderVariantCollector/ShaderVariantCollectorWindow.cs @@ -12,19 +12,18 @@ namespace YooAsset.Editor { if (_thisInstance == null) { - _thisInstance = GetWindow("ShaderVariant Collector", true, EditorDefine.DockedWindowTypes); + _thisInstance = GetWindow("着色器变种收集工具"); _thisInstance.minSize = new Vector2(800, 600); } _thisInstance.Show(); } - private string _saveFilePath = "Assets/MyShaderVariants.shadervariants"; private ShaderVariantCollection _selectSVC; private void OnGUI() { EditorGUILayout.Space(); - _saveFilePath = EditorGUILayout.TextField("收集文件保存路径", _saveFilePath); + ShaderVariantCollectorSettingData.Setting.SavePath = EditorGUILayout.TextField("收集文件保存路径", ShaderVariantCollectorSettingData.Setting.SavePath); int currentShaderCount = ShaderVariantCollector.GetCurrentShaderVariantCollectionShaderCount(); int currentVariantCount = ShaderVariantCollector.GetCurrentShaderVariantCollectionVariantCount(); @@ -35,7 +34,7 @@ namespace YooAsset.Editor EditorGUILayout.Space(); if (GUILayout.Button("搜集变种", GUILayout.MaxWidth(80))) { - ShaderVariantCollector.Run(_saveFilePath); + ShaderVariantCollector.Run(ShaderVariantCollectorSettingData.Setting.SavePath); } // 查询 @@ -54,5 +53,9 @@ namespace YooAsset.Editor EditorGUILayout.LabelField($"VariantCount : {_selectSVC.variantCount}"); } } + private void OnDestroy() + { + ShaderVariantCollectorSettingData.SaveFile(); + } } } \ No newline at end of file