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..15bd16d 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 edit in code + public static void OnValidate(LWGUIMetaDatas metaDatas) + { + OnValidate(metaDatas?.GetMaterialEditor()?.targets); + OnValidate(metaDatas?.GetMaterialEditor()?.targets); + } + + // Called after edit or undo public override void ValidateMaterial(Material material) { base.ValidateMaterial(material); - metaDatas?.OnValidate(); + // Undo + if (metaDatas == null) + { + OnValidate(new Object[] { material }); + } + // Edit + 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": [