EditorUtility.SaveFilePanelInProject 在项目中保存文件夹面板

static function SaveFilePanelInProject (title : string, defaultName : string, extension : string, message : string) : string

Description描述

Displays the "save file" dialog in the Assets folder of the project and returns the selected path name.

在项目的资源文件夹,显示“save file”对话框并返回选择的路径名。

参见:SaveFilePanel function.

EditorUtility.SaveFilePanelInProject 在项目中保存文件夹面板

Save File panel in project.
在项目文件中保存文件夹面板

// Opens a file selection dialog for a PNG file and saves a selected texture to the file.

//打开一个文件选择对话框用于PNG文件并保持一个选择的纹理到文件

import System.IO;



@MenuItem("Examples/Save Texture to file")

static function Apply () {

	var texture : Texture2D = Selection.activeObject as Texture2D;



	if(!texture) {

		EditorUtility.DisplayDialog("Select Texture",

		"You Must Select a Texture first!",

		"Ok");

		return;

	}



	var path = EditorUtility.SaveFilePanelInProject("Save texture as PNG",

		texture.name + ".png",

		"png",

		"Please enter a file name to save the texture to");

	if(path.Length != 0) {

		// Convert the texture to a format compatible with EncodeToPNG

		//转换纹理到EncodeToPNG兼容格式

		if(texture.format != TextureFormat.ARGB32 && texture.format != TextureFormat.RGB24) {

			var newTexture = Texture2D(texture.width, texture.height);

			newTexture.SetPixels(texture.GetPixels(0),0);

			texture = newTexture;

		}

		var 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

			//保存到资源文件夹,告诉Unity来扫描修改的或新的资源

			AssetDatabase.Refresh();

		}

	}

}
Page last updated: 2011-7-15