- 最后登录
- 2013-9-29
- 注册时间
- 2012-8-20
- 阅读权限
- 90
- 积分
- 6371
- 纳金币
- 6372
- 精华
- 0
|
其实关键代码就是这三句,先取到目标的贴图,然后转成字节,最后字节输出成图片:
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;
}
}
}
|
|