Unity截屏

    IEnumerator CoroutineScreenShot(System.Action action)
    {

        //ReadPixels was called to read pixels from system frame buffer, while not inside drawing frame.
        yield return new WaitForEndOfFrame();
        byte[] data = CaptureScreenshot();
        CacheUtil.WriteSync(ScreenshotPath,data);
        if(action!=null)
            action();
        yield break;
    }
    /// <summary>
    /// 截图
    /// </summary>
    public void SahreCaptureScreenshot()
    {
        Dg.Log("SaveCaptureScreenshot:", ScreenshotPath);

        StartCoroutine(CoroutineScreenShot(() => {
        
        }));
    }

屏幕截图时需要在协程中执行,且必须有yield return new WaitForEndOfFrame();,否则报错:ReadPixels was called to read pixels from system frame buffer, while not inside drawing frame.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容