From aafde9ca6f5ee3256bd2a5ce8cad6a2c4ef829fc Mon Sep 17 00:00:00 2001 From: Jason Ma <1312119064@qq.com> Date: Fri, 17 Nov 2023 18:38:08 +0800 Subject: [PATCH] add fuzzy matched comparisonMethod --- Editor/ShaderDrawer.cs | 26 ++++++++++++++++++++++---- README.md | 2 +- README_CN.md | 2 +- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/Editor/ShaderDrawer.cs b/Editor/ShaderDrawer.cs index dff0f41..f462ab6 100644 --- a/Editor/ShaderDrawer.cs +++ b/Editor/ShaderDrawer.cs @@ -1334,22 +1334,40 @@ public override void DrawProp(Rect position, MaterialProperty prop, GUIContent l /// 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 | Equal | LessEqual | Greater | NotEqual | GreaterEqual. + /// compareFunction: Less (L) | Equal (E) | LessEqual (LEqual / LE) | Greater (G) | NotEqual (NEqual / NE) | GreaterEqual (GEqual / GE). /// value: Target Property Value used for comparison. /// public class ShowIfDecorator : SubDrawer { private ShowIfData _showIfData = new ShowIfData(); + private readonly Dictionary _compareFunctionLUT = new Dictionary() + { + { "Less", "Less" }, + { "L", "Less" }, + { "Equal", "Equal" }, + { "E", "Equal" }, + { "LessEqual", "LessEqual" }, + { "LEqual", "LessEqual" }, + { "LE", "LessEqual" }, + { "Greater", "Greater" }, + { "G", "Greater" }, + { "NotEqual", "NotEqual" }, + { "NEqual", "NotEqual" }, + { "NE", "NotEqual" }, + { "GreaterEqual", "GreaterEqual" }, + { "GEqual", "GreaterEqual" }, + { "GE", "GreaterEqual" }, + }; 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 | Equal | LessEqual | Greater | NotEqual | GreaterEqual."); + if (!_compareFunctionLUT.ContainsKey(compareFunction) || !Enum.IsDefined(typeof(CompareFunction), _compareFunctionLUT[compareFunction])) + Debug.LogError("Invalid compareFunction: '" + compareFunction + "', Must be one of the following: Less (L) | Equal (E) | LessEqual (LEqual / LE) | Greater (G) | NotEqual (NEqual / NE) | GreaterEqual (GEqual / GE)."); else - _showIfData.compareFunction = (CompareFunction)Enum.Parse(typeof(CompareFunction), compareFunction); + _showIfData.compareFunction = (CompareFunction)Enum.Parse(typeof(CompareFunction), _compareFunctionLUT[compareFunction]); _showIfData.value = value; } diff --git a/README.md b/README.md index 41c55a5..837209a 100644 --- a/README.md +++ b/README.md @@ -596,7 +596,7 @@ public Hidden() /// 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 | Equal | LessEqual | Greater | NotEqual | GreaterEqual. +/// compareFunction: Less (L) | Equal (E) | LessEqual (LEqual / LE) | Greater (G) | NotEqual (NEqual / NE) | GreaterEqual (GEqual / GE). /// 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) diff --git a/README_CN.md b/README_CN.md index 5b66ee6..98b8da1 100644 --- a/README_CN.md +++ b/README_CN.md @@ -595,7 +595,7 @@ public Hidden() /// 可以根据多个条件控制单个或者一组属性的显示 / 隐藏. /// logicalOperator: And | Or (Default: And). /// propName: Target Property Name used for comparison. -/// compareFunction: Less | Equal | LessEqual | Greater | NotEqual | GreaterEqual. +/// compareFunction: Less (L) | Equal (E) | LessEqual (LEqual / LE) | Greater (G) | NotEqual (NEqual / NE) | GreaterEqual (GEqual / GE). /// 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)