Skip to content

Commit

Permalink
fix revert button in Advanced()
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonMa0012 committed Oct 27, 2023
1 parent c5bae10 commit 3b26e55
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Editor/LWGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] pro
var rect = EditorGUILayout.GetControlRect();
var revertButtonRect = RevertableHelper.SplitRevertButtonRect(ref rect);
var label = string.IsNullOrEmpty(propStaticData.advancedHeaderString) ? "Advanced" : propStaticData.advancedHeaderString;
RevertableHelper.DrawRevertableProperty(revertButtonRect, prop, this);
propStaticData.isExpanding = EditorGUI.Foldout(rect, propStaticData.isExpanding, label);
RevertableHelper.DrawRevertableProperty(revertButtonRect, prop, this, true);

if (!propStaticData.isExpanding)
{
Expand Down Expand Up @@ -161,9 +161,9 @@ private void DrawProperty(MaterialProperty prop)
Helper.BeginProperty(rect, prop, this);
Helper.DoPropertyContextMenus(rect, prop, this);
RevertableHelper.FixGUIWidthMismatch(prop.type, materialEditor);
RevertableHelper.DrawRevertableProperty(revertButtonRect, prop, this);
if (propStaticData.isAdvancedHeaderProperty)
propStaticData.isExpanding = EditorGUI.Foldout(rect, propStaticData.isExpanding, string.Empty);
RevertableHelper.DrawRevertableProperty(revertButtonRect, prop, this, propStaticData.isMain || propStaticData.isAdvancedHeaderProperty);
materialEditor.ShaderProperty(rect, prop, label);
Helper.EndProperty(this, prop);
}
Expand Down
11 changes: 8 additions & 3 deletions Editor/MetaDataHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ public void BuildPropertyStaticData(Shader shader, MaterialProperty[] props)
// Build Display Mode Data
{
PropertyStaticData lastPropData = null;
PropertyStaticData lastHeaderPropData = null;
for (int i = 0; i < props.Length; i++)
{
var prop = props[i];
Expand Down Expand Up @@ -201,12 +202,15 @@ public void BuildPropertyStaticData(Shader shader, MaterialProperty[] props)
&& propStaticData.advancedHeaderString != lastPropData.advancedHeaderString))
{
propStaticData.isAdvancedHeader = true;
lastHeaderPropData = propStaticData;
}
// Else set to child
else
{
propStaticData.parent = lastPropData.isAdvancedHeader ? lastPropData : lastPropData.parent;
propStaticData.parent = lastHeaderPropData;
lastHeaderPropData.children.Add(propStaticData);
}

}

lastPropData = propStaticData;
Expand Down Expand Up @@ -338,6 +342,7 @@ public class PropertyDynamicData
public MaterialProperty defualtProperty; // Default values may be overridden by Preset
public string defaultValueDescription = string.Empty; // Description of the default values used in Tooltip
public bool hasModified = false; // Are properties modified in the material?
public bool hasChildrenModified = false; // Are Children properties modified in the material?
public bool hasRevertChanged = false; // Used to call property EndChangeCheck()
public bool isShowing = true; // ShowIf() result

Expand Down Expand Up @@ -428,9 +433,9 @@ public void BuildPerFrameData(Shader shader, Material material, MaterialProperty
var parentPropData = propStaticData.parent;
if (parentPropData != null)
{
propertyDatas[parentPropData.name].hasModified = true;
propertyDatas[parentPropData.name].hasChildrenModified = true;
if (parentPropData.parent != null)
propertyDatas[parentPropData.parent.name].hasModified = true;
propertyDatas[parentPropData.parent.name].hasChildrenModified = true;
}
}

Expand Down
5 changes: 4 additions & 1 deletion Editor/RevertableHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public static string GetPropertyDefaultValueText(MaterialProperty defaultProp)

#region Draw revert button

public static bool DrawRevertableProperty(Rect position, MaterialProperty prop, LWGUI lwgui)
public static bool DrawRevertableProperty(Rect position, MaterialProperty prop, LWGUI lwgui, bool isHeader = false)
{
bool hasModified = prop.hasMixedValue;

Expand All @@ -126,6 +126,9 @@ public static bool DrawRevertableProperty(Rect position, MaterialProperty prop,
if (!hasModified)
hasModified = propDynamicData.hasModified;

if (!hasModified && isHeader)
hasModified = propDynamicData.hasChildrenModified;

var extraPropNames = lwgui.perShaderData.propertyDatas[prop.name].extraPropNames;
if (!hasModified && extraPropNames.Count > 0)
hasModified = extraPropNames.Any((extraPropName => lwgui.perFrameData.propertyDatas[extraPropName].hasModified));
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.13.1",
"version": "1.13.2",
"displayName": "LWGUI",
"description": "A Lightweight, Flexible, Powerful Shader GUI System for Unity.",
"keywords": [
Expand Down

0 comments on commit 3b26e55

Please sign in to comment.