Is it possible to show a Partial enum in a custom inspector in Unity?

Viewed 734

Is there a way to only have certain enum values available in the inspector? For example I have an enum full of objects, and if I select table I want a second enum with specific object ids to only show table1/table2/table3 instead of all the available objects.

public enum Objects
{
    Chair,
    Table,
    Door
}

public enum ObjectIDs
{
    Chair01, 
    Chair02,
    Table01,
    Table02,
    Table03,
    etc..
}
2 Answers

you can modify this code to make what you want.

You need to change the EnumOrderDrawer class to make the loops not go for all the enum variables.

For example change the code

public const string TypeOrder = "10,1,5,2";
public enum Type 
    {
        One = 10,
        Two = 1,
        Three = 5,
        Four = 2,
    }

    [EnumOrder(TypeOrder)]
    public Type type3;
.
.
.
.
for (int i=0; i<property.enumNames.Length; i++) 
        {
             items[i] = property.enumNames[indexArray[i]];
        }

to

public const int[] TypeOrder = new int[] { 10, 1, 5, 2 };
public enum Type 
    {
        One = 10,
        Two = 1,
        Three = 5,
        Four = 2,
    }

    [EnumOrder(TypeOrder)]
    public Type type3;
.
.
.
.
for (int i=0; i<TypeOrder.Length; i++) 
        {
             items[i] = property.enumNames[indexArray[i]];
        }
.
.
.
.

Related