Skip to content

Commit

Permalink
Merge pull request #69 from JasonMa0012/2.x
Browse files Browse the repository at this point in the history
Fix OnValidate event on undo
  • Loading branch information
JasonMa0012 authored Nov 18, 2024
2 parents 029b06f + a06dadb commit ff69045
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
6 changes: 0 additions & 6 deletions Editor/Helper/MetaDataHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 24 additions & 2 deletions Editor/LWGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions Editor/ShaderDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1083,7 +1083,7 @@ void OnSwitchRampMapEvent(Texture2D newRampMap)
LwguiGradientWindow.CloseWindow();
prop.textureValue = newRampMap;
OnSwitchRampMap(prop.textureValue);
metaDatas.OnValidate();
LWGUI.OnValidate(metaDatas);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down

0 comments on commit ff69045

Please sign in to comment.