首页 > 解决方案 > 是否可以在 Unity 的自定义检查器中显示部分枚举?

问题描述

有没有办法在检查器中只提供某些枚举值?例如,我有一个充满对象的枚举,如果我选择表,我希望第二个具有特定对象 id 的枚举仅显示 table1/table2/table3 而不是所有可用的对象。

public enum Objects
{
    Chair,
    Table,
    Door
}

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

标签: c#unity3denums

解决方案


您可以修改此代码以制作您想要的内容。

您需要更改EnumOrderDrawer类以使循环不适用于所有enum变量。

例如更改代码

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]];
        }

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]];
        }
.
.
.
.


推荐阅读