private void CaptureUnity(string mFileName)
{
Application.CaptureScreenshot(mFileName, 0);
}
private IEnumerator CaptureByRect(Rect mRect, string mFileName)
{
yield return new WaitForEndOfFrame();
Texture2D mTexture = new Texture2D((int)mRect.width, (int)mRect.height, TextureFormat.RGB24, false);
mTexture.ReadPixels(mRect, 0, 0);
mTexture.Apply();
byte[] bytes = mTexture.EncodeToPNG();
System.IO.File.WriteAllBytes(mFileName, bytes);
}
private IEnumerator CaptureByCamera(Camera mCamera, Rect mRect, string mFileName)
{
yield return new WaitForEndOfFrame();
RenderTexture mRender = new RenderTexture((int)mRect.width, (int)mRect.height, 0);
mCamera.targetTexture = mRender;
mCamera.Render();
RenderTexture.active = mRender;
Texture2D mTexture = new Texture2D((int)mRect.width, (int)mRect.height, TextureFormat.RGB24, false);
mTexture.ReadPixels(mRect, 0, 0);
mTexture.Apply();
mCamera.targetTexture = null;
RenderTexture.active = null;
GameObject.Destroy(mRender);
byte[] bytes = mTexture.EncodeToPNG();
System.IO.File.WriteAllBytes(mFileName, bytes);
}