Skip to content

Commit

Permalink
Fixed keywords and presets being applied incorrectly when editing mul…
Browse files Browse the repository at this point in the history
…tiple materials
  • Loading branch information
JasonMa0012 committed Jan 8, 2025
1 parent bcc01b0 commit 8bed3ae
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
1 change: 0 additions & 1 deletion Editor/LWGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ public static void OnValidate(Object[] materials)
public static void OnValidate(LWGUIMetaDatas metaDatas)
{
OnValidate(metaDatas?.GetMaterialEditor()?.targets);
OnValidate(metaDatas?.GetMaterialEditor()?.targets);
}

// Called after edit or undo
Expand Down
33 changes: 24 additions & 9 deletions Editor/ShaderDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,15 @@ public override float GetPropertyHeight(MaterialProperty prop, string label, Mat
return _height;
}

// Call when creating new material, used to set keywords
// Call when create/edit/undo materials, used to set keywords and presets
public override void Apply(MaterialProperty prop)
{
base.Apply(prop);
Helper.SetShaderKeyWord(prop.targets, Helper.GetKeyWord(_keyword, prop.name), prop.floatValue > 0f);
PresetDrawer.ApplyPreset(_presetFileName, prop);
if (!prop.hasMixedValue)
{
Helper.SetShaderKeyWord(prop.targets, Helper.GetKeyWord(_keyword, prop.name), prop.floatValue > 0f);
PresetDrawer.ApplyPreset(_presetFileName, prop);
}
}
}

Expand Down Expand Up @@ -248,8 +251,11 @@ public override void DrawProp(Rect position, MaterialProperty prop, GUIContent l
public override void Apply(MaterialProperty prop)
{
base.Apply(prop);
Helper.SetShaderKeyWord(prop.targets, Helper.GetKeyWord(_keyWord, prop.name), prop.floatValue > 0f);
PresetDrawer.ApplyPreset(_presetFileName, prop);
if (!prop.hasMixedValue)
{
Helper.SetShaderKeyWord(prop.targets, Helper.GetKeyWord(_keyWord, prop.name), prop.floatValue > 0f);
PresetDrawer.ApplyPreset(_presetFileName, prop);
}
}
}

Expand Down Expand Up @@ -561,7 +567,10 @@ public override void DrawProp(Rect position, MaterialProperty prop, GUIContent l
public override void Apply(MaterialProperty prop)
{
base.Apply(prop);
Helper.SetShaderKeyWord(prop.targets, GetKeywords(prop), (int)prop.floatValue);
if (!prop.hasMixedValue)
{
Helper.SetShaderKeyWord(prop.targets, GetKeywords(prop), (int)prop.floatValue);
}
}
}

Expand Down Expand Up @@ -1236,7 +1245,10 @@ public override void DrawProp(Rect position, MaterialProperty prop, GUIContent l
public override void Apply(MaterialProperty prop)
{
base.Apply(prop);
ApplyPreset(presetFileName, prop);
if (!prop.hasMixedValue)
{
ApplyPreset(presetFileName, prop);
}
}
}

Expand Down Expand Up @@ -1579,8 +1591,11 @@ public override void DrawProp(Rect position, MaterialProperty prop, GUIContent l
public override void Apply(MaterialProperty prop)
{
base.Apply(prop);
if (ShowIfDecorator.GetShowIfResultToFilterDrawerApplying(prop))
Helper.SetShaderPassEnabled(prop.targets, _lightModeNames, prop.floatValue > 0);
if (!prop.hasMixedValue)
{
if (ShowIfDecorator.GetShowIfResultToFilterDrawerApplying(prop))
Helper.SetShaderPassEnabled(prop.targets, _lightModeNames, prop.floatValue > 0);
}
}
}

Expand Down
1 change: 1 addition & 0 deletions UnityEditorExtension/UnityEditorExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public static void ApplyMaterialPropertyAndDecoratorDrawers(Material material)
ApplyMaterialPropertyAndDecoratorDrawers(objs);
}

// Called after edit or undo
public static void ApplyMaterialPropertyAndDecoratorDrawers(Object[] targets)
{
if (!EditorMaterialUtility.disableApplyMaterialPropertyDrawers)
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.21.0",
"version": "1.21.1",
"displayName": "LWGUI",
"description": "A Lightweight, Flexible, Powerful Shader GUI System for Unity.",
"keywords": [
Expand Down

0 comments on commit 8bed3ae

Please sign in to comment.