search bar

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

// C# Code Snippet
// Search Bar Example
void OnGUI()
{
   searchText = GUILayout.TextField(searchText);
   for (int i = 0; i < words.Count; i++)
   {
      if (string.IsNullOrEmpty(searchText) || words[i].Contains(searchText))
      {
         GUILayout.Button(words[i]);
      }
   }
}

That should do the trick. In this snippet, “words” is a List 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.

Is it possible to easily copy the GUI style of the hierarchy or project search bar ?

Many of the existing styles could be referenced using the static EditorSettings class (no Skin file required).

GUILayout.TextField(_text, EditorSettings.objectField);

Hi,

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

EditorGUIUtility.LookLikeInspector();
GUILayout.BeginHorizontal(GUI.skin.FindStyle("Toolbar"));
searchString = GUILayout.TextField(searchString, GUI.skin.FindStyle("ToolbarSeachTextField"));
if (GUILayout.Button("", GUI.skin.FindStyle("ToolbarSeachCancelButton")))
{
	// Remove focus if cleared
	searchString = "";
	GUI.FocusControl(null);
}
GUILayout.EndHorizontal();

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.

1 Like

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?

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

sir how can i connect the search bar to my map?.

sir where did you create that project?

hi are creating a search bar in unity?