具有枚举的Unity UI Onclick检查器 [英] Unity UI Onclick inspector with Enumeration
问题描述
我有一个问题.
这是我的检查器窗口.
对于On Click()窗口,我想设置为Enum类型的参数. 不是字符串或整数.
In case of On Click() window, I'd like to set parameter that is type of Enum. not string or int.
换句话说,我想用 无效的GoToNext(DATA_TYPE类型). 但这没有出现.
In other words, I'd like to use void GoToNext(DATA_TYPE type). But that doesn't show up.
即使我将枚举设置为[SerializedField],也不会在此窗口中显示.
Even if I set my enum as [SerializedField], that doesn't show in this window.
我该怎么做?
推荐答案
您目前无法执行此操作,Unity不支持.但是,由于枚举基本上是int,也许您可以设置函数以接受int并以某种方式将其强制转换为适当的enum?
You can't currently do this, Unity doesn't support it. But, since enums are basically ints, perhaps you could setup your function to accept an int and somehow cast it to the appropriate enum?
我用枚举编写的一些代码尝试了这个小实验,它似乎运行良好:
I tried this little experiment in some code I have with an enum, and it seemed to work fine:
public enum unitType {orc_warrior, archer, none};
int test2 = 0;
unitType test;
test = (unitType)test2;
Debug.Log(test);
test2 = 1;
test = (unitType)test2;
Debug.Log(test);
Debug正确打印出orc_warrior
,然后archer
Debug correctly printed out orc_warrior
and then archer
这篇关于具有枚举的Unity UI Onclick检查器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!