diff --git a/Editor/Helper.cs b/Editor/Helper.cs index 29fd5a3..1760c41 100644 --- a/Editor/Helper.cs +++ b/Editor/Helper.cs @@ -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 diff --git a/Editor/LWGUI.cs b/Editor/LWGUI.cs index 65a8ad2..51b17ab 100644 --- a/Editor/LWGUI.cs +++ b/Editor/LWGUI.cs @@ -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); @@ -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 \ No newline at end of file diff --git a/Editor/MetaDataHelper.cs b/Editor/MetaDataHelper.cs index 39df9e4..f32927e 100644 --- a/Editor/MetaDataHelper.cs +++ b/Editor/MetaDataHelper.cs @@ -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 showIfDatas = new List(); // [ShowIf()] // Metadata diff --git a/Editor/ShaderDrawer.cs b/Editor/ShaderDrawer.cs index 4677bea..c967042 100644 --- a/Editor/ShaderDrawer.cs +++ b/Editor/ShaderDrawer.cs @@ -1345,6 +1345,21 @@ public override void BuildStaticMetaData(Shader inShader, MaterialProperty inPro public override void DrawProp(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor) { } } + /// + /// Set the property to read-only. + /// + 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) { } + } + /// /// Control the show or hide of a single or a group of properties based on multiple conditions. /// logicalOperator: And | Or (Default: And). diff --git a/README.md b/README.md index a81b2cd..bdc3726 100644 --- a/README.md +++ b/README.md @@ -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# diff --git a/README_CN.md b/README_CN.md index 111e49a..ec80877 100644 --- a/README_CN.md +++ b/README_CN.md @@ -584,9 +584,20 @@ Tips: ```c# /// 类似于HideInInspector(), 区别在于Hidden()可以通过Display Mode按钮取消隐藏. -public Hidden() +public HiddenDecorator() ``` + + +#### ReadOnly + +```c# +/// 将属性设为只读. +public ReadOnlyDecorator() +``` + + + #### ShowIf ```c# diff --git a/package.json b/package.json index a46e9a3..2e20cb3 100644 --- a/package.json +++ b/package.json @@ -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": [