title | The title of the window to display. |
directory | The working directory that this dialog opens on. |
defaultName | The placeholder text to display in the "Save As" text field. This is the name of file to be saved. |
extension | The file extension to use in the saved file path. For example, enter "png" to save an image in the PNG format. |
string A string path to the saved file if the dialog was canceled or the save failed, it returns an empty string.
"save file"ダイアログを表示し、選択されたパスを取得します
This function displays a dialog that prompts the user for a path to save an asset to. It does not create the file or parent directories. You are responsible for creating and writing to the file at the returned path location.
Note: The dialog has a Save button and a Cancel button. If you click the Cancel button, the window closes without saving.
関連項目: OpenFilePanel 関数
Save File Panel.
// Opens a file selection dialog for a PNG file and saves a selected texture to the file.
using UnityEditor; using UnityEngine; using System.IO;
public class EditorUtilitySaveFilePanel : MonoBehaviour { [MenuItem("Examples/Save Texture to file")] static void Apply() { Texture2D texture = Selection.activeObject as Texture2D; if (texture == null) { EditorUtility.DisplayDialog( "Select Texture", "You Must Select a Texture first!", "Ok"); return; }
var path = EditorUtility.SaveFilePanel( "Save texture as PNG", "", texture.name + ".png", "png");
if (path.Length != 0) { var pngData = texture.EncodeToPNG(); if (pngData != null) File.WriteAllBytes(path, pngData); } } }