VR4Medical/ICI/Library/PackageCache/com.unity.xr.core-utils@5b282bc7378d/Runtime/TextureUtils.cs
2025-07-29 13:45:50 +03:00

24 lines
849 B
C#

using UnityEngine;
namespace Unity.XR.CoreUtils
{
/// <summary>
/// Utilities for manipulating Textures.
/// </summary>
public static class TextureUtils
{
/// <summary>
/// Copy a given <see cref="RenderTexture"/> to a <see cref="Texture2D"/>.
/// This method assumes that both textures exist and are the same size.
/// </summary>
/// <param name="renderTexture">The source <see cref="RenderTexture" />.</param>
/// <param name="texture">The destination <see cref="Texture2D" />.</param>
public static void RenderTextureToTexture2D(RenderTexture renderTexture, Texture2D texture)
{
RenderTexture.active = renderTexture;
texture.ReadPixels(new Rect(0, 0, texture.width, texture.height), 0, 0);
texture.Apply();
}
}
}