/// <summary>
/// 针对相机的截图
/// </summary>
public void CameraScreenShot(){
Rect rect = new Rect(0,0,Screen.width,Screen.height);
RenderTexture renderTexture = RenderTexture.GetTemporary((int)rect.width,(int)rect.height,0, RenderTextureFormat.ARGB32);
#region 默认内置渲染管线或者urp渲染管线(相机都是Base模式),多个相机截图的顺序是depth越小越在前渲染,如下,最终就是两个相机的画面结合
// Camera.main.targetTexture = renderTexture;
// Camera.main.Render();
// camera.targetTexture = renderTexture;
// camera.Render();
#endregion
#region urp渲染管线(base和overlay两种相机) 多个相机截图的顺序是先渲染overlay的相机再是Base的相机。如下,最终就是两个相机的画面结合
// camera.targetTexture = renderTexture;
// camera.Render();
Camera.main.targetTexture = renderTexture;
Camera.main.Render();
#endregion
RenderTexture.active = renderTexture;
Texture2D texture2D = new Texture2D((int)rect.width,(int)rect.height,TextureFormat.ARGB32,false);
texture2D.ReadPixels(rect,0,0);
texture2D.Apply(false);
Camera.main.targetTexture = null;
camera.targetTexture = null;
RenderTexture.active = null;
image.sprite = Sprite.Create(texture2D,rect,new Vector2(0.5f,0.5f));
RenderTexture.ReleaseTemporary(renderTexture);
}文章来源:https://www.toymoban.com/news/detail-812094.html
在这里只是记录一下多相机截图并不包含保存、加入文字水印等方式文章来源地址https://www.toymoban.com/news/detail-812094.html
到了这里,关于unity 相机截图的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!