Camera.Render
Declaration
public void Render();Описание
Рендирование камеры вручную.
Это будет рендировать камеру. Она будет использовать clear flags камеры, текстуру цели и все другие настройки.
Камера отправит MonoBehaviour.OnPreCull, MonoBehaviour.OnPreRender и MonoBehaviour.OnPostRender в любые приложенные скрипты, и рендирует любые возможные фильтры изображения.
Это используется для точного контроля порядка рендеринга. Чтобы использовать эту функцию, создайте камеру и отключите ее. Затем вызовите Render на ней.
Вы не можете вызвать функцию Render с камеры, которая в настоящее время рендируется. Если вы хотите сделать это, создайте копию камеры, и сделайте ее соответствующей оригинальной с помощью CopyFrom.
Дополнительные ресурсы: RenderWithShader.
using UnityEngine;
public class Example : MonoBehaviour { // Take a "screenshot" of a camera's Render Texture. Texture2D RTImage(Camera camera) { // The Render Texture in RenderTexture.active is the one // that will be read by ReadPixels. var currentRT = RenderTexture.active; RenderTexture.active = camera.targetTexture;
// Render the camera's view. camera.Render();
// Make a new texture and read the active Render Texture into it. Texture2D image = new Texture2D(camera.targetTexture.width, camera.targetTexture.height); image.ReadPixels(new Rect(0, 0, camera.targetTexture.width, camera.targetTexture.height), 0, 0); image.Apply();
// Replace the original active Render Texture. RenderTexture.active = currentRT; return image; } }