public static string SaveFilePanel (string title, string directory, string defaultName, string extension);

描述

显示“保存文件”对话框并返回所选的路径名称。

注意:该对话框有一个“Save”按钮和“Cancel”按钮。“Cancel”按钮可关闭窗口,但不保存纹理。

另请参阅:OpenFilePanel 函数。


保存文件面板。

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