版本:Unity 6(6000.0)
语言English
  • C#

EditorUtility.SaveFolderPanel

提出修改建议

成功!

感谢您帮助我们改进 Unity 文档的质量。尽管我们无法接受所有的提交,但是我们会阅读用户建议的每一项修改,并在适用时进行更新。

关闭

提交失败

由于某种原因,无法提交您的修改建议。请在几分钟后<a>重试</a>。感谢您花时间帮助我们改进 Unity 文档的质量。

关闭

取消

声明

public static string SaveFolderPanel(string title, string folder, string defaultName);

描述

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

其他资源:SaveFilePanelOpenFilePanel 函数。


保存文件夹面板。

using UnityEngine;
using UnityEditor;
using System.IO;

public class SaveFolderPanelExample : EditorWindow { [MenuItem("Example/Save Textures To Folder")] static void Apply() { Object[] textures = Selection.GetFiltered(typeof(Texture2D), SelectionMode.Unfiltered); if (textures.Length == 0) { EditorUtility.DisplayDialog("Select Textures", "You must select at least one texture first!", "OK"); return; }

string path = EditorUtility.SaveFolderPanel("Save textures to folder", "", ""); if (path.Length != 0) { foreach (Texture2D texture in textures) { Texture2D processedTex = texture;

byte[] pngData = processedTex.EncodeToPNG(); if (pngData != null) File.WriteAllBytes(path + "/" + texture.name + ".png", pngData); else Debug.Log("Could not convert " + texture.name + " to png. Skipping saving texture."); }

// Just in case we are saving to the asset folder, tell Unity to scan for modified or new assets AssetDatabase.Refresh(); } } }