New UI Search System

Hello,
I’m working on a search system running in runtime.
With a Input field, you can seek for a word and then display all the correspondence.

With the old GUI system it was quite simple, but now I would like to use the New UI.
And I don’t know how to do to make it simple without using several time per frame Destroy and
Instantiate.

I was thinking to create something maybe less dynamic, like let the users type the entire word and after that call a function who display the correspondence.

But that’s my last solution.

That’s the Old Version

void Start ()
    {
        objectsContains = new List<GameObject>(objects);
    }
  
    // Update is called once per frame
    void Update ()
    {
        a = 0;
      
        for (int i = 0; i < Objects.Count; i++)

            if(objects[i].name.ToUpper().Contains(searchText.ToUpper()))
            {
                objectsContains[a] = objects[i];
                a++;
              
            }
    }
  
    void OnGUI()
    {
         GUILayout.BeginHorizontal(EditorStyles.toolbar);
         GUILayout.FlexibleSpace();
         searchText = GUILayout.TextField(searchText, EditorStyles.toolbarTextField);
         GUILayout.EndHorizontal();
         searchText = GUI.TextField (new Rect (25, 25, 210, 30),searchText);
       
         if(searchText.Length != 0)
         {
            for (int ai = 0; ai < a; ai++)
            {
                GUI.Button(new Rect (25, 50+(ai+1)*35, 210, 30),(objectsContains[ai].name));
             }
         }
       
    }

I know the last solution is the most optimized or maybe stay with the Old Version but I’m sure there is a way to do it with the New UI system.

Thanks for your help :slight_smile:

You can check out the AutoComplete combo box in the UI Extensions, seems to do what your looking for (link in sig)

1 Like

Thanks I think it’s what I need, I have trouble making it work, but I’ll do it myself this time :wink:

Thanks Simon :slight_smile:

Well, this announcement today might help with that :wink:
http://forum.unity3d.com/threads/unity-ui-extensions-project-gets-a-big-update.351641/

1 Like