Skip to content

Commit

Permalink
add fuzzy matched comparisonMethod
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonMa0012 committed Nov 17, 2023
1 parent b7a35e3 commit aafde9c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
26 changes: 22 additions & 4 deletions Editor/ShaderDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1334,22 +1334,40 @@ public override void BuildStaticMetaData(Shader inShader, MaterialProperty inPro
/// 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.
/// </summary>
public class ShowIfDecorator : SubDrawer
{
private ShowIfData _showIfData = new ShowIfData();
private readonly Dictionary<string, string> _compareFunctionLUT = new Dictionary<string, string>()
{
{ "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;
}

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit aafde9c

Please sign in to comment.