Conditionals
Last updated
Last updated
Displays the variable in the inspector only if the condition set with ComparisonType parameter is true between compared variable and condition value.
Supported property types
Everything.
Parameters
ComparedVariableName
ConditionValue
ComparisonType
DisablingType
Compared variable and condition value must be the same type and only work with bool, enum, float, int and string.
Code Example
using UltimateAttributesPack;
public class ShowIfExample : MonoBehaviour
{
public bool showFloat;
[ShowIf("showFloat", true)] // You can use it to show variables if a bool is on a specific state
public float floatValue;
[Space]
public float showIntIfSuperiorTo5;
[ShowIf("showIntIfSuperiorTo5", 5, ComparisonType.GreaterThan)] // You can also use it with numeric comparison
public int intValue;
[Space]
public string showStringIfEqualTo4;
[ShowIf("showStringIfEqualTo4", 4, ComparisonType.Equals)] // It also works with string lenght (characters number is the value)
public string stringValue;
[Space]
public string writeYesToShow = "Yes";
[ShowIf("writeYesToShow", "Yes", ComparisonType.Equals)] // It also works with string comparison
public string secondStringValue;
[Space]
public bool readOnlyShowIf;
[ShowIf("readOnlyShowIf", true, ComparisonType.Equals, DisablingType.ReadOnly)] // You can also set the disabling type to readonly if you want it to be visible in readonly in the inspector when it's disabled
public string thirdStringValue;
}
Displays the variable in the inspector only if the project is in edit mode.
Supported property types
Everything.
Parameters
DisablingType
Code Example
using UltimateAttributesPack;
public class ShowOnlyInEditModeExample : MonoBehaviour
{
// ShowOnlyInEditMode displays the variable only in edit mode
[ShowOnlyInEditMode]
public float floatValue;
// You can also set the param to ReadOnly to show the variable in readonly when it's disabled
[ShowOnlyInEditMode(DisablingType.ReadOnly)]
public int intValue;
}
Displays the variable in the inspector only if the project is in play mode.
Supported property types
Everything.
Parameters
DisablingType
Code Example
using UltimateAttributesPack;
public class ShowOnlyInPlayModeExample : MonoBehaviour
{
// ShowOnlyInEditMode displays the variable only in edit mode
[ShowOnlyInPlayMode]
public float floatValue;
// You can also set the param to ReadOnly to show the variable in readonly when it's disabled
[ShowOnlyInPlayMode(DisablingType.ReadOnly)]
public int intValue;
}
Executes a function if the variable change.
Supported property types
Everything.
Parameters
FunctionName
ClassType
Code Example
using UltimateAttributesPack;
public class DoOnValueChangedExample : MonoBehaviour
{
// You can use it to execute a function if a value has changed
[DoOnValueChanged("LogMessageOnValueChanged", typeof(DoOnValueChangedExample))]
public float floatValue;
void LogMessageOnValueChanged()
{
Debug.Log("The value has changed");
}
}