C#实现下拉菜单选择文件夹
时间: 2023-11-13 17:05:16 浏览: 162
要在C#中实现下拉菜单选择文件夹,可以使用Unity的EditorGUILayout下拉菜单和EditorUtility.OpenFolderPanel方法。下面是一个示例代码:
```csharp
using UnityEngine;
using UnityEditor;
public class FolderSelectionWindow : EditorWindow
{
private string selectedFolder;
\[MenuItem("Window/Folder Selection")\]
public static void ShowWindow()
{
GetWindow<FolderSelectionWindow>("Folder Selection");
}
private void OnGUI()
{
GUILayout.Label("Select a folder:", EditorStyles.boldLabel);
if (GUILayout.Button("Select Folder"))
{
selectedFolder = EditorUtility.OpenFolderPanel("Select Folder", "", "");
}
GUILayout.Label("Selected Folder: " + selectedFolder);
}
}
```
这个代码创建了一个名为"Folder Selection"的窗口,其中包含一个按钮和一个标签。当点击按钮时,会弹出文件夹选择对话框,选择的文件夹路径会显示在标签中。
要使用这个代码,将其放在Unity项目的Editor文件夹中,并在Unity编辑器中选择"Window/Folder Selection"菜单项即可打开窗口。
#### 引用[.reference_title]
- *1* [WinForm学习03 下拉菜单](https://blog.csdn.net/weixin_47326735/article/details/117201389)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* *3* [Unity自定义Attribute实现下拉菜单场景选择](https://blog.csdn.net/m0_49792815/article/details/124356276)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文