From 0c2f7a4801539f4b5b37706feb135fc3d57abcb8 Mon Sep 17 00:00:00 2001 From: Sakura-Luna <53183413+Sakura-Luna@users.noreply.github.com> Date: Mon, 13 Oct 2025 06:15:53 +0000 Subject: [PATCH] Add order to presets --- Editor/Helper/PresetHelper.cs | 10 ++++++++-- Editor/ScriptableObject/LwguiShaderPropertyPreset.cs | 4 ++++ Editor/ShaderDrawer.cs | 1 + 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Editor/Helper/PresetHelper.cs b/Editor/Helper/PresetHelper.cs index 9cc533a..7d89710 100644 --- a/Editor/Helper/PresetHelper.cs +++ b/Editor/Helper/PresetHelper.cs @@ -67,6 +67,7 @@ public static LwguiShaderPropertyPreset GetPresetAsset(string presetFileName) public static void ApplyPresetsInMaterial(Material material) { var props = MaterialEditor.GetMaterialProperties(new UnityEngine.Object[] { material }); + var presets = new List(); foreach (var prop in props) { var drawer = ReflectionHelper.GetPropertyDrawer(material.shader, prop, out _); @@ -75,10 +76,15 @@ public static void ApplyPresetsInMaterial(Material material) if (drawer is IPresetDrawer presetDrawer) { var activePreset = presetDrawer.GetActivePreset(prop, GetPresetAsset(presetDrawer.GetPresetFileName())); - activePreset?.ApplyToDefaultMaterial(material); + if (activePreset?.order > -1) presets.Add(activePreset); } } - UnityEditorExtension.ApplyMaterialPropertyAndDecoratorDrawers(material); + if (presets.Count > 0) + { + presets.Sort((x, y) => x.order.CompareTo(y.order)); + foreach (var preset in presets) preset.ApplyToDefaultMaterial(material); + UnityEditorExtension.ApplyMaterialPropertyAndDecoratorDrawers(material); + } } } } \ No newline at end of file diff --git a/Editor/ScriptableObject/LwguiShaderPropertyPreset.cs b/Editor/ScriptableObject/LwguiShaderPropertyPreset.cs index 6276e7a..4c862ee 100644 --- a/Editor/ScriptableObject/LwguiShaderPropertyPreset.cs +++ b/Editor/ScriptableObject/LwguiShaderPropertyPreset.cs @@ -22,6 +22,9 @@ public enum PropertyType Integer, } + [SerializeField] + public int order; + [Serializable] public class PropertyValue { @@ -161,6 +164,7 @@ public class Preset public List enabledPasses = new List(); public List disabledPasses = new List(); public int renderQueue = -1; + public int order = -1; public void ApplyToDefaultMaterial(Material material) diff --git a/Editor/ShaderDrawer.cs b/Editor/ShaderDrawer.cs index eaed7de..43f5e6f 100644 --- a/Editor/ShaderDrawer.cs +++ b/Editor/ShaderDrawer.cs @@ -724,6 +724,7 @@ public static LwguiShaderPropertyPreset.Preset GetActivePresetFromFloatProperty( if (lwguiShaderPropertyPreset && index >= 0 && index < lwguiShaderPropertyPreset.GetPresetCount()) { preset = lwguiShaderPropertyPreset.GetPreset(index); + preset.order = index != 0 ? lwguiShaderPropertyPreset.order : -1; } return preset; }