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

Script language

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

EditorUtility.SaveFilePanelInProject

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 SaveFilePanelInProject(title: string, defaultName: string, extension: string, message: string): string;
public static string SaveFilePanelInProject(string title, string defaultName, string extension, string message);

Description

Displays the "save file" dialog in the Assets folder of the project and returns the selected path name.

See Also: SaveFilePanel function.


Save File panel in project.

#pragma strict

class SaveFilePanelInProjectTest extends EditorWindow {

@MenuItem("Examples/Save File Panel In Project") static function Init() { var window = GetWindowWithRect(SaveFilePanelInProjectTest, Rect(0, 0, 220, 50)); window.Show(); }

function OnGUI() { if(GUI.Button(Rect(10,10, 200, 30), "Choose folder for selected object")) { 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.SaveFilePanelInProject( "Save png", texture.name + "png", "png", "Please enter a file name to save the texture to" );

if (path.Length != 0) { var processedTex : Texture2D = texture; var pngData = processedTex.EncodeToPNG();

if (pngData != null) { System.IO.File.WriteAllBytes(path, pngData);

// Just in case we are saving to the asset folder, tell Unity to scan for modified or new assets AssetDatabase.Refresh(); } } } } }
using UnityEngine;
using UnityEditor;
using System.IO;

public class SaveFilePanelInProjectExample : EditorWindow { [MenuItem("Example/Save Texture In Project")] 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.SaveFilePanelInProject("Save png", texture.name + "png", "png", "Please enter a file name to save the texture to"); if (path.Length != 0) { byte[] pngData = texture.EncodeToPNG(); if (pngData != null) { File.WriteAllBytes(path, pngData);

// As we are saving to the asset folder, tell Unity to scan for modified or new assets AssetDatabase.Refresh(); } } } }

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