Hide
Syntax for Show/Hide/Enable/Disable/Required-If

This applies to ShowIf, HideIf, EnableIf, DisableIf, RequiredIf, PlayaShowIf, PlayaHideIf, PlayaEnableIf, PlayaDisableIf.

These decorators accept many objects.

By Default

Passing many strings, each string is represent either a field, property or a method. SaintsField will check the value accordingly. If it's a method, it'll also receive the field's value and index if it's inside an array/list.

Sub Field

You can use dot (.) to obtain a sub-field from a field/property/method. This is useful if your condition is relayed on a sub-field of a field.

using SaintsField; [GetComponentInChildren, Expandable] public ToggleSub toggle; // Show if toggle.requireADescription is a truly value [ShowIf(nameof(toggle) + ".requireADescription")] public string description; // ToggleSub.cs public class ToggleSub : MonoBehaviour { [LeftToggle] public bool requireADescription; }

Value Equality

You can also pass a string, then followed by a value you want to compare with. For example:

using SaintsField; public int myInt; [EnableIf(nameof(myInt), 2] public int enableIfEquals2;

This field will only be enabled if the myInt is equal to 2.

This can be mixed with many pairs:

using SaintsField; public int myInt1; public int myInt2; [EnableIf(nameof(myInt1), 2, nameof(myInt2), 3] public int enableIfMultipleCondition;

multiple conditions are logically chained accordingly. See each section of these decorators for more information.

Value Comparison

The string can have ! prefix to negate the comparison.

And ==, !=, > etc. suffix for more comparison you want. The suffix supports:

Comparison Suffixes:

  • ==: equal to the next parameter
  • ==$: equal, but the value is a callback by the next parameter
  • !=: not equal to the next parameter
  • >: greater than the next parameter
  • >$: greater than, but the value is a callback by the next parameter
  • <: less than the next parameter
  • <$: less than, but the value is a callback by the next parameter
  • >=: greater or equal to the next parameter
  • >=$: greater or equal, but the value is a callback by the next parameter
  • <=: less or equal to the next parameter
  • <=$: less or equal, but the value is a callback by the next parameter

Bitwise Suffixes:

  • &: bitwise and with the next parameter
  • &$: bitwise and, but the value is a callback by the next parameter
  • ^: bitwise xor with the next parameter
  • ^$: bitwise xor, but the value is a callback by the next parameter
  • &==: bitwise has flag of the next parameter
  • &==$: bitwise has flag, but the value is a callback by the next parameter

Some examples:

using SaintsField; public bool boolValue; [EnableIf("!" + nameof(boolValue)), LabelText("Reverse!")] public string boolValueEnableN; [Range(0, 2)] public int int01; [EnableIf(nameof(int01), 1), LabelText("default")] public string int01Enable1; [EnableIf(nameof(int01) + ">=", 1), LabelText(">=1")] public string int01EnableGe1; [EnableIf("!" + nameof(int01) + "<=", 1), LabelText("! <=1")] public string int01EnableNLe1; [Range(0, 2)] public int int02; // we need the "==
quot; to tell the next string is a value callback, not a condition checker
[EnableIf(nameof(int01) + "==
quot;
, nameof(int02)), LabelText("==
quot;
)] public string int01Enable1Callback; [EnableIf(nameof(int01) + "<
quot;
, nameof(int02)), LabelText("<
quot;
)] public string int01EnableLt1Callback; [EnableIf("!" + nameof(int01) + ">
quot;
, nameof(int02)), LabelText("! >
quot;
)] public string int01EnableNGt1Callback; // example of bitwise [Serializable] public enum EnumOnOff { A = 1, B = 1 << 1, } [Space] [Range(0, 3)] public int enumOnOffBits; [EnableIf(nameof(enumOnOffBits) + "&", EnumOnOff.A), LabelText("&01")] public string bitA; [EnableIf(nameof(enumOnOffBits) + "^", EnumOnOff.B), LabelText("^10")] public string bitB; [EnableIf(nameof(enumOnOffBits) + "&==", EnumOnOff.B), LabelText("hasFlag(B)")] public string hasFlagB;

Default Value Comparison

When passing the parameters, any parameter that is not a string, means it's a value comparison to the previous one.

(Which also means, to compare with a literal string value, you need to suffix the previous string with ==)

[ShowIf(nameof(MyFunc), 3)] means it will check if the result of MyFunc equals to 3.

However, if the later parameter is a bitMask (an enum with [Flags]), it'll check if the target has the required bit on:

using SaintsField; [Flags, Serializable] public enum EnumF { A = 1, B = 1 << 1, } [EnumFlags] public EnumF enumF; [EnableIf(nameof(enumF), EnumF.A), LabelText("hasFlag(A)")] public string enumFEnableA; [EnableIf(nameof(enumF), EnumF.B), LabelText("hasFlag(B)")] public string enumFEnableB; [EnableIf(nameof(enumF), EnumF.A | EnumF.B), LabelText("hasFlag(A | B)")] public string enumFEnableAB;