init commit
This commit is contained in:
32
Assets/Scripts/Project/Screenshooter.cs
Normal file
32
Assets/Scripts/Project/Screenshooter.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
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()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user