Use the file selection screen in Unity

less than 1 minute read

↓ I want to select a file using a dialog box like this: thinking:

image.png

Script

script


using UnityEditor;

 public void OpenFile()
    {
        //Get the path
        var path = EditorUtility.OpenFilePanel("Open csv", "", "CSV");
        if (string.IsNullOrEmpty(path))
            return;
        Debug.Log(path);

        //Read
        var reader = new StreamReader(path);
        Debug.Log(reader);
    }

Details // Show dialog box here

Select one file

script


        var path = EditorUtility.OpenFilePanel("Open csv", "", "CSV");
        var path = EditorUtility.OpenFilePanel(Dialog box name,Directory default settings,File extension to read);

EditorUtility.OpenFilePanel

When specifying multiple types of file extensions

script


var path = EditorUtility.OpenFilePanelWithFilters("Open image", "", {"Music file","mp3,ogg,wav"});

EditorUtility.OpenFilePanelWithFilters

When selecting a folder

script


var path = EditorUtility.OpenFolderPanel("Open Folder", "", "");

EditorUtility.OpenFolderPanel