Legacy Documentation: Version 2017.2 (Go to current version)
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

EditorUtility.OpenFilePanel

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

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

Description

Displays the "open file" dialog and returns the selected path name.

See Also: SaveFilePanel function.


Open File Panel.

#pragma strict
public class OpenFilePanelExample extends EditorWindow {
	@MenuItem("Example/Overwrite Texture")
	static function Apply() {
		var texture: Texture2D = Selection.activeObject as Texture2D;
		if (texture == null) {
			EditorUtility.DisplayDialog("Select Texture", "You must select a texture first!", "OK");
			return ;
		}
		var path: String = EditorUtility.OpenFilePanel("Overwrite with png", "", "png");
		if (path.Length != 0) {
			var www: WWW = new WWW("file:///" + path);
			www.LoadImageIntoTexture(texture);
		}
	}
}
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) { WWW www = new WWW("file:///" + path); www.LoadImageIntoTexture(texture); } } }

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