FieldShowIf / FieldHideIfWarningDeprecated. UseShowIf/HideIfinstead.
Only use this if you can NOT have SaintsEditor enabled. If you can not use SaintsEditor, you should be able to use an alternative ShowIf/HideIf provided by the editor plugin you're globally 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 editorModeCondition: 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-EModefor more information. -
object by...callbacks or attributes for the condition. For more information, see
Callbacksection. -
AllowMultiple: Yes
You can use multiple FieldShowIf, FieldShowIf, and even a mix of the two.
For FieldShowIf: The field will be shown if ALL condition is true (and operation)
For FieldShowIf: 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, [FieldShowIf(A...), FieldShowIf(B...)] will be shown if FieldShowIf(A...) || FieldShowIf(B...) is true.
FieldHideIf is the opposite of FieldShowIf. Please note "the opposite" is like the logic operation, like !(A && B) is !A || !B, !(A || B) is !A && !B.
FieldHideIf(A)==FieldShowIf(!A)FieldHideIf(A, B)==FieldHideIf(A || B)==FieldShowIf(!(A || B))==FieldShowIf(!A && !B)[FieldHideIf(A), FieldHideIf(B)]==[FieldShowIf(!A), FieldShowIf(!B)]==FieldShowIf(!A || !B)
A simple example:
using SaintsField; [FieldShowIf(nameof(ShouldShow))] public int showMe; public bool ShouldShow() // change the logic here { return true; } // This also works on static/const callbacks using `$:` [FieldHideIf("$:" + 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; [Serializable] public enum EnumToggle { Off, On, } public EnumToggle enum1; [FieldShowIf(nameof(enum1), EnumToggle.On)] public string enum1Show;
A more complex example:
using SaintsField; [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 [FieldShowIf(nameof(bool1), nameof(bool2), nameof(enum1), EnumToggle.On, nameof(enum2), EnumToggle.On)] public string bool12AndEnum12;
A more complex example about logic operation:
using SaintsField; public bool _bool1; public bool _bool2; public bool _bool3; public bool _bool4; [FieldShowIf(nameof(_bool1))] [FieldShowIf(nameof(_bool2))] [LabelText("<color=red>show=1||2")] public string _showIf1Or2; [FieldShowIf(nameof(_bool1), nameof(_bool2))] [LabelText("<color=green>show=1&&2")] public string _showIf1And2; [FieldHideIf(nameof(_bool1))] [FieldHideIf(nameof(_bool2))] [LabelText("<color=blue>show=!1||!2")] public string _hideIf1Or2; [FieldHideIf(nameof(_bool1), nameof(_bool2))] [LabelText("<color=yellow>show=!(1||2)=!1&&!2")] public string _hideIf1And2; [FieldShowIf(nameof(_bool1))] [FieldHideIf(nameof(_bool2))] [LabelText("<color=magenta>show=1||!2")] public string _showIf1OrNot2; [FieldShowIf(nameof(_bool1), nameof(_bool2))] [FieldShowIf(nameof(_bool3), nameof(_bool4))] [LabelText("<color=orange>show=(1&&2)||(3&&4)")] public string _showIf1234; [FieldHideIf(nameof(_bool1), nameof(_bool2))] [FieldHideIf(nameof(_bool3), nameof(_bool4))] [LabelText("<color=pink>show=!(1||2)||!(3||4)=(!1&&!2)||(!3&&!4)")] public string _hideIf1234;
Example about EMode:
using SaintsField; public bool boolValue; [FieldShowIf(EMode.Edit)] public string showEdit; [FieldShowIf(EMode.Play)] public string showPlay; [FieldShowIf(EMode.Edit, nameof(boolValue))] public string showEditAndBool; [FieldShowIf(EMode.Edit), FieldShowIf(nameof(boolValue))] public string showEditOrBool; [FieldHideIf(EMode.Edit)] public string hideEdit; [FieldHideIf(EMode.Play)] public string hidePlay; [FieldHideIf(EMode.Edit, nameof(boolValue))] public string hideEditOrBool; [FieldHideIf(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.