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;
    }
    /// 
    /// 截图
    /// 
    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截屏)