这是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();
}
同样,它适用于第一个字母,第三个字母...但不适用于第二个和第四个字母,下拉菜单不显示(因为每次都会调用此功能...
我也遇到类似的问题,并试图在2天之内解决它……现在我做到了!尽量不要使用dropdown.Hide();,而是使用dropdown.gameObject.SetActive()停用和激活游戏对象。然后激活dropdown.Show();。它也可以在同一帧中工作,但是每次都会闪烁)))