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.

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容