Hide
ShowIf/HideIf
Important
Enable SaintsEditor before using

Show or hide the field based on a condition. Supports callbacks (function/field/property) and enum types. by using multiple arguments and decorators, you can make logic operation with it.

Arguments:

  • (Optional) EMode editorMode

    Condition: if it should be in edit mode, play mode for Editor or in some prefab stage. By default, (omitting this parameter) it does not check the mode at all.

    See Misc - EMode for more information.

  • object by...

    callbacks or attributes for the condition. For more information, see Callback section.

  • Allow Multiple: Yes

You can use multiple ShowIf, HideIf, and even a mix of the two.

For ShowIf: The field will be shown if ALL condition is true (and operation)

For HideIf: The field will be hidden if ANY condition is true (or operation)

For multiple attributes: The field will be shown if ANY condition is true (or operation)

For example, [ShowIf(A...), ShowIf(B...)] will be shown if ShowIf(A...) || ShowIf(B...) is true.

HideIf is the opposite of ShowIf. Please note "the opposite" is like the logic operation, like !(A && B) is !A || !B, !(A || B) is !A && !B.

  • HideIf(A) == ShowIf(!A)
  • HideIf(A, B) == HideIf(A || B) == ShowIf(!(A || B)) == ShowIf(!A && !B)
  • [Hideif(A), HideIf(B)] == [ShowIf(!A), ShowIf(!B)] == ShowIf(!A || !B)

A simple example:

using SaintsField.Playa; [ShowIf(nameof(ShouldShow))] public int showMe; public bool ShouldShow() // change the logic here { return true; } // This also works on static/const callbacks using `$:` [HideIf("$:" + nameof(Util) + "." + nameof(_shouldHide))] public int hideMe; // you can put this under another file like `Util.cs` public static class Util { [ShowInIspector] private static bool _shouldHide; }

It also supports enum types. The syntax is like this:

using SaintsField.Playa; [Serializable] public enum EnumToggle { Off, On, } public EnumToggle enum1; [ShowIf(nameof(enum1), EnumToggle.On)] public string enum1Show;

A more complex example:

using SaintsField.Playa; [Serializable] public enum EnumToggle { Off, On, } public EnumToggle enum1; public EnumToggle enum2; public bool bool1; public bool bool2 { return true; } // example of checking two normal callbacks and two enum callbacks [ShowIf(nameof(bool1), nameof(bool2), nameof(enum1), EnumToggle.On, nameof(enum2), EnumToggle.On)] public string bool12AndEnum12;

A more complex example about logic operation:

using SaintsField.Playa; public bool _bool1; public bool _bool2; public bool _bool3; public bool _bool4; [ShowIf(nameof(_bool1))] [ShowIf(nameof(_bool2))] [LabelText("<color=red>show=1||2")] public string _showIf1Or2; [ShowIf(nameof(_bool1), nameof(_bool2))] [LabelText("<color=green>show=1&&2")] public string _showIf1And2; [HideIf(nameof(_bool1))] [HideIf(nameof(_bool2))] [LabelText("<color=blue>show=!1||!2")] public string _hideIf1Or2; [HideIf(nameof(_bool1), nameof(_bool2))] [LabelText("<color=yellow>show=!(1||2)=!1&&!2")] public string _hideIf1And2; [ShowIf(nameof(_bool1))] [HideIf(nameof(_bool2))] [LabelText("<color=magenta>show=1||!2")] public string _showIf1OrNot2; [ShowIf(nameof(_bool1), nameof(_bool2))] [ShowIf(nameof(_bool3), nameof(_bool4))] [LabelText("<color=orange>show=(1&&2)||(3&&4)")] public string _showIf1234; [HideIf(nameof(_bool1), nameof(_bool2))] [HideIf(nameof(_bool3), nameof(_bool4))] [LabelText("<color=pink>show=!(1||2)||!(3||4)=(!1&&!2)||(!3&&!4)")] public string _hideIf1234;

Example about EMode:

using SaintsField.Playa; public bool boolValue; [ShowIf(EMode.Edit)] public string showEdit; [ShowIf(EMode.Play)] public string showPlay; [ShowIf(EMode.Edit, nameof(boolValue))] public string showEditAndBool; [ShowIf(EMode.Edit), ShowIf(nameof(boolValue))] public string showEditOrBool; [HideIf(EMode.Edit)] public string hideEdit; [HideIf(EMode.Play)] public string hidePlay; [HideIf(EMode.Edit, nameof(boolValue))] public string hideEditOrBool; [HideIf(EMode.Edit), HideIf(nameof(boolValue))] public string hideEditAndBool;

It also supports sub-field, and value comparison like ==, >, <=. Read more in the "Syntax for Show/Hide/Enable/Disable/Required-If" section.

// Please ensure you already have SaintsEditor enabled in your project before trying this example using SaintsField.Playa; public bool boolValue; [PlayaHideIf] public int[] justHide; [PlayaShowIf] public int[] justShow; [PlayaHideIf(nameof(boolValue))] public int[] hideIf; [PlayaShowIf(nameof(boolValue))] public int[] showIf; [PlayaHideIf(EMode.Edit)] public int[] hideEdit; [PlayaHideIf(EMode.Play)] public int[] hidePlay; [PlayaShowIf(EMode.Edit)] public int[] showEdit; [PlayaShowIf(EMode.Play)] public int[] showPlay; [ShowInInspector, PlayaHideIf(nameof(boolValue))] public const float HideIfConst = 3.14f; [ShowInInspector, PlayaShowIf(nameof(boolValue))] public const float ShowIfConst = 3.14f; [ShowInInspector, PlayaHideIf(EMode.Edit)] public const float HideEditConst = 3.14f; [ShowInInspector, PlayaHideIf(EMode.Play)] public const float HidePlayConst = 3.14f; [ShowInInspector, PlayaShowIf(EMode.Edit)] public const float ShowEditConst = 3.14f; [ShowInInspector, PlayaShowIf(EMode.Play)] public const float ShowPlayConst = 3.14f; [ShowInInspector, PlayaHideIf(nameof(boolValue))] public static readonly Color HideIfStatic = Color.green; [ShowInInspector, PlayaShowIf(nameof(boolValue))] public static readonly Color ShowIfStatic = Color.green; [ShowInInspector, PlayaHideIf(EMode.Edit)] public static readonly Color HideEditStatic = Color.green; [ShowInInspector, PlayaHideIf(EMode.Play)] public static readonly Color HidePlayStatic = Color.green; [ShowInInspector, PlayaShowIf(EMode.Edit)] public static readonly Color ShowEditStatic = Color.green; [ShowInInspector, PlayaShowIf(EMode.Play)] public static readonly Color ShowPlayStatic = Color.green; [Button, PlayaHideIf(nameof(boolValue))] private void HideIfBtn() => Debug.Log("HideIfBtn"); [Button, PlayaShowIf(nameof(boolValue))] private void ShowIfBtn() => Debug.Log("ShowIfBtn"); [Button, PlayaHideIf(EMode.Edit)] private void HideEditBtn() => Debug.Log("HideEditBtn"); [Button, PlayaHideIf(EMode.Play)] private void HidePlayBtn() => Debug.Log("HidePlayBtn"); [Button, PlayaShowIf(EMode.Edit)] private void ShowEditBtn() => Debug.Log("ShowEditBtn"); [Button, PlayaShowIf(EMode.Play)] private void ShowPlayBtn() => Debug.Log("ShowPlayBtn");

image

It also supports sub-field, and value comparison like ==, >, <=. Read more in the "Syntax for Show/Hide/Enable/Disable/Required-If" section.