语言英语
  • C#

EditorUtility.OpenFilePanel

声明

public static string OpenFilePanel(string title, string directory, string extension);

参数

title 对话框工具栏中显示的文本。
directory 此对话框打开的默认文件目录。此参数相对于项目目录。例如,当打开此对话框时,“Assets”显示 Assets 目录。
extension 在此对话框中筛选的文件扩展名。不要在文件扩展名前加上句点。输入空字符串可包括所有文件类型。使用逗号分隔多个文件扩展名。

说明

显示“打开文件”对话框并返回所选路径名。

其他资源:SaveFilePanel 函数。


打开文件面板。

using System.IO;
using UnityEngine;
using UnityEditor;

public class OpenFilePanelExample : EditorWindow { [MenuItem("Example/Overwrite Texture")] static void Apply() { Texture2D texture = Selection.activeObject as Texture2D; if (texture == null) { EditorUtility.DisplayDialog("Select Texture", "You must select a texture first!", "OK"); return; }

string path = EditorUtility.OpenFilePanel("Overwrite with png", "", "png"); if (path.Length != 0) { var fileContent = File.ReadAllBytes(path); texture.LoadImage(fileContent); } } }

Did you find this page useful? Please give it a rating: