2016-06-16 18 views
2

我正在嘗試將我的Unity項目的幀保存爲自動生成預覽Gif。 我調用該方法在我的腳本是這樣的:在UntyWebGl中保存幀

Application.CaptureScreenshot("Screenshot" + Time.frameCount + ".png"); 

如果我這樣做在Unity它工作得很好。但是當我將自己的項目構建爲WebGL時,它不再這樣做了。爲什麼?還是有人知道一種不同的方式來保存幀?

回答

0

還有其他方法可以截屏。沒有在WebGL上測試過,但你應該嘗試一下。

void CaptureScreenshot() 
{ 
    StartCoroutine(CaptureScreenshotCRT()); 
} 

IEnumerator CaptureScreenshotCRT() 
{ 
    yield return new WaitForEndOfFrame(); 
    string path = Application.persistentDataPath + "/Screenshot" + Time.frameCount + ".png"; 
    Texture2D screenImage = new Texture2D(Screen.width, Screen.height); 
    //Get Image from screen 
    screenImage.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0); 
    screenImage.Apply(); 
    //Convert to png 
    byte[] imageBytes = screenImage.EncodeToPNG(); 

    //Save image to file 
    System.IO.File.WriteAllBytes(path, imageBytes); 
} 
+0

此解決方案不會在我的應用程序中保存任何屏幕截圖。 – MaryLu

+0

它現在可以在Unity中使用,但仍然不能作爲webGL導出:/ – MaryLu

+0

@MaryLu首先,你說甚至沒有提供更多信息,甚至不保存任何屏幕截圖,現在你說它在Unity中工作,但不在WebGL中。我忽略這些評論。 – Programmer