【问题标题】:C# Unity searchbar with inputfield and dropdown, dynamic values带有输入字段和下拉列表、动态值的 C# Unity 搜索栏
【发布时间】: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


【解决方案1】:

我有类似的问题,并试图在 2 天内解决它......我现在做到了! 尽量不要使用 dropdown.Hide();,而是使用 dropdown.gameObject.SetActive() 停用和激活游戏对象。并在激活后制作 dropdown.Show();。它也可以在同一帧中工作,但每次都会闪烁)))

【讨论】:

    猜你喜欢
    • 2022-07-21
    • 1970-01-01
    • 1970-01-01
    • 2018-12-30
    • 2020-11-26
    • 1970-01-01
    • 1970-01-01
    • 2016-10-19
    • 2015-01-10
    相关资源
    最近更新 更多