Version: 2022.3
言語: 日本語
public static string SaveFilePanelInProject (string title, string defaultName, string extension, string message);
public static string SaveFilePanelInProject (string title, string defaultName, string extension, string message, string path);

パラメーター

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.

説明

プロジェクトのアセットフォルダーから始まる"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) { 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(); } } } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961