Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

search bar

Discussion in 'Immediate Mode GUI (IMGUI)' started by ozone00x, Jul 17, 2012.

  1. ozone00x

    ozone00x

    Joined:
    Sep 8, 2010
    Posts:
    37
    search bar can you make one in unity i want to have a list of words and when you search for a word a box of words would come up and you can pick from them
     
  2. ModStoryGames

    ModStoryGames

    Joined:
    Apr 27, 2012
    Posts:
    179
    Code (csharp):
    1.  
    2. // C# Code Snippet
    3. // Search Bar Example
    4. void OnGUI()
    5. {
    6.    searchText = GUILayout.TextField(searchText);
    7.    for (int i = 0; i < words.Count; i++)
    8.    {
    9.       if (string.IsNullOrEmpty(searchText) || words[i].Contains(searchText))
    10.       {
    11.          GUILayout.Button(words[i]);
    12.       }
    13.    }
    14. }
    15.  
    That should do the trick. In this snippet, "words" is a List<string> object, and searchText is a string. The snippet will draw all of the words in the list if there is no search text entered by the User, or only words that contain the search text entered by the User.
     
  3. MaT227

    MaT227

    Joined:
    Jul 3, 2012
    Posts:
    628
    Is it possible to easily copy the GUI style of the hierarchy or project search bar ?
     
  4. dkozar

    dkozar

    Joined:
    Nov 30, 2009
    Posts:
    1,410
    Many of the existing styles could be referenced using the static EditorSettings class (no Skin file required).

    Code (csharp):
    1. GUILayout.TextField(_text, EditorSettings.objectField);
     
  5. MaT227

    MaT227

    Joined:
    Jul 3, 2012
    Posts:
    628
    Hi,

    Thanks for your answer !
    I grabbed the Editor GUISkin like this to have the GUIStyle list and used it like this :

    Code (csharp):
    1.  
    2. EditorGUIUtility.LookLikeInspector();
    3. GUILayout.BeginHorizontal(GUI.skin.FindStyle("Toolbar"));
    4. searchString = GUILayout.TextField(searchString, GUI.skin.FindStyle("ToolbarSeachTextField"));
    5. if (GUILayout.Button("", GUI.skin.FindStyle("ToolbarSeachCancelButton")))
    6. {
    7.     // Remove focus if cleared
    8.     searchString = "";
    9.     GUI.FocusControl(null);
    10. }
    11. GUILayout.EndHorizontal();
    12.  
    btw1: Is there a link were all the editor styles are referenced ? I used a small trick to look at them but it could be cool to have all the built-in skins.
     
    Last edited: May 30, 2013
    LucaHofmann likes this.
  6. lloyd vicente

    lloyd vicente

    Joined:
    Sep 23, 2013
    Posts:
    4
    hello there, does anybody knows how to put or have a search bar in unity 3D? Wherein the user will just type a certain word and that word will lead to its corresponding destination. For example, a mini map is built on Unity 3D, and we want to locate a specific establishment. We want to do this just by simply typing the name of that building/establishment. Or can we have it as buttons?
     
  7. dkozar

    dkozar

    Joined:
    Nov 30, 2009
    Posts:
    1,410
    You can make a search bar having a TextField and a Button, like in this WebPlayer demo.

    You can check the TextField for changes, and make a search each time after:

    - the content of the TextField changes
    - the Enter key is pressed
    - the button is pressed

    $flickr.png
     
  8. lloyd vicente

    lloyd vicente

    Joined:
    Sep 23, 2013
    Posts:
    4
    sir how can i connect the search bar to my map?.
     
  9. lloyd vicente

    lloyd vicente

    Joined:
    Sep 23, 2013
    Posts:
    4
    sir where did you create that project?
     
  10. lloyd vicente

    lloyd vicente

    Joined:
    Sep 23, 2013
    Posts:
    4
    hi are creating a search bar in unity?