Search code examples
user-interfaceunity-game-engineenumsinspector

Unity UI Onclick inspector with Enumeration


I have a question.

enter image description here

Here's My inspector Window.

In case of On Click() window, I'd like to set parameter that is type of Enum. not string or int.

In other words, I'd like to use void GoToNext(DATA_TYPE type). But that doesn't show up.

Even if I set my enum as [SerializedField], that doesn't show in this window.

How can I do this?


Solution

  • 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 correctly printed out orc_warrior and then archer