Unity 6.3
0 онлайн 53 гостей 3 в системе
Вход

RenderTexture.active

Declaration

public static RenderTexture active;

Описание

Текущая активная текстура отображения.

Все рендеринг идет в активный RenderTexture. Если активный RenderTexture является null все отображается в главном окне.

Настройка RenderTexture.active это то же самое, что и вызов Graphics.SetRenderTarget. Как правило, вы изменяете или запрашиваете активную текстуру рендеринга при реализации пользовательских графических эффектов; если все, что вам нужно, это сделать Camera рендеринг в текстуру, а затем использование Camera.targetTexture вместо этого.

Когда RenderTexture становится активным, его аппаратный контекст отображения автоматически создается, если он еще не был создан.

Дополнительные ресурсы: Graphics.SetRenderTarget, GraphicsTexture.active.

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); tex.Apply();

// Restore previously active render texture RenderTexture.active = currentActiveRT; return tex; } }