C#Unity搜索栏,带有输入字段和下拉菜单,动态值



这是C#/Unity,编辑器配置正确。

我让这个输入字段搜索栏工作,背景下拉列表显示动态值,但这个下拉列表只显示在奇数字符上(第一个、第三个……而不是第二个、第四个……(

此处:

//call whenever the input field changes, even OR odd, its working
public void newSearchFieldValueChanged()
{
//read the input field, ok...   
searchText = newSearchField.text;
//return when empty...
if (string.IsNullOrEmpty(searchText)) return;
//I need to hide the dropdown   
dropdown.Hide();
//clear its old options
dropdown.ClearOptions();
//this is a dictionary to fill the dropdown options, clear it
dicTemp.Clear();
//add a first empty value
dicTemp.Add("", "0");
//so I run for another dic, that dont change its original values 
for (int i = 0; i < dic.Keys.Count; i++)
{
//if it contains in its keys the word typed in the search bar...
if (dic.Keys.ElementAt(i).ToLower().Contains(searchText.ToLower()))
{
//I add it to the cleared dicTemp that will fill the dropdown options   
dicTemp.Add(dic.Keys.ElementAt(i), dic.Values.ElementAt(i));
}
}
//fill the dropdown options with the new dicTemp, each time something changes
dropdown.AddOptions(dicTemp.Keys.ToList());
//duh
dropdown.Show();
//keep the focus on input field to continue type (dropdown selected by mouse)
newSearchField.ActivateInputField();
}

同样,它对第一个字母有效,第三个。。。但不是在第二个和第四个,下拉列表不会出现(除了每次调用函数之外(。。。

我遇到了类似的问题,并试图在两天内解决。。。我现在做到了!尽量不要使用下拉菜单。隐藏((,但使用下拉菜单停用并激活gameobject.gameobject.SetActive((。激活后使出现下拉菜单。显示((。它也在同一帧中工作,但每次都会闪烁((

最新更新