33 lines
832 B
C#
33 lines
832 B
C#
using UnityEngine;
|
|
|
|
public class Screenshooter : MonoBehaviour
|
|
{
|
|
public Camera cam;
|
|
public int width = 3840;
|
|
public int height = 2160;
|
|
|
|
void Update()
|
|
{
|
|
if (Input.GetKeyDown(KeyCode.F12))
|
|
{
|
|
RenderTexture rt = new RenderTexture(width, height, 24);
|
|
cam.targetTexture = rt;
|
|
|
|
Texture2D image = new Texture2D(width, height, TextureFormat.RGB24, false);
|
|
cam.Render();
|
|
RenderTexture.active = rt;
|
|
image.ReadPixels(new Rect(0, 0, width, height), 0, 0);
|
|
image.Apply();
|
|
|
|
cam.targetTexture = null;
|
|
RenderTexture.active = null;
|
|
Destroy(rt);
|
|
|
|
System.IO.File.WriteAllBytes(
|
|
"screenshot_4k.png",
|
|
image.EncodeToPNG()
|
|
);
|
|
}
|
|
}
|
|
}
|