Namespace: | Sirenix.OdinInspector |
Assembly: | Sirenix.OdinInspector.Attributes |
[DontApplyToListElements]
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Module | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Parameter | AttributeTargets.Delegate | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter | AttributeTargets.All, AllowMultiple = true, Inherited = true)]
[Conditional("UNITY_EDITOR")]
public sealed class EnableIfAttribute : Attribute, _Attribute
EnableIf is used on any property, and can enable or disable the property in the inspector.
Use this to enable properties when they are relevant.
The following example shows how a property can be enabled by the state of a field.
public class MyComponent : MonoBehaviour
{
public bool EnableProperty;
[EnableIf("EnableProperty")]
public int MyInt;
public SomeEnum SomeEnumField;
[EnableIf("SomeEnumField", SomeEnum.SomeEnumMember)]
public string SomeString;
}
The following examples show how a property can be enabled by a function.
public class MyComponent : MonoBehaviour
{
[EnableIf("MyEnableFunction")]
public int MyInt;
private bool MyEnableFunction()
{
// ...
}
}
public EnableIfAttribute(string condition)
System.String | condition | A resolved string that defines the condition to check the value of, such as a member name or an expression. |
public EnableIfAttribute(string condition, object optionalValue)
System.String | condition | A resolved string that defines the condition to check the value of, such as a member name or an expression. |
System.Object | optionalValue | Value to check against. |
public string Condition
public object Value