IEnumerator CRCaptureScreenshot() { // Wait for right timing to take screenshot yield return(new WaitForEndOfFrame()); // Temporarily render the camera content to our screenshotRenderTexture. // Later we'll share the screenshot from this rendertexture. RenderTexture tempRT = RenderTexture.GetTemporary(Screen.width, Screen.height, 24); Camera.main.targetTexture = tempRT; Camera.main.Render(); yield return(null); Camera.main.targetTexture = null; yield return(null); // Read the rendertexture contents RenderTexture.active = tempRT; if (CapturedScreenshot == null) { CapturedScreenshot = new Texture2D(tempRT.width, tempRT.height, TextureFormat.RGB24, false); } CapturedScreenshot.ReadPixels(new Rect(0, 0, tempRT.width, tempRT.height), 0, 0); CapturedScreenshot.Apply(); RenderTexture.active = null; RenderTexture.ReleaseTemporary(tempRT); }
void CaptureandStopRecordImmediately() { #if EASY_MOBILE if (recorder != null) { RecordedClip = recorder.Stop(); } #endif RenderTexture tempRT = RenderTexture.GetTemporary(Screen.width, Screen.height, 24); Camera.main.targetTexture = tempRT; Camera.main.Render(); Camera.main.targetTexture = null; RenderTexture.active = tempRT; if (CapturedScreenshot == null) { CapturedScreenshot = new Texture2D(tempRT.width, tempRT.height, TextureFormat.RGB24, false); } CapturedScreenshot.ReadPixels(new Rect(0, 0, tempRT.width, tempRT.height), 0, 0); CapturedScreenshot.Apply(); RenderTexture.active = null; RenderTexture.ReleaseTemporary(tempRT); }
IEnumerator CRCaptureScreenshot() { // Wait for right timing to take screenshot yield return(new WaitForEndOfFrame()); #if UNITY_ANDROID // Temporarily render the camera content to our screenshotRenderTexture. // Later we'll share the screenshot from this rendertexture. if (tempRT == null) { tempRT = RenderTexture.GetTemporary(Screen.width, Screen.height, 24, RenderTextureFormat.ARGB32); } else { tempRT.DiscardContents(); } RenderTexture lastRT = Camera.main.targetTexture; Camera.main.targetTexture = tempRT; Camera.main.Render(); Camera.main.targetTexture = lastRT; #else if (CapturedScreenshot == null) { CapturedScreenshot = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false); } CapturedScreenshot.ReadPixels(new Rect(0, 0, CapturedScreenshot.width, CapturedScreenshot.height), 0, 0); CapturedScreenshot.Apply(); #endif }
IEnumerator CRCaptureScreenshot() { // Wait for right timing to take screenshot yield return(new WaitForEndOfFrame()); if (CapturedScreenshot == null) { CapturedScreenshot = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false); } CapturedScreenshot.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0); CapturedScreenshot.Apply(); }
void RenderTextureToScreenshot(RenderTexture rt) { // Read the rendertexture contents RenderTexture.active = rt; if (CapturedScreenshot == null) { CapturedScreenshot = new Texture2D(rt.width, rt.height, TextureFormat.RGB24, false); } CapturedScreenshot.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0); CapturedScreenshot.Apply(); RenderTexture.active = null; }