title | The title of the window to display. |
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. |
message | The text summary to display in the dialog window. |
path | The working directory for this dialog to open in. The default value is "Assets.". |
string A string path to the saved file. If the dialog was canceled or the save failed, it returns an empty string.
在项目的 Assets 文件夹中显示“保存文件”对话框并返回所选的路径名称。
另请参阅:SaveFilePanel 函数。
项目中的保存文件面板。
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(); } } } }