美文网首页
Unity截屏

Unity截屏

作者: codingriver | 来源:发表于2017-11-13 19:39 被阅读21次
    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.

相关文章

网友评论

      本文标题:Unity截屏

      本文链接:https://www.haomeiwen.com/subject/zjjzmxtx.html