Панель поиска C # Unity с полем ввода и раскрывающимся списком, динамические значения - PullRequest
0 голосов
/ 01 ноября 2019

Это 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();
}

Опять же, он работает с первой буквой и третьей ... но не с второйи, в-четвертых, выпадающий список НЕ ПОКАЗЫВАЕТСЯ (кроме того, что функция вызывается каждый раз) ...

...