Version: 5.4
public static string SaveFilePanelInProject (string title, string defaultName, string extension, string message);

説明

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

関連項目: SaveFilePanel 関数


Save File panel in project.

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 ) { // Convert the texture to a format compatible with EncodeToPNG if( texture.format != TextureFormat.ARGB32 && texture.format != TextureFormat.RGB24 ) { Texture2D newTexture = new Texture2D( texture.width, texture.height ); newTexture.SetPixels( texture.GetPixels( 0 ), 0 ); texture = newTexture; }

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( ); } } }

}