实现
截屏
Texture2D texture = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
texture.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
texture.Apply();
存储
byte[] array = ImageConversion.EncodeToPNG(texture);
if (!Directory.Exists(filePath))
{
Directory.CreateDirectory(filePath);
}
File.WriteAllBytes(filePath + "/" + fileName, array);
问题
ReadPixels was called to read pixels from system frame buffer, while not inside drawing frame.
直接使用截屏会出错,可使用协程或在OnPostRender 中处理来解决,具体参见链接文章。