ScreenCapture.CaptureScreenshotAsTexture

切换到手册
public static Texture2D CaptureScreenshotAsTexture (int superSize);
public static Texture2D CaptureScreenshotAsTexture (ScreenCapture.StereoScreenCaptureMode stereoCaptureMode);

参数

superSize分辨率的增加倍数。
stereoCaptureMode指定启用立体渲染时要捕获的眼睛纹理。

描述

将此游戏对象的截屏捕获到 Texture2D 对象中。

superSize 参数大于 1 时,将生成更大分辨率的 截屏。例如,传递 4 将使截屏比通常情况大 4x4。 这适用于生成用于打印的截屏。

要从此方法获得可靠的输出,必须确保在帧渲染结束后调用此方法,而不是在渲染过程中调用。确保这一点的一种简单方式是从一个在 WaitForEndOfFrame 上产生的协程调用此方法。如果在渲染过程中调用此方法,则会得到不可预测且未定义的结果。

using UnityEngine;
using System.Collections;

public class ScreenShotter : MonoBehaviour { IEnumerator RecordFrame() { yield return new WaitForEndOfFrame(); var texture = ScreenCapture.CaptureScreenshotAsTexture(); // do something with texture

// cleanup Object.Destroy(texture); }

public void LateUpdate() { StartCoroutine(RecordFrame()); } }