Version: 2020.2
public static RenderTexture active ;

描述

当前处于活动状态的渲染纹理。

所有渲染都将进入处于活动状态的 RenderTexture。 如果处于活动状态的 RenderTexture 为 /null/,则在主窗口中渲染所有内容。

设置 RenderTexture.active 与调用 Graphics.SetRenderTarget 相同。在实现 自定义图形效果时,您通常需要更改或查询处于活动状态的 渲染纹理;如果您只需要将摄像机渲染到纹理, 可以改用 Camera.targetTexture

当 RenderTexture 处于活动状态时, 将自动创建其硬件渲染上下文(如果尚未创建)。

另请参阅:Graphics.SetRenderTarget

using UnityEngine;
using System.Collections;

// Get the contents of a RenderTexture into a Texture2D public class ExampleClass : MonoBehaviour { static public Texture2D GetRTPixels(RenderTexture rt) { // Remember currently active render texture RenderTexture currentActiveRT = RenderTexture.active;

// Set the supplied RenderTexture as the active one RenderTexture.active = rt;

// Create a new Texture2D and read the RenderTexture image into it Texture2D tex = new Texture2D(rt.width, rt.height); tex.ReadPixels(new Rect(0, 0, tex.width, tex.height), 0, 0);

// Restorie previously active render texture RenderTexture.active = currentActiveRT; return tex; } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961