在Unity中的自定义检视面板中,是否有可能显示部分枚举?

3

有没有办法只在检视面板中提供特定枚举值?例如,我有一个充满对象的枚举,如果我选择表格,我希望第二个枚举只显示特定对象ID,比如只显示table1/table2/table3,而不是所有可用的对象。

public enum Objects
{
    Chair,
    Table,
    Door
}

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

也许您可以使用 Enum.GetNames 来接收整个 ObjectIDs 名称列表,然后使用所选 Objects 值的名称进行过滤,再使用 Enum.GetValue 传递每个已过滤的名称。 - Stefano Cavion
2个回答

0

0

你可以修改这段代码来实现你想要的功能。

你需要修改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]];
        }
.
.
.
.


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接