DisableIfAttribute

DisableIf is used on any property, and can disable or enable the property in the inspector.

Use this to disable properties when they are irrelevant.

namespace Sirenix.OdinInspector
{
[DontApplyToListElementsAttribute]
[AttributeUsageAttribute((AttributeTargets)448, AllowMultiple = False, Inherited = True)]
public sealed class DisableIfAttribute : Attribute
}

Requirements

Namespace: Sirenix.OdinInspector
Assembly: Sirenix.OdinInspector
Version: 1.0.6.1

See Also

Constructors

Definition Description
DisableIfAttribute(string) Disables a property in the inspector, based on the state of a member.
DisableIfAttribute(string, Object) Disables a property in the inspector, if the specified member returns the specified value.

Properties

Return Type Definition Description
string MemberName The name of a bool member field, property or method.
Object Value The optional member value.

Example

The following example shows how a property can be disabled by the state of a field.

public class MyComponent : MonoBehaviour
{
	public bool DisableProperty;

	[DisableIf("DisableProperty")]
	public int MyInt;
	
    public SomeEnum SomeEnumField;
	
	[DisableIf("SomeEnumField", SomeEnum.SomeEnumMember)]
	public string SomeString;
}

Example

The following examples show how a property can be disabled by a function.

public class MyComponent : MonoBehaviour
{
	[EnableIf("MyDisableFunction")]
	public int MyInt;

	private bool MyDisableFunction()
	{
		// ...
	}
}