public static IEnumerator CaptureScreenshot(Action<string> callback)
{
yield return new WaitForEndOfFrame();//在当前帧绘制完后才截屏
Rect rect = new Rect(0, 0, Screen.width, Screen.height);
RenderTexture rt = new RenderTexture((int)rect.width, (int)rect.height, 24);
Texture2D screenShot = new Texture2D((int)rect.width, (int)rect.height, TextureFormat.RGB24, false);
foreach (var camera in Camera.allCameras)
{
if(camera.isActiveAndEnabled)
{
camera.targetTexture = rt;
camera.Render();
camera.targetTexture = null;
}
}
RenderTexture prevActiveTex = RenderTexture.active;
RenderTexture.active = rt;
screenShot.ReadPixels(rect, 0, 0);
screenShot.Apply();
RenderTexture.active = prevActiveTex
Unity 截图分享实现
最新推荐文章于 2025-09-10 12:09:22 发布

5947

被折叠的 条评论
为什么被折叠?



