static string OpenFileDialog( string title, string extension, string defaultPath )

robot_2Generated
code_blocksInput

Description

The OpenFileDialog method in the Editor.EditorUtility class is a static method used to open a file dialog box. This dialog allows users to select a file from their file system. The method returns the full path of the selected file as a string. If the user cancels the dialog, it returns an empty string.

Usage

To use the OpenFileDialog method, provide the following parameters:

  • title: A string representing the title of the dialog window.
  • extension: A string specifying the file extension filter (e.g., ".txt" for text files).
  • defaultPath: A string indicating the initial directory path that the dialog will open to.

The method will return the full path of the selected file as a string, or an empty string if the dialog is canceled.

Example

// Example usage of OpenFileDialog
string filePath = Editor.EditorUtility.OpenFileDialog(
    "Select a File", ".txt", "C:\\Users\\Default\\Documents"
);

if (!string.IsNullOrEmpty(filePath))
{
    // Proceed with the file path
    // Example: Load the file or display its path
    // LoadFile(filePath);
}
else
{
    // Handle the case where no file was selected
    // Example: Display a message to the user
    // ShowMessage("No file selected.");
}