Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

How to create a List<T> in UIElements?

Discussion in 'UI Toolkit' started by KosaJr, Jul 18, 2019.

  1. KosaJr

    KosaJr

    Joined:
    Jan 3, 2017
    Posts:
    8
    Is it possible to create a List<T> with UIElements, when the List<T> is in the same class as MyEditor? I want to create/map/bind it in .uxml file, but dont know how (or is it even possible).

    in example (blabla code):
    Code (CSharp):
    1. public class MyEditor : EditorWindow
    2. {
    3.       public List<string> someStringList = new List<string>();
    4.  
    5.       // Rest of EditorWindow code...
    6. }
     
  2. AlexandreT-unity

    AlexandreT-unity

    Unity Technologies

    Joined:
    Feb 1, 2018
    Posts:
    46
    The ability to declare a generic list in a class is independent from UIElements. Just add
    using System.Collections.Generic;
    at the top of your file, or use the full name of
    System.Collections.Generic.List<T>
    .
     
  3. KosaJr

    KosaJr

    Joined:
    Jan 3, 2017
    Posts:
    8
    Yes, I know that :) I mean, how to make this list visible in my editor (not inspector) Window in Unity.
    For example (in uxml file) : <TextField class="tf" name="myname" /> creates a Text field. How to create a list/array in that way?

    == SOLVED ==
    I figured it out! Simply I just need this:
    Code (CSharp):
    1. rootVisualElement.Q<PropertyField>("stringList").Bind(new SerializedObject(this));
    and properly configured UXML:
    Code (CSharp):
    1. <ue:PropertyField name="stringList" label="Unaccepted climates: " binding-path="stringes"/>
    , where "stringes" is my List<string> variable name located in MyEditor.
     

    Attached Files:

    Last edited: Jul 19, 2019
unityunity