【问题标题】:Unity3D how to stop dropdown from duplicate the add?Unity3D如何停止下拉重复添加?
【发布时间】:2019-03-05 04:38:31
【问题描述】:

我尝试在按下加载按钮时创建下拉菜单填充保存文件问题是当我按下加载按钮时它再次加载相同的文件我尝试 indexof 但仍然复制文件我如何解决这个问题?!

     string[] getfilesname()
{
    string folderPath = Path.Combine(Application.persistentDataPath, foldername);
    string[] filePaths = Directory.GetFiles(folderPath, "*.txt");
    foreach (string file in filePaths)
    {
        var onlyFileName = Path.GetFileNameWithoutExtension(file);
        if (mylist.IndexOf(onlyFileName) == -1)
        {
            mylist.Add(onlyFileName);
        }
        Debug.Log(onlyFileName);
    }
    dropi.AddOptions(mylist);
    return filePaths;
}

enter image description here

【问题讨论】:

    标签: c# visual-studio unity3d


    【解决方案1】:

    IndexOf 方法应该处理 mylist 中的重复项,但您总是调用 dropi.AddOptions(mylist); 方法,这将再次添加列表的内容。

    您应该清除mylist 并在Load 方法的开头调用dropi.ClearOptions();,这种情况在您的情况下是可能的。这样你也摆脱了if( ...IndexOf("") == -1)

    【讨论】:

    • 感谢您的帮助,您的回答解决了我的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-24
    • 2020-07-21
    • 2019-12-20
    • 2023-03-12
    • 2023-03-17
    相关资源
    最近更新 更多