【发布时间】:2020-02-27 23:58:31
【问题描述】:
这是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();
}
同样,它适用于第一个字母和第三个...但不适用于第二个和第四个,下拉菜单不显示(除了每次都调用函数)...
【问题讨论】:
-
嗨@Hogan 对不起,你是什么意思?
-
哦,是的,我做了 dropdown.RefreshShownValue();我想,这就是这里的等价物。到处放,没用...谢谢
-
嗯...这个刷新是 System.Windows.Forms,通过链接...但这个问题不是 Windows 窗体...它的引擎 Unity...
-
我知道,里面没有太多“描述”...
标签: c# unity3d input dropdown searchbar