纳金网
标题:
unity3d 屏幕截图 核心代码
[打印本页]
作者:
yeu1233
时间:
2012-9-4 09:44
标题:
unity3d 屏幕截图 核心代码
其实关键代码就是这三句,先取到目标的贴图,然后转成字节,最后字节输出成图片:
Texture2D tex = (Texture2D)target.renderer.material.mainTexture;
byte[] byt = tex.EncodeToPNG ();
System.IO.File.WriteAllBytes ("Assets/" + textureName + ".png", byt);
private void SaveMenuWindow (int windowID)
{
if (!saved) {
GUILayout.Label ("Name:");
textureName = GUILayout.TextField (textureName);
if (GUILayout.Button ("Save")) {
Texture2D tex = (Texture2D)target.renderer.material.mainTexture;
byte[] byt = tex.EncodeToPNG ();
System.IO.File.WriteAllBytes ("Assets/" + textureName + ".png", byt);
saved = ***e;
}
} else {
GUILayout.Label (Application.dataPath + "/" + textureName + ".png");
if (GUILayout.Button ("Close")) {
objectMenuIndex = 0;
showSaveMenu = false;
saved = false;
}
}
}
欢迎光临 纳金网 (http://course.narkii.com/club/)
Powered by Discuz! X2.5