Namespace: | Sirenix.OdinInspector |
Assembly: | Sirenix.OdinInspector.Attributes |
[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 = false, Inherited = true)]
[Conditional("UNITY_EDITOR")]
public class ValueDropdownAttribute : Attribute, _Attribute
ValueDropdown is used on any property and creates a dropdown with configurable options.
Use this to give the user a specific set of options to select from.
Due to a bug in Unity, enums will sometimes not work correctly. The last example shows how this can be fixed.
The following example shows a how the ValueDropdown can be used on an int property.
public class MyComponent : MonoBehaviour
{
[ValueDropdown("myValues")]
public int MyInt;
// The selectable values for the dropdown.
private int[] myValues = { 1, 2, 3 };
}
The following example shows how ValueDropdownList can be used for objects, that do not implement a usable ToString.
public class MyComponent : MonoBehaviour
{
[ValueDropdown("myVectorValues")]
public Vector3 MyVector;
// The selectable values for the dropdown, with custom names.
private ValueDropdownList<Vector3> myVectorValues = new ValueDropdownList<Vector3>()
{
{"Forward", Vector3.forward },
{"Back", Vector3.back },
{"Up", Vector3.up },
{"Down", Vector3.down },
{"Right", Vector3.right },
{"Left", Vector3.left },
};
}
The following example shows how the ValueDropdown can on any member that implements IList.
public class MyComponent : MonoBehaviour
{
// Member field of type float[].
private float[] valuesField;
[ValueDropdown("valuesField")]
public float MyFloat;
// Member property of type List<thing>.
private List<string> ValuesProperty { get; set; }
[ValueDropdown("ValuesProperty")]
public string MyString;
// Member function that returns an object of type IList.
private IList<ValueDropdownItem<int>> ValuesFunction()
{
return new ValueDropdownList<int>
{
{ "The first option", 1 },
{ "The second option", 2 },
{ "The third option", 3 },
};
}
[ValueDropdown("ValuesFunction")]
public int MyInt;
}
Due to a bug in Unity, enums member arrays will in some cases appear as empty. This example shows how you can get around that.
public class MyComponent : MonoBehaviour
{
// Make the field static.
private static MyEnum[] MyStaticEnumArray = MyEnum[] { ... };
// Force Unity to serialize the field, and hide the property from the inspector.
[SerializeField, HideInInspector]
private MyEnum MySerializedEnumArray = MyEnum[] { ... };
}
public ValueDropdownAttribute(string valuesGetter)
System.String | valuesGetter | A resolved string that should evaluate to a value that is assignable to IList; e.g, arrays and lists are compatible. |
public bool AppendNextDrawer
public bool CopyValues
public bool DisableGUIInAppendedDrawer
public bool DisableListAddButtonBehaviour
public bool DoubleClickToConfirm
public bool DrawDropdownForListElements
public int DropdownHeight
public string DropdownTitle
public int DropdownWidth
public bool ExcludeExistingValuesInList
public bool ExpandAllMenuItems
public bool FlattenTreeView
public bool HideChildProperties
public bool IsUniqueList
public int NumberOfItemsBeforeEnablingSearch
public bool OnlyChangeValueOnConfirm
public bool SortDropdownItems
public string ValuesGetter