From 92de92bd7a79bec7217ac5d5f2ac62e64b57fe76 Mon Sep 17 00:00:00 2001 From: Jason Ma <1312119064@qq.com> Date: Mon, 18 Nov 2024 17:27:16 +0800 Subject: [PATCH 1/2] Fix OnValidate event on undo --- Editor/Helper/MetaDataHelper.cs | 6 ------ Editor/LWGUI.cs | 26 ++++++++++++++++++++++++-- Editor/ShaderDrawer.cs | 4 ++-- package.json | 2 +- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/Editor/Helper/MetaDataHelper.cs b/Editor/Helper/MetaDataHelper.cs index cac4f91..db9ea18 100644 --- a/Editor/Helper/MetaDataHelper.cs +++ b/Editor/Helper/MetaDataHelper.cs @@ -49,12 +49,6 @@ public class LWGUIMetaDatas public Shader GetShader() => perShaderData.shader; public MaterialEditor GetMaterialEditor() => perInspectorData.materialEditor; - - public void OnValidate() - { - UnityEditorExtension.ApplyMaterialPropertyAndDecoratorDrawers(GetMaterialEditor()?.targets); - MetaDataHelper.ForceUpdateMaterialsMetadataCache(GetMaterialEditor()?.targets); - } } public class MetaDataHelper diff --git a/Editor/LWGUI.cs b/Editor/LWGUI.cs index d6ddfbc..a7a37b7 100644 --- a/Editor/LWGUI.cs +++ b/Editor/LWGUI.cs @@ -185,11 +185,33 @@ public override void AssignNewShaderToMaterial(Material material, Shader oldShad MetaDataHelper.ReleaseMaterialMetadataCache(material); } - // Called after editing the material + public static void OnValidate(Object[] materials) + { + UnityEditorExtension.ApplyMaterialPropertyAndDecoratorDrawers(materials); + MetaDataHelper.ForceUpdateMaterialsMetadataCache(materials); + } + + // Called after editing in code + public static void OnValidate(LWGUIMetaDatas metaDatas) + { + OnValidate(metaDatas?.GetMaterialEditor()?.targets); + OnValidate(metaDatas?.GetMaterialEditor()?.targets); + } + + // Called after editing or undoing the material public override void ValidateMaterial(Material material) { base.ValidateMaterial(material); - metaDatas?.OnValidate(); + // Undoing + if (metaDatas == null) + { + OnValidate(new Object[] { material }); + } + // Editing + else + { + OnValidate(metaDatas); + } } } } //namespace LWGUI \ No newline at end of file diff --git a/Editor/ShaderDrawer.cs b/Editor/ShaderDrawer.cs index 5f2012e..7632dd3 100644 --- a/Editor/ShaderDrawer.cs +++ b/Editor/ShaderDrawer.cs @@ -1021,7 +1021,7 @@ public override void DrawProp(Rect position, MaterialProperty prop, GUIContent l LwguiGradientWindow.CloseWindow(); prop.textureValue = newCreatedTexture; OnCreateNewRampMap(prop.textureValue); - metaDatas.OnValidate(); + LWGUI.OnValidate(metaDatas); } // Save gradient changes @@ -1083,7 +1083,7 @@ void OnSwitchRampMapEvent(Texture2D newRampMap) LwguiGradientWindow.CloseWindow(); prop.textureValue = newRampMap; OnSwitchRampMap(prop.textureValue); - metaDatas.OnValidate(); + LWGUI.OnValidate(metaDatas); } } } diff --git a/package.json b/package.json index d7c74d8..e18fca5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.jasonma.lwgui", - "version": "1.19.4", + "version": "1.19.5", "displayName": "LWGUI", "description": "A Lightweight, Flexible, Powerful Shader GUI System for Unity.", "keywords": [ From a06dadbf3f9c38d6101e54040ed065da4324949e Mon Sep 17 00:00:00 2001 From: Jason Ma <1312119064@qq.com> Date: Mon, 18 Nov 2024 17:33:56 +0800 Subject: [PATCH 2/2] Update comment --- Editor/LWGUI.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Editor/LWGUI.cs b/Editor/LWGUI.cs index a7a37b7..15bd16d 100644 --- a/Editor/LWGUI.cs +++ b/Editor/LWGUI.cs @@ -191,23 +191,23 @@ public static void OnValidate(Object[] materials) MetaDataHelper.ForceUpdateMaterialsMetadataCache(materials); } - // Called after editing in code + // Called after edit in code public static void OnValidate(LWGUIMetaDatas metaDatas) { OnValidate(metaDatas?.GetMaterialEditor()?.targets); OnValidate(metaDatas?.GetMaterialEditor()?.targets); } - // Called after editing or undoing the material + // Called after edit or undo public override void ValidateMaterial(Material material) { base.ValidateMaterial(material); - // Undoing + // Undo if (metaDatas == null) { OnValidate(new Object[] { material }); } - // Editing + // Edit else { OnValidate(metaDatas);