Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Binding generated UXML Enum with C#

Discussion in 'UI Toolkit' started by Fritsl, Aug 14, 2020.

  1. Fritsl

    Fritsl

    Joined:
    Mar 10, 2013
    Posts:
    211
    Am learning how to do Editor Window w UI Toolkit

    UI Toolkit: Inserted Enum
    C#: Q'ed Enum, initiated like this:

    Code (CSharp):
    1. enum UIstates { listIsEmpty, browseList, editItem, addNEwItem }
    2. debugUIstate = root.Query<EnumField>("debugUIstate");
    3. debugUIstate.Init(UIstates.browseList);
    Now Enum shows up in Editor window, with Init state, good!

    Question:
    How would I get the Enum Value OUT in C#?

    Thanks :)
     
  2. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,231
    Code (CSharp):
    1. var val = debugUIstate.value;
    should do the trick. Might need a cast.

    We have a built-in sample for EnumField under Windows > UI Toolkit > Samples for more details.
     
  3. Fritsl

    Fritsl

    Joined:
    Mar 10, 2013
    Posts:
    211
    Thanks - there was that problem of the Windows > UI Toolkit > Samples did not appear to show anything other than a list of functions -> window had to be resized ;)