System.Collections.IEnumerator CaptureCoroutine() { for (var eof = new WaitForEndOfFrame(); true;) { // Wait for the end of the frame. yield return(eof); PrepareSenderObjects(); // Texture capture method if (captureMethod == CaptureMethod.Texture && sourceTexture != null) { var(w, h) = (sourceTexture.width, sourceTexture.height); // Pixel format conversion var buffer = _converter.Encode(sourceTexture, keepAlpha, true); // Readback entry allocation and request _pool.NewEntry(w, h, keepAlpha, metadata) .RequestReadback(buffer, _onReadback); } // Game View capture method if (captureMethod == CaptureMethod.GameView) { // Game View screen capture with a temporary RT var(w, h) = (Screen.width, Screen.height); var tempRT = RenderTexture.GetTemporary(w, h, 0); ScreenCapture.CaptureScreenshotIntoRenderTexture(tempRT); // Pixel format conversion var buffer = _converter.Encode(tempRT, keepAlpha, false); RenderTexture.ReleaseTemporary(tempRT); // Readback entry allocation and request _pool.NewEntry(w, h, keepAlpha, metadata) .RequestReadback(buffer, _onReadback); } } }
ComputeBuffer CaptureImmediate() { PrepareInternalObjects(); // Texture capture method // Simply convert the source texture and return it. if (_captureMethod == CaptureMethod.Texture) { if (_sourceTexture == null) { return(null); } _width = _sourceTexture.width; _height = _sourceTexture.height; return(_converter.Encode(_sourceTexture, _enableAlpha)); } // Game View capture method // Capture the screen into a temporary RT, then convert it. if (_captureMethod == CaptureMethod.GameView) { _width = Screen.width; _height = Screen.height; var tempRT = RenderTexture.GetTemporary(_width, _height, 0); ScreenCapture.CaptureScreenshotIntoRenderTexture(tempRT); var converted = _converter.Encode(tempRT, _enableAlpha); RenderTexture.ReleaseTemporary(tempRT); return(converted); } Debug.LogError("Wrong capture method."); return(null); }