言語: 日本語
  • C#
  • JS
  • Boo

スクリプト言語

お好みのスクリプト言語を選択すると、サンプルコードがその言語で表示されます。

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

Sumbission failed

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

Close

Cancel

public static function SaveFilePanelInProject(title: string, defaultName: string, extension: string, message: string): string;
public static string SaveFilePanelInProject(string title, string defaultName, string extension, string message);
public static def SaveFilePanelInProject(title as string, defaultName as string, extension as string, message as string) as string

Description

プロジェクトのアセットフォルダから始まる"save file"ダイアログを表示し、選択したファイルのパス名を取得します

See Also: SaveFilePanel 関数
プロジェクトのSave File panel.

	// Opens a file selection dialog for a PNG file and saves a selected texture to the file.

	import System.IO;

	@MenuItem("Examples/Save Texture to file")
	static function Apply () {
		var texture : Texture2D = Selection.activeObject as Texture2D;

		if(!texture) {
			EditorUtility.DisplayDialog("Select Texture",
						    "You Must Select a Texture first!",
						    "Ok");
			return;
		}

		var path = EditorUtility.SaveFilePanelInProject("Save texture as PNG",
								texture.name + ".png",
								"png",
								"Please enter a file name to save the texture to");
		if(path.Length != 0) {
			// Convert the texture to a format compatible with EncodeToPNG
			if(texture.format != TextureFormat.ARGB32 && texture.format != TextureFormat.RGB24) {
				var newTexture = Texture2D(texture.width, texture.height);
				newTexture.SetPixels(texture.GetPixels(0),0);
				texture = newTexture;
			}
			var 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();
			}
		}
	}