Skip to content

Commit

Permalink
Add ReadOnly()
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonMa0012 committed Jan 19, 2024
1 parent 96b79b5 commit f15f869
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 3 deletions.
1 change: 1 addition & 0 deletions Editor/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,7 @@ public static void DoPropertyContextMenus(Rect rect, MaterialProperty prop, LWGU
}
}
};

if (_copiedMaterial != null && _copiedProps.Count > 0 && GUI.enabled)
menus.AddItem(new GUIContent("Paste"), false, pasteAction);
else
Expand Down
3 changes: 3 additions & 0 deletions Editor/LWGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ private void DrawProperty(MaterialProperty prop)

var revertButtonRect = RevertableHelper.SplitRevertButtonRect(ref rect);

var enabled = GUI.enabled;
if (propStaticData.isReadOnly) GUI.enabled = false;
Helper.BeginProperty(rect, prop, this);
Helper.DoPropertyContextMenus(rect, prop, this);
RevertableHelper.FixGUIWidthMismatch(prop.type, materialEditor);
Expand All @@ -174,6 +176,7 @@ private void DrawProperty(MaterialProperty prop)
RevertableHelper.DrawRevertableProperty(revertButtonRect, prop, this, propStaticData.isMain || propStaticData.isAdvancedHeaderProperty);
materialEditor.ShaderProperty(rect, prop, label);
Helper.EndProperty(this, prop);
GUI.enabled = enabled;
}
}
} //namespace LWGUI
1 change: 1 addition & 0 deletions Editor/MetaDataHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public class PropertyStaticData
public bool isSearchMatched = true; // Draws when the search match is successful
public bool isExpanding = false; // Draws when the group is expanding
public bool isHidden = false; // [Hidden]
public bool isReadOnly = false; // [ReadOnly]
public List<ShowIfData> showIfDatas = new List<ShowIfData>(); // [ShowIf()]

// Metadata
Expand Down
15 changes: 15 additions & 0 deletions Editor/ShaderDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1345,6 +1345,21 @@ public override void BuildStaticMetaData(Shader inShader, MaterialProperty inPro
public override void DrawProp(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor) { }
}

/// <summary>
/// Set the property to read-only.
/// </summary>
public class ReadOnlyDecorator : SubDrawer
{
protected override float GetVisibleHeight(MaterialProperty prop) { return 0; }

public override void BuildStaticMetaData(Shader inShader, MaterialProperty inProp, MaterialProperty[] inProps, PropertyStaticData inoutPropertyStaticData)
{
inoutPropertyStaticData.isReadOnly = true;
}

public override void DrawProp(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor) { }
}

/// <summary>
/// Control the show or hide of a single or a group of properties based on multiple conditions.
/// logicalOperator: And | Or (Default: And).
Expand Down
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -583,9 +583,20 @@ Tips:

```c#
/// Similar to HideInInspector(), the difference is that Hidden() can be unhidden through the Display Mode button.
public Hidden()
public HiddenDecorator()
```



#### ReadOnly

```c#
/// Set the property to read-only.
public ReadOnlyDecorator()
```



#### ShowIf

```c#
Expand Down
13 changes: 12 additions & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -584,9 +584,20 @@ Tips:

```c#
/// 类似于HideInInspector(), 区别在于Hidden()可以通过Display Mode按钮取消隐藏.
public Hidden()
public HiddenDecorator()
```



#### ReadOnly

```c#
/// 将属性设为只读.
public ReadOnlyDecorator()
```



#### ShowIf

```c#
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.14.6",
"version": "1.15.0",
"displayName": "LWGUI",
"description": "A Lightweight, Flexible, Powerful Shader GUI System for Unity.",
"keywords": [
Expand Down

0 comments on commit f15f869

Please sign in to comment.