diff --git a/Editor/Helper.cs b/Editor/Helper.cs
index ecddcaa..db8357a 100644
--- a/Editor/Helper.cs
+++ b/Editor/Helper.cs
@@ -534,7 +534,7 @@ public static void DrawToolbarButtons(ref Rect toolBarRect, LWGUI lwgui)
foreach (var propertyStaticDataPair in lwgui.perShaderData.propertyDatas)
{
if (propertyStaticDataPair.Value.isMain || propertyStaticDataPair.Value.isAdvancedHeader)
- propertyStaticDataPair.Value.isExpanded = true;
+ propertyStaticDataPair.Value.isExpanding = true;
}
}
@@ -546,7 +546,7 @@ public static void DrawToolbarButtons(ref Rect toolBarRect, LWGUI lwgui)
foreach (var propertyStaticDataPair in lwgui.perShaderData.propertyDatas)
{
if (propertyStaticDataPair.Value.isMain || propertyStaticDataPair.Value.isAdvancedHeader)
- propertyStaticDataPair.Value.isExpanded = false;
+ propertyStaticDataPair.Value.isExpanding = false;
}
}
diff --git a/Editor/LWGUI.cs b/Editor/LWGUI.cs
index ad63649..a0e74a7 100644
--- a/Editor/LWGUI.cs
+++ b/Editor/LWGUI.cs
@@ -98,9 +98,9 @@ public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] pro
var revertButtonRect = RevertableHelper.SplitRevertButtonRect(ref rect);
var label = string.IsNullOrEmpty(propStaticData.advancedHeaderString) ? "Advanced" : propStaticData.advancedHeaderString;
RevertableHelper.DrawRevertableProperty(revertButtonRect, prop, this);
- propStaticData.isExpanded = EditorGUI.Foldout(rect, propStaticData.isExpanded, label);
+ propStaticData.isExpanding = EditorGUI.Foldout(rect, propStaticData.isExpanding, label);
- if (!propStaticData.isExpanded)
+ if (!propStaticData.isExpanding)
{
RevertableHelper.SetRevertableGUIWidths();
EditorGUI.indentLevel = indentLevel;
@@ -163,7 +163,7 @@ private void DrawProperty(MaterialProperty prop)
RevertableHelper.FixGUIWidthMismatch(prop.type, materialEditor);
RevertableHelper.DrawRevertableProperty(revertButtonRect, prop, this);
if (propStaticData.isAdvancedHeaderProperty)
- propStaticData.isExpanded = EditorGUI.Foldout(rect, propStaticData.isExpanded, string.Empty);
+ propStaticData.isExpanding = EditorGUI.Foldout(rect, propStaticData.isExpanding, string.Empty);
materialEditor.ShaderProperty(rect, prop, label);
Helper.EndProperty(this, prop);
}
diff --git a/Editor/MetaDataHelper.cs b/Editor/MetaDataHelper.cs
index 59214fd..93fddcc 100644
--- a/Editor/MetaDataHelper.cs
+++ b/Editor/MetaDataHelper.cs
@@ -4,6 +4,7 @@
using System.Linq;
using UnityEditor;
using UnityEngine;
+using UnityEngine.Rendering;
namespace LWGUI
{
@@ -15,6 +16,12 @@ public enum SearchMode
Num = 3
}
+ public enum LogicalOperator
+ {
+ And,
+ Or
+ }
+
public struct DisplayModeData
{
public bool showAllAdvancedProperties;
@@ -27,6 +34,14 @@ public struct DisplayModeData
public bool IsDefaultDisplayMode() { return !(showAllAdvancedProperties || showAllHiddenProperties || showOnlyModifiedProperties); }
}
+ public class ShowIfData
+ {
+ public LogicalOperator logicalOperator = LogicalOperator.And;
+ public string targetPropertyName = string.Empty;
+ public CompareFunction compareFunction = CompareFunction.Equal;
+ public float value = 0;
+ }
+
///
/// All static metadata for a Property, determined after the Shader is compiled.
///
@@ -46,10 +61,11 @@ public class PropertyStaticData
public List children = new List();
// Visibility
- public string conditionalDisplayKeyword = string.Empty; // [Group(groupName_conditionalDisplayKeyword)]
- public bool isSearchDisplayed = true; // Draws when the search match is successful
- public bool isExpanded = false; // Draws when the group has been expanded
- public bool isHidden = false; // [Hidden]
+ public string conditionalDisplayKeyword = string.Empty; // [Group(groupName_conditionalDisplayKeyword)]
+ 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 List showIfDatas = new List(); // [ShowIf()]
// Metadata
public List extraPropNames = new List(); // Other Props that have been associated
@@ -244,7 +260,7 @@ public void UpdateSearchFilter()
// The First Search
foreach (var propertyData in propertyDatas)
{
- propertyData.Value.isSearchDisplayed = isSearchStringEmpty
+ propertyData.Value.isSearchMatched = isSearchStringEmpty
? true
: IsWholeWordMatch(propertyData.Value.displayName, propertyData.Key, searchKeywords);
}
@@ -257,7 +273,7 @@ public void UpdateSearchFilter()
if (searchModeTemp == SearchMode.Auto)
{
// if has no group
- if (!propertyDatas.Any((propertyData => propertyData.Value.isSearchDisplayed && propertyData.Value.isMain)))
+ if (!propertyDatas.Any((propertyData => propertyData.Value.isSearchMatched && propertyData.Value.isMain)))
searchModeTemp = SearchMode.Property;
else
searchModeTemp = SearchMode.Group;
@@ -269,8 +285,8 @@ public void UpdateSearchFilter()
// when a SubProp is displayed, the MainProp is also displayed
foreach (var propertyData in propertyDatas)
{
- if (propertyData.Value.isMain && propertyData.Value.children.Any((childPropertyData => childPropertyData.isSearchDisplayed)))
- propertyData.Value.isSearchDisplayed = true;
+ if (propertyData.Value.isMain && propertyData.Value.children.Any((childPropertyData => childPropertyData.isSearchMatched)))
+ propertyData.Value.isSearchMatched = true;
}
}
// search by group
@@ -281,7 +297,7 @@ public void UpdateSearchFilter()
{
if (propertyData.Value.isMain)
foreach (var childPropertyData in propertyData.Value.children)
- childPropertyData.isSearchDisplayed = propertyData.Value.isSearchDisplayed;
+ childPropertyData.isSearchMatched = propertyData.Value.isSearchMatched;
}
}
}
@@ -308,7 +324,7 @@ public void ToggleShowAllAdvancedProperties()
foreach (var propertyStaticDataPair in propertyDatas)
{
if (propertyStaticDataPair.Value.isAdvancedHeader)
- propertyStaticDataPair.Value.isExpanded = displayModeData.showAllAdvancedProperties;
+ propertyStaticDataPair.Value.isExpanding = displayModeData.showAllAdvancedProperties;
}
}
}
@@ -321,8 +337,9 @@ public class PropertyDynamicData
public MaterialProperty property;
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 revertChanged = false; // Used to call property EndChangeCheck()
+ public bool hasModified = false; // Are properties modified in the material?
+ public bool hasRevertChanged = false; // Used to call property EndChangeCheck()
+ public bool isShowing = true; // ShowIf() result
}
@@ -355,6 +372,8 @@ public void BuildPerFrameData(Shader shader, Material material, MaterialProperty
{
List decoratorDrawers;
var drawer = ReflectionHelper.GetPropertyDrawer(shader, prop, out decoratorDrawers);
+
+ // Get Presets
if (drawer != null)
{
if (drawer is IBasePresetDrawer)
@@ -400,10 +419,13 @@ public void BuildPerFrameData(Shader shader, Material material, MaterialProperty
foreach (var prop in props)
{
+ var propStaticData = perShaderData.propertyDatas[prop.name];
+ var propDynamicData = propertyDatas[prop.name];
+
// Override parent hasModified
- if (propertyDatas[prop.name].hasModified)
+ if (propDynamicData.hasModified)
{
- var parentPropData = perShaderData.propertyDatas[prop.name].parent;
+ var parentPropData = propStaticData.parent;
if (parentPropData != null)
{
propertyDatas[parentPropData.name].hasModified = true;
@@ -413,9 +435,9 @@ public void BuildPerFrameData(Shader shader, Material material, MaterialProperty
}
// Get default value descriptions
+ List decoratorDrawers;
+ var drawer = ReflectionHelper.GetPropertyDrawer(shader, prop, out decoratorDrawers);
{
- List decoratorDrawers;
- var drawer = ReflectionHelper.GetPropertyDrawer(shader, prop, out decoratorDrawers);
if (decoratorDrawers != null && decoratorDrawers.Count > 0)
{
foreach (var decoratorDrawer in decoratorDrawers)
@@ -429,9 +451,48 @@ public void BuildPerFrameData(Shader shader, Material material, MaterialProperty
if (drawer is IBaseDrawer)
(drawer as IBaseDrawer).GetDefaultValueDescription(shader, prop, perShaderData, this);
}
- if (string.IsNullOrEmpty(propertyDatas[prop.name].defaultValueDescription))
- propertyDatas[prop.name].defaultValueDescription =
- RevertableHelper.GetPropertyDefaultValueText(propertyDatas[prop.name].defualtProperty);
+ if (string.IsNullOrEmpty(propDynamicData.defaultValueDescription))
+ propDynamicData.defaultValueDescription =
+ RevertableHelper.GetPropertyDefaultValueText(propDynamicData.defualtProperty);
+ }
+
+ // Get ShowIf() results
+ foreach (var showIfData in propStaticData.showIfDatas)
+ {
+ var propCurrentValue = propertyDatas[showIfData.targetPropertyName].property.floatValue;
+ bool compareResult;
+
+ switch (showIfData.compareFunction)
+ {
+ case CompareFunction.Less:
+ compareResult = propCurrentValue < showIfData.value;
+ break;
+ case CompareFunction.LessEqual:
+ compareResult = propCurrentValue <= showIfData.value;
+ break;
+ case CompareFunction.Greater:
+ compareResult = propCurrentValue > showIfData.value;
+ break;
+ case CompareFunction.NotEqual:
+ compareResult = propCurrentValue != showIfData.value;
+ break;
+ case CompareFunction.GreaterEqual:
+ compareResult = propCurrentValue >= showIfData.value;
+ break;
+ default:
+ compareResult = propCurrentValue == showIfData.value;
+ break;
+ }
+
+ switch (showIfData.logicalOperator)
+ {
+ case LogicalOperator.And:
+ propDynamicData.isShowing &= compareResult;
+ break;
+ case LogicalOperator.Or:
+ propDynamicData.isShowing |= compareResult;
+ break;
+ }
}
}
}
@@ -457,8 +518,8 @@ public bool EndChangeCheck(string propName = null)
var result = EditorGUI.EndChangeCheck();
if (!string.IsNullOrEmpty(propName))
{
- result |= propertyDatas[propName].revertChanged;
- propertyDatas[propName].revertChanged = false;
+ result |= propertyDatas[propName].hasRevertChanged;
+ propertyDatas[propName].hasRevertChanged = false;
}
return result;
}
@@ -531,12 +592,14 @@ public static bool GetPropertyVisibility(MaterialProperty prop, Material materia
if ( // if HideInInspector
Helper.IsPropertyHideInInspector(prop)
// if Search Filtered
- || !propertyStaticData.isSearchDisplayed
+ || !propertyStaticData.isSearchMatched
// if the Conditional Display Keyword is not active
|| (!string.IsNullOrEmpty(propertyStaticData.conditionalDisplayKeyword) && !material.shaderKeywords.Any((str => str == propertyStaticData.conditionalDisplayKeyword)))
|| (!displayModeData.showAllHiddenProperties && propertyStaticData.isHidden)
// if show modified only
|| (displayModeData.showOnlyModifiedProperties && !propertyDynamicData.hasModified)
+ // ShowIf() == false
+ || !propertyDynamicData.isShowing
)
{
result = false;
@@ -550,7 +613,7 @@ public static bool GetParentPropertyVisibility(PropertyStaticData parentPropStat
bool result = true;
if (parentPropStaticData != null
- && (!lwgui.perShaderData.propertyDatas[parentPropStaticData.name].isExpanded
+ && (!lwgui.perShaderData.propertyDatas[parentPropStaticData.name].isExpanding
|| !MetaDataHelper.GetPropertyVisibility(lwgui.perFrameData.propertyDatas[parentPropStaticData.name].property, material, lwgui)))
{
result = false;
diff --git a/Editor/ReflectionHelper.cs b/Editor/ReflectionHelper.cs
index f6ea392..29f101f 100644
--- a/Editor/ReflectionHelper.cs
+++ b/Editor/ReflectionHelper.cs
@@ -138,9 +138,8 @@ public static void ShowModal(EditorWindow window)
#region MaterialProperty.PropertyData
-
- private static Type MaterialProperty_Type = typeof(MaterialProperty);
#if UNITY_2022_1_OR_NEWER
+ private static Type MaterialProperty_Type = typeof(MaterialProperty);
private static Type PropertyData_Type = MaterialProperty_Type.GetNestedType("PropertyData", BindingFlags.NonPublic);
// MergeStack(out bool lockedInChildren, out bool lockedByAncestor, out bool overriden)
private static MethodInfo PropertyData_MergeStack_Method = PropertyData_Type.GetMethod("MergeStack", BindingFlags.Static | BindingFlags.NonPublic);
diff --git a/Editor/RevertableHelper.cs b/Editor/RevertableHelper.cs
index cb2f978..32ecfa0 100644
--- a/Editor/RevertableHelper.cs
+++ b/Editor/RevertableHelper.cs
@@ -156,12 +156,12 @@ private static void DoRevertProperty(MaterialProperty prop, LWGUI lwgui)
{
var propDynamicData = lwgui.perFrameData.propertyDatas[prop.name];
var extraPropNames = lwgui.perShaderData.propertyDatas[prop.name].extraPropNames;
- propDynamicData.revertChanged = true;
+ propDynamicData.hasRevertChanged = true;
SetPropertyToDefault(propDynamicData.defualtProperty, prop);
foreach (var extraPropName in extraPropNames)
{
var extraPropDynamicData = lwgui.perFrameData.propertyDatas[extraPropName];
- extraPropDynamicData.revertChanged = true;
+ extraPropDynamicData.hasRevertChanged = true;
SetPropertyToDefault(extraPropDynamicData.defualtProperty, extraPropDynamicData.property);
}
}
diff --git a/Editor/ShaderDrawer.cs b/Editor/ShaderDrawer.cs
index db73c1b..2040855 100644
--- a/Editor/ShaderDrawer.cs
+++ b/Editor/ShaderDrawer.cs
@@ -4,6 +4,7 @@
using System.Linq;
using UnityEditor;
using UnityEngine;
+using UnityEngine.Rendering;
using Object = UnityEngine.Object;
namespace LWGUI
@@ -62,7 +63,7 @@ public virtual void BuildStaticMetaData(Shader inShader, MaterialProperty inProp
{
inoutPropertyStaticData.groupName = _group;
inoutPropertyStaticData.isMain = true;
- inoutPropertyStaticData.isExpanded = _defaultFoldingState;
+ inoutPropertyStaticData.isExpanding = _defaultFoldingState;
}
public virtual void GetDefaultValueDescription(Shader inShader,
@@ -85,7 +86,7 @@ public override void OnGUI(Rect position, MaterialProperty prop, GUIContent labe
EditorGUI.BeginChangeCheck();
- bool toggleResult = Helper.DrawFoldout(position, ref propertyStaticData.isExpanded, prop.floatValue > 0, _defaultToggleDisplayed, label);
+ bool toggleResult = Helper.DrawFoldout(position, ref propertyStaticData.isExpanding, prop.floatValue > 0, _defaultToggleDisplayed, label);
if (Helper.EndChangeCheck(lwgui, prop))
{
@@ -1328,4 +1329,37 @@ public override void BuildStaticMetaData(Shader inShader, MaterialProperty inPro
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).
+ /// propName: Target Property Name used for comparison.
+ /// compareFunction: Less | Greater | LEqual | GEqual | Equal | NotEqual.
+ /// value: Target Property Value used for comparison.
+ ///
+ public class ShowIfDecorator : SubDrawer
+ {
+ private ShowIfData _showIfData = new ShowIfData();
+
+ public ShowIfDecorator(string propName, string comparisonMethod, float value) : this("And", propName, comparisonMethod, value) { }
+ public ShowIfDecorator(string logicalOperator, string propName, string compareFunction, float value)
+ {
+ _showIfData.logicalOperator = logicalOperator.ToLower() == "or" ? LogicalOperator.Or : LogicalOperator.And;
+ _showIfData.targetPropertyName = propName;
+ if (!Enum.IsDefined(typeof(CompareFunction), compareFunction))
+ Debug.LogError("Invalid compareFunction: '" + compareFunction + "', Must be one of the following: Less | Greater | LEqual | GEqual | Equal | NotEqual | Always.");
+ else
+ _showIfData.compareFunction = (CompareFunction)Enum.Parse(typeof(CompareFunction), compareFunction);
+ _showIfData.value = value;
+ }
+
+ protected override float GetVisibleHeight(MaterialProperty prop) { return 0; }
+
+ public override void BuildStaticMetaData(Shader inShader, MaterialProperty inProp, MaterialProperty[] inProps, PropertyStaticData inoutPropertyStaticData)
+ {
+ inoutPropertyStaticData.showIfDatas.Add(_showIfData);
+ }
+
+ public override void DrawProp(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor) { }
+ }
} //namespace LWGUI
\ No newline at end of file
diff --git a/Editor/ShaderPropertyPreset.cs b/Editor/ShaderPropertyPreset.cs
index 605acdf..614ce6c 100644
--- a/Editor/ShaderPropertyPreset.cs
+++ b/Editor/ShaderPropertyPreset.cs
@@ -98,7 +98,7 @@ public void Apply(Material material, bool isDefaultMaterial, PerFrameData perFra
break;
}
- propDynamicData.revertChanged = true;
+ propDynamicData.hasRevertChanged = true;
}
}
diff --git a/Editor/Test/LWGUI_KeywordTest 1.mat b/Editor/Test/LWGUI_KeywordTest 1.mat
index f9a228e..dd605f6 100644
--- a/Editor/Test/LWGUI_KeywordTest 1.mat
+++ b/Editor/Test/LWGUI_KeywordTest 1.mat
@@ -9,7 +9,7 @@ Material:
m_PrefabAsset: {fileID: 0}
m_Name: LWGUI_KeywordTest 1
m_Shader: {fileID: 4800000, guid: 98ad70357ecd6134dbac80aef9c63f6f, type: 3}
- m_ShaderKeywords: _KEYWORDENUM_KEY2 _KWENUM_KEY2 _SUBKEYWORDENUM_KEY2 _TOGGLE_KEYWORD
+ m_ShaderKeywords: _GROUP_TOGGLE_KEYWORD _KEYWORDENUM_KEY1 _KWENUM_KEY1 _SUBKEYWORDENUM_KEY1
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
@@ -23,10 +23,12 @@ Material:
- _ZWrite: 1
- _enum: 1
- _group: 1
- - _keywordEnum: 1
- - _kwenum: 1
+ - _group_toggle1: 1
+ - _keywordEnum: 0
+ - _kwenum: 0
+ - _preset2: 1
- _subEnum: 1
- - _subKeywordEnum: 1
+ - _subKeywordEnum: 0
- _toggle: 0
- - _toggle1: 1
+ - _toggle1: 0
m_Colors: []
diff --git a/Editor/Test/LWGUI_KeywordTest Variant.mat b/Editor/Test/LWGUI_KeywordTest Variant.mat
index f494f91..442ae07 100644
--- a/Editor/Test/LWGUI_KeywordTest Variant.mat
+++ b/Editor/Test/LWGUI_KeywordTest Variant.mat
@@ -2,33 +2,32 @@
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
- serializedVersion: 8
+ serializedVersion: 6
m_ObjectHideFlags: 0
- m_CorrespondingSourceObject: {fileID: 0}
- m_PrefabInstance: {fileID: 0}
- m_PrefabAsset: {fileID: 0}
+ m_PrefabParentObject: {fileID: 0}
+ m_PrefabInternal: {fileID: 0}
m_Name: LWGUI_KeywordTest Variant
m_Shader: {fileID: 4800000, guid: 98ad70357ecd6134dbac80aef9c63f6f, type: 3}
- m_Parent: {fileID: 2100000, guid: 64f63a798b03f4a448ef2a853da686c9, type: 2}
- m_ModifiedSerializedProperties: 0
- m_ValidKeywords:
- - _KEYWORDENUM_KEY1
- - _KWENUM_KEY1
- - _SUBKEYWORDENUM_KEY2
- - _TOGGLE_KEYWORD
- m_InvalidKeywords: []
+ m_ShaderKeywords: _GROUP_TOGGLE_KEYWORD _KEYWORDENUM_KEY1 _KWENUM_KEY1 _SUBKEYWORDENUM_KEY1
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
- m_LockedProperties:
m_SavedProperties:
serializedVersion: 3
m_TexEnvs: []
- m_Ints: []
m_Floats:
+ - _ZWrite: 1
+ - _enum: 1
- _group: 1
+ - _group_toggle1: 1
+ - _keywordEnum: 0
+ - _kwenum: 0
+ - _preset2: 1
+ - _subEnum: 0.5
+ - _subKeywordEnum: 0
+ - _toggle: 0
+ - _toggle1: 0
m_Colors: []
- m_BuildTextureStacks: []
diff --git a/Editor/Test/LWGUI_KeywordTest.mat b/Editor/Test/LWGUI_KeywordTest.mat
index 1b5e3fa..a0f4dba 100644
--- a/Editor/Test/LWGUI_KeywordTest.mat
+++ b/Editor/Test/LWGUI_KeywordTest.mat
@@ -4,9 +4,8 @@
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
- m_CorrespondingSourceObject: {fileID: 0}
- m_PrefabInstance: {fileID: 0}
- m_PrefabAsset: {fileID: 0}
+ m_PrefabParentObject: {fileID: 0}
+ m_PrefabInternal: {fileID: 0}
m_Name: LWGUI_KeywordTest
m_Shader: {fileID: 4800000, guid: 98ad70357ecd6134dbac80aef9c63f6f, type: 3}
m_ShaderKeywords: _KEYWORDENUM_KEY2 _KWENUM_KEY2 _SUBKEYWORDENUM_KEY1
@@ -15,17 +14,18 @@ Material:
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
- disabledShaderPasses:
- - ALWAYS
+ disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs: []
m_Floats:
- _ZWrite: 1
- _enum: 1
- - _group: 0
+ - _group: 1
+ - _group_toggle1: 0
- _keywordEnum: 1
- _kwenum: 1
+ - _preset2: 0
- _subEnum: 1
- _subKeywordEnum: 0
- _toggle: 0
diff --git a/Editor/Test/LWGUI_SampleDrawer 1.mat b/Editor/Test/LWGUI_SampleDrawer 1.mat
index a601054..8091619 100644
--- a/Editor/Test/LWGUI_SampleDrawer 1.mat
+++ b/Editor/Test/LWGUI_SampleDrawer 1.mat
@@ -8,7 +8,7 @@ Material:
m_PrefabInternal: {fileID: 0}
m_Name: LWGUI_SampleDrawer 1
m_Shader: {fileID: 4800000, guid: 7ee048c9536c0344bb8b4860595a4d9b, type: 3}
- m_ShaderKeywords: _GROUP_ON _KEY3 _TOGGLE_KEYWORD
+ m_ShaderKeywords: _GROUP_ON _KEY2
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
@@ -69,7 +69,7 @@ Material:
- _Advancedfloat3: 0.21
- _Advancedfloat4: 0
- _Advancedfloat7: 0.24
- - _enum: 2
+ - _enum: 1
- _float: -0.8
- _float1: -0.05
- _float2: -0.08
@@ -82,6 +82,7 @@ Material:
- _group1: 0
- _group2: 0
- _group3: 0
+ - _key13_PowerSlider: 0.199
- _key1_Float1: 0
- _key2_Float2: 0
- _key3_Float3: -0.34
@@ -94,7 +95,7 @@ Material:
- _range: 0.42
- _rangeEnd: 0.70471865
- _rangeStart: 0.20471871
- - _toggle: 1
+ - _toggle: 0
- _toggle1: 1
m_Colors:
- _color: {r: 1, g: 0.5886792, b: 0.5886792, a: 1}
diff --git a/Editor/Test/LWGUI_ShaderPropertyPreset2.asset b/Editor/Test/LWGUI_ShaderPropertyPreset2.asset
index 19f9023..6b27de8 100644
--- a/Editor/Test/LWGUI_ShaderPropertyPreset2.asset
+++ b/Editor/Test/LWGUI_ShaderPropertyPreset2.asset
@@ -10,16 +10,28 @@ MonoBehaviour:
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 28fbcbca3fb14507af6ed5c104c40b84, type: 3}
- m_Name: LWGUI_ShaderPropertyPreset1
+ m_Name: LWGUI_ShaderPropertyPreset2
m_EditorClassIdentifier:
presets:
- - presetName: Preset X
- propertyValues: []
- - presetName: Preset Y
+ - presetName: Preset 1
propertyValues:
- - propertyName: _vector1
- propertyType: 1
+ - propertyName: _group_toggle1
+ propertyType: 2
floatValue: 0
colorValue: {r: 0, g: 0, b: 0, a: 0}
- vectorValue: {x: 1.32, y: 1, z: 1, w: 1}
+ vectorValue: {x: 0, y: 0, z: 0, w: 0}
+ textureValue: {fileID: 0}
+ - propertyName: _group
+ propertyType: 2
+ floatValue: 1
+ colorValue: {r: 0, g: 0, b: 0, a: 0}
+ vectorValue: {x: 0, y: 0, z: 0, w: 0}
+ textureValue: {fileID: 0}
+ - presetName: Preset 2
+ propertyValues:
+ - propertyName: _group_toggle1
+ propertyType: 2
+ floatValue: 1
+ colorValue: {r: 0, g: 0, b: 0, a: 0}
+ vectorValue: {x: 0, y: 0, z: 0, w: 0}
textureValue: {fileID: 0}
diff --git a/Editor/Test/SampleDrawer 1.shader b/Editor/Test/SampleDrawer 1.shader
index 6a3e4dc..3323cb9 100644
--- a/Editor/Test/SampleDrawer 1.shader
+++ b/Editor/Test/SampleDrawer 1.shader
@@ -2,7 +2,8 @@
{
Properties
{
- [Hidden][Title(Main Samples)]
+ [ShowIf(_enum, Equal, 1)]
+ [Title(ShowIf Main Samples)]
[Main(GroupName)] _group ("Group", float) = 0
[Sub(GroupName)] _float ("Float", float) = 0
[Sub(GroupName)] _Tex ("Tex", 2D) = "white" { }
@@ -17,16 +18,11 @@
[SubTitle(Group1, Conditional Display Samples Enum)]
[KWEnum(Group1, Name 1, _KEY1, Name 2, _KEY2, Name 3, _KEY3)] _enum ("KWEnum", float) = 0
- // Display when the keyword ("group name + keyword") is activated
- [Sub(Group1_KEY1)] _key1_Float1 ("Key1 Float", float) = 0
- [Sub(Group1_KEY2)] _key2_Float2 ("Key2 Float", float) = 0
- [SubIntRange(Group1_KEY3)] _key3_Int_Range ("Key3 Int Range", Range(0, 10)) = 0
- [SubPowerSlider(Group1_KEY3, 10)] _key3_Float4_PowerSlider ("Key3 Power Slider", Range(0, 1)) = 0
-
- [SubTitle(Group1, Conditional Display Samples Toggle)]
- [SubToggle(Group1, _TOGGLE_KEYWORD)] _toggle ("SubToggle", float) = 0
- [Tex(Group1_TOGGLE_KEYWORD)][Normal] _normal ("Normal Keyword", 2D) = "bump" { }
- [Sub(Group1_TOGGLE_KEYWORD)] _float2 ("Float Keyword", float) = 0
+ [Sub(Group1)][ShowIf(_enum, Equal, 0)] _key1_Float1 ("Key1 Float", float) = 0
+ [Sub(Group1)][ShowIf(_enum, Equal, 1)] _key2_Float2 ("Key2 Float", float) = 0
+ [SubIntRange(Group1)][ShowIf(_enum, Equal, 2)] _key3_Int_Range ("Key3 Int Range", Range(0, 10)) = 0
+ [ShowIf(_enum, Equal, 0)][ShowIf(Or, _enum, Equal, 2)]
+ [SubPowerSlider(Group1, 3)] _key13_PowerSlider ("Key1 or Key3 Power Slider", Range(0, 1)) = 0
[Main(Group2, _, off, off)] _group2 ("Group - Without Toggle", float) = 0
diff --git a/README.md b/README.md
index 0cf60e5..9d7e01f 100644
--- a/README.md
+++ b/README.md
@@ -47,6 +47,7 @@ Having been validated through numerous large-scale commercial projects, employin
+ [PassSwitch](#passswitch)
+ [Advanced & AdvancedHeaderProperty](#advanced--advancedheaderproperty)
+ [Hidden](#hidden)
+ + [ShowIf](#showif)
* [Unity Builtin Drawers](#unity-builtin-drawers)
+ [Space](#space)
+ [Header](#header)
@@ -589,6 +590,42 @@ Tips:
public Hidden()
```
+#### ShowIf
+
+```c#
+/// Control the show or hide of a single or a group of properties based on multiple conditions.
+/// logicalOperator: And | Or (Default: And).
+/// propName: Target Property Name used for comparison.
+/// compareFunction: Less | Greater | LEqual | GEqual | Equal | NotEqual.
+/// value: Target Property Value used for comparison.
+public ShowIfDecorator(string propName, string comparisonMethod, float value) : this("And", propName, comparisonMethod, value) { }
+public ShowIfDecorator(string logicalOperator, string propName, string compareFunction, float value)
+```
+
+Example:
+
+```c#
+[ShowIf(_enum, Equal, 1)]
+[Title(ShowIf Main Samples)]
+[Main(GroupName)] _group ("Group", float) = 0
+[Sub(GroupName)] _float ("Float", float) = 0
+[Sub(GroupName)] _Tex ("Tex", 2D) = "white" { }
+
+...
+
+[SubTitle(Group1, Conditional Display Samples Enum)]
+[KWEnum(Group1, Name 1, _KEY1, Name 2, _KEY2, Name 3, _KEY3)] _enum ("KWEnum", float) = 0
+[Sub(Group1)][ShowIf(_enum, Equal, 0)] _key1_Float1 ("Key1 Float", float) = 0
+[Sub(Group1)][ShowIf(_enum, Equal, 1)] _key2_Float2 ("Key2 Float", float) = 0
+[SubIntRange(Group1)][ShowIf(_enum, Equal, 2)] _key3_Int_Range ("Key3 Int Range", Range(0, 10)) = 0
+[ShowIf(_enum, Equal, 0)][ShowIf(Or, _enum, Equal, 2)]
+[SubPowerSlider(Group1, 3)] _key13_PowerSlider ("Key1 or Key3 Power Slider", Range(0, 1)) = 0
+
+```
+
+| ![image-20231023010137495](./README_CN.assets/image-20231023010137495.png) | ![image-20231023010153213](./README_CN.assets/image-20231023010153213.png) | ![image-20231023010204399](./README_CN.assets/image-20231023010204399.png) |
+| ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ |
+
diff --git a/README_CN.assets/image-20231023010137495.png b/README_CN.assets/image-20231023010137495.png
new file mode 100644
index 0000000..31d0c1d
Binary files /dev/null and b/README_CN.assets/image-20231023010137495.png differ
diff --git a/README_CN.assets/image-20231023010137495.png.meta b/README_CN.assets/image-20231023010137495.png.meta
new file mode 100644
index 0000000..10fd27d
--- /dev/null
+++ b/README_CN.assets/image-20231023010137495.png.meta
@@ -0,0 +1,92 @@
+fileFormatVersion: 2
+guid: 4120695270bd16d498f94233b81b7f8b
+TextureImporter:
+ internalIDToNameTable: []
+ externalObjects: {}
+ serializedVersion: 11
+ mipmaps:
+ mipMapMode: 0
+ enableMipMap: 1
+ sRGBTexture: 1
+ linearTexture: 0
+ fadeOut: 0
+ borderMipMap: 0
+ mipMapsPreserveCoverage: 0
+ alphaTestReferenceValue: 0.5
+ mipMapFadeDistanceStart: 1
+ mipMapFadeDistanceEnd: 3
+ bumpmap:
+ convertToNormalMap: 0
+ externalNormalMap: 0
+ heightScale: 0.25
+ normalMapFilter: 0
+ isReadable: 0
+ streamingMipmaps: 0
+ streamingMipmapsPriority: 0
+ grayScaleToAlpha: 0
+ generateCubemap: 6
+ cubemapConvolution: 0
+ seamlessCubemap: 0
+ textureFormat: 1
+ maxTextureSize: 2048
+ textureSettings:
+ serializedVersion: 2
+ filterMode: 1
+ aniso: 1
+ mipBias: 0
+ wrapU: 0
+ wrapV: 0
+ wrapW: 0
+ nPOTScale: 1
+ lightmap: 0
+ compressionQuality: 50
+ spriteMode: 0
+ spriteExtrude: 1
+ spriteMeshType: 1
+ alignment: 0
+ spritePivot: {x: 0.5, y: 0.5}
+ spritePixelsToUnits: 100
+ spriteBorder: {x: 0, y: 0, z: 0, w: 0}
+ spriteGenerateFallbackPhysicsShape: 1
+ alphaUsage: 1
+ alphaIsTransparency: 0
+ spriteTessellationDetail: -1
+ textureType: 0
+ textureShape: 1
+ singleChannelComponent: 0
+ maxTextureSizeSet: 0
+ compressionQualitySet: 0
+ textureFormatSet: 0
+ applyGammaDecoding: 0
+ platformSettings:
+ - serializedVersion: 3
+ buildTarget: DefaultTexturePlatform
+ maxTextureSize: 2048
+ resizeAlgorithm: 0
+ textureFormat: -1
+ textureCompression: 1
+ compressionQuality: 50
+ crunchedCompression: 0
+ allowsAlphaSplitting: 0
+ overridden: 0
+ androidETC2FallbackOverride: 0
+ forceMaximumCompressionQuality_BC6H_BC7: 0
+ spriteSheet:
+ serializedVersion: 2
+ sprites: []
+ outline: []
+ physicsShape: []
+ bones: []
+ spriteID:
+ internalID: 0
+ vertices: []
+ indices:
+ edges: []
+ weights: []
+ secondaryTextures: []
+ spritePackingTag:
+ pSDRemoveMatte: 0
+ pSDShowRemoveMatteOption: 0
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/README_CN.assets/image-20231023010153213.png b/README_CN.assets/image-20231023010153213.png
new file mode 100644
index 0000000..445c642
Binary files /dev/null and b/README_CN.assets/image-20231023010153213.png differ
diff --git a/README_CN.assets/image-20231023010153213.png.meta b/README_CN.assets/image-20231023010153213.png.meta
new file mode 100644
index 0000000..42585f5
--- /dev/null
+++ b/README_CN.assets/image-20231023010153213.png.meta
@@ -0,0 +1,92 @@
+fileFormatVersion: 2
+guid: bb260ab89a5ace146b38226feb492662
+TextureImporter:
+ internalIDToNameTable: []
+ externalObjects: {}
+ serializedVersion: 11
+ mipmaps:
+ mipMapMode: 0
+ enableMipMap: 1
+ sRGBTexture: 1
+ linearTexture: 0
+ fadeOut: 0
+ borderMipMap: 0
+ mipMapsPreserveCoverage: 0
+ alphaTestReferenceValue: 0.5
+ mipMapFadeDistanceStart: 1
+ mipMapFadeDistanceEnd: 3
+ bumpmap:
+ convertToNormalMap: 0
+ externalNormalMap: 0
+ heightScale: 0.25
+ normalMapFilter: 0
+ isReadable: 0
+ streamingMipmaps: 0
+ streamingMipmapsPriority: 0
+ grayScaleToAlpha: 0
+ generateCubemap: 6
+ cubemapConvolution: 0
+ seamlessCubemap: 0
+ textureFormat: 1
+ maxTextureSize: 2048
+ textureSettings:
+ serializedVersion: 2
+ filterMode: 1
+ aniso: 1
+ mipBias: 0
+ wrapU: 0
+ wrapV: 0
+ wrapW: 0
+ nPOTScale: 1
+ lightmap: 0
+ compressionQuality: 50
+ spriteMode: 0
+ spriteExtrude: 1
+ spriteMeshType: 1
+ alignment: 0
+ spritePivot: {x: 0.5, y: 0.5}
+ spritePixelsToUnits: 100
+ spriteBorder: {x: 0, y: 0, z: 0, w: 0}
+ spriteGenerateFallbackPhysicsShape: 1
+ alphaUsage: 1
+ alphaIsTransparency: 0
+ spriteTessellationDetail: -1
+ textureType: 0
+ textureShape: 1
+ singleChannelComponent: 0
+ maxTextureSizeSet: 0
+ compressionQualitySet: 0
+ textureFormatSet: 0
+ applyGammaDecoding: 0
+ platformSettings:
+ - serializedVersion: 3
+ buildTarget: DefaultTexturePlatform
+ maxTextureSize: 2048
+ resizeAlgorithm: 0
+ textureFormat: -1
+ textureCompression: 1
+ compressionQuality: 50
+ crunchedCompression: 0
+ allowsAlphaSplitting: 0
+ overridden: 0
+ androidETC2FallbackOverride: 0
+ forceMaximumCompressionQuality_BC6H_BC7: 0
+ spriteSheet:
+ serializedVersion: 2
+ sprites: []
+ outline: []
+ physicsShape: []
+ bones: []
+ spriteID:
+ internalID: 0
+ vertices: []
+ indices:
+ edges: []
+ weights: []
+ secondaryTextures: []
+ spritePackingTag:
+ pSDRemoveMatte: 0
+ pSDShowRemoveMatteOption: 0
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/README_CN.assets/image-20231023010204399.png b/README_CN.assets/image-20231023010204399.png
new file mode 100644
index 0000000..ebad0b8
Binary files /dev/null and b/README_CN.assets/image-20231023010204399.png differ
diff --git a/README_CN.assets/image-20231023010204399.png.meta b/README_CN.assets/image-20231023010204399.png.meta
new file mode 100644
index 0000000..ca759b6
--- /dev/null
+++ b/README_CN.assets/image-20231023010204399.png.meta
@@ -0,0 +1,92 @@
+fileFormatVersion: 2
+guid: 19f871ea958fa8a45a4826417fcdebd6
+TextureImporter:
+ internalIDToNameTable: []
+ externalObjects: {}
+ serializedVersion: 11
+ mipmaps:
+ mipMapMode: 0
+ enableMipMap: 1
+ sRGBTexture: 1
+ linearTexture: 0
+ fadeOut: 0
+ borderMipMap: 0
+ mipMapsPreserveCoverage: 0
+ alphaTestReferenceValue: 0.5
+ mipMapFadeDistanceStart: 1
+ mipMapFadeDistanceEnd: 3
+ bumpmap:
+ convertToNormalMap: 0
+ externalNormalMap: 0
+ heightScale: 0.25
+ normalMapFilter: 0
+ isReadable: 0
+ streamingMipmaps: 0
+ streamingMipmapsPriority: 0
+ grayScaleToAlpha: 0
+ generateCubemap: 6
+ cubemapConvolution: 0
+ seamlessCubemap: 0
+ textureFormat: 1
+ maxTextureSize: 2048
+ textureSettings:
+ serializedVersion: 2
+ filterMode: 1
+ aniso: 1
+ mipBias: 0
+ wrapU: 0
+ wrapV: 0
+ wrapW: 0
+ nPOTScale: 1
+ lightmap: 0
+ compressionQuality: 50
+ spriteMode: 0
+ spriteExtrude: 1
+ spriteMeshType: 1
+ alignment: 0
+ spritePivot: {x: 0.5, y: 0.5}
+ spritePixelsToUnits: 100
+ spriteBorder: {x: 0, y: 0, z: 0, w: 0}
+ spriteGenerateFallbackPhysicsShape: 1
+ alphaUsage: 1
+ alphaIsTransparency: 0
+ spriteTessellationDetail: -1
+ textureType: 0
+ textureShape: 1
+ singleChannelComponent: 0
+ maxTextureSizeSet: 0
+ compressionQualitySet: 0
+ textureFormatSet: 0
+ applyGammaDecoding: 0
+ platformSettings:
+ - serializedVersion: 3
+ buildTarget: DefaultTexturePlatform
+ maxTextureSize: 2048
+ resizeAlgorithm: 0
+ textureFormat: -1
+ textureCompression: 1
+ compressionQuality: 50
+ crunchedCompression: 0
+ allowsAlphaSplitting: 0
+ overridden: 0
+ androidETC2FallbackOverride: 0
+ forceMaximumCompressionQuality_BC6H_BC7: 0
+ spriteSheet:
+ serializedVersion: 2
+ sprites: []
+ outline: []
+ physicsShape: []
+ bones: []
+ spriteID:
+ internalID: 0
+ vertices: []
+ indices:
+ edges: []
+ weights: []
+ secondaryTextures: []
+ spritePackingTag:
+ pSDRemoveMatte: 0
+ pSDShowRemoveMatteOption: 0
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/README_CN.md b/README_CN.md
index 93e07cc..e9533aa 100644
--- a/README_CN.md
+++ b/README_CN.md
@@ -46,6 +46,7 @@
+ [PassSwitch](#passswitch)
+ [Advanced & AdvancedHeaderProperty](#advanced--advancedheaderproperty)
+ [Hidden](#hidden)
+ + [ShowIf](#showif)
* [Unity Builtin Drawers](#unity-builtin-drawers)
+ [Space](#space)
+ [Header](#header)
@@ -588,6 +589,44 @@ Tips:
public Hidden()
```
+#### ShowIf
+
+```c#
+/// 可以根据多个条件控制单个或者一组属性的显示 / 隐藏.
+/// logicalOperator: And | Or (Default: And).
+/// propName: Target Property Name used for comparison.
+/// compareFunction: Less | Greater | LEqual | GEqual | Equal | NotEqual.
+/// value: Target Property Value used for comparison.
+public ShowIfDecorator(string propName, string comparisonMethod, float value) : this("And", propName, comparisonMethod, value) { }
+public ShowIfDecorator(string logicalOperator, string propName, string compareFunction, float value)
+```
+
+Example:
+
+```c#
+[ShowIf(_enum, Equal, 1)]
+[Title(ShowIf Main Samples)]
+[Main(GroupName)] _group ("Group", float) = 0
+[Sub(GroupName)] _float ("Float", float) = 0
+[Sub(GroupName)] _Tex ("Tex", 2D) = "white" { }
+
+...
+
+[SubTitle(Group1, Conditional Display Samples Enum)]
+[KWEnum(Group1, Name 1, _KEY1, Name 2, _KEY2, Name 3, _KEY3)] _enum ("KWEnum", float) = 0
+[Sub(Group1)][ShowIf(_enum, Equal, 0)] _key1_Float1 ("Key1 Float", float) = 0
+[Sub(Group1)][ShowIf(_enum, Equal, 1)] _key2_Float2 ("Key2 Float", float) = 0
+[SubIntRange(Group1)][ShowIf(_enum, Equal, 2)] _key3_Int_Range ("Key3 Int Range", Range(0, 10)) = 0
+[ShowIf(_enum, Equal, 0)][ShowIf(Or, _enum, Equal, 2)]
+[SubPowerSlider(Group1, 3)] _key13_PowerSlider ("Key1 or Key3 Power Slider", Range(0, 1)) = 0
+
+```
+
+| ![image-20231023010137495](./README_CN.assets/image-20231023010137495.png) | ![image-20231023010153213](./README_CN.assets/image-20231023010153213.png) | ![image-20231023010204399](./README_CN.assets/image-20231023010204399.png) |
+| ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ |
+
+
+
### Unity Builtin Drawers
diff --git a/package.json b/package.json
index 37962d8..64a2c55 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "com.jasonma.lwgui",
- "version": "1.12.2",
+ "version": "1.13.0",
"displayName": "LWGUI",
"description": "A Lightweight, Flexible, Powerful Shader GUI System for Unity.",
"keywords": [