ScreenCapture.CaptureScreenshotAsTexture

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

参数

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

描述

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

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

在帧处理中,当调用生成的截屏时将影响此截屏。要捕获所有渲染堆栈,需要在帧结束后调用它。使用在 WaitForEndOfFrame 上执行 yield 的协程是一种执行此操作的简单方式。 如果在调用此方法时帧尚未结束,则生成的纹理中可能不包含某些渲染瑕疵(例如 UI)。

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()); } }