Version: 2023.2
언어: 한국어
public static string SaveFilePanel (string title, string directory, string defaultName, string extension);

파라미터

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.

설명

Displays the "save file" dialog and returns the selected path name.

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.

See Also: OpenFilePanel function.


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); } } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961