EditorUtility
- ClearProgressBar
- CloneComponent
- CollectDeepHierarchy
- CollectDependencies
- CompressTexture
- CopySerialized
- CreateEmptyPrefab
- CreateGameObjectWithHideFlags
- DisplayCancelableProgressBar
- DisplayDialogComplex
- DisplayDialog
- DisplayPopupMenu
- DisplayProgressBar
- ExtractOggFile
- FindPrefabRoot
- FocusProjectWindow
- FormatBytes
- GetObjectEnabled
- GetPrefabParent
- GetPrefabType
- InstanceIDToObject
- InstantiatePrefab
- IsPersistent
- OpenFilePanel
- OpenFolderPanel
- ReconnectToLastPrefab
- ReplacePrefab
- ResetGameObjectToPrefabState
- ResetToPrefabState
- SaveFilePanelInProject
- SaveFilePanel
- SaveFolderPanel
- SetDirty
- SetObjectEnabled
- SetSelectedWireframeHidden
- UnloadUnusedAssetsIgnoreM...
- UnloadUnusedAssets
EditorUtility.SaveFilePanel 保存文件面板
static function SaveFilePanel (title : string, directory : string, defaultName : string, extension : string) : string
Description描述
Displays the "save file" dialog and returns the selected path name.
显示“save file”对话框,并返回选择的路径名。
参见: OpenFilePanel function.
Save File Panel.
保存文件面板
// Opens a file selection dialog for a PNG file and saves a selected texture to the file.
//打开一个PNG文件选择对话框并保持一个选择的纹理到文件
import System.IO;
class EditorUtilitySaveFilePanel {
@MenuItem("Examples/Save Texture to file")
static function Apply () {
var texture : Texture2D = 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) {
// 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);
}
}
}
最后修改:2011年7月15日 Friday 18:20