Exemplo n.º 1
0
        private void OnRenderObject()
        {
            if (!_takeScreenshotNextFrame)
            {
                return;
            }

            _takeScreenshotNextFrame = false;
            var renderTexture = _screenshotCamera.targetTexture;

            Texture2D renderResult = new Texture2D(renderTexture.width, renderTexture.height, TextureFormat.ARGB32, false);
            Rect      rect         = new Rect(0, 0, renderTexture.width, renderTexture.height);

            renderResult.ReadPixels(rect, 0, 0);

            var finalPath = FileStaticAPI.CreateFileIncrementInPersistant(_relativeSavePath + "/CameraScreenshot", "png");

            Debug.Log("final Path:: " + finalPath);

            byte[] byteArray = renderResult.EncodeToPNG();
            FileStaticAPI.WriteInPersistant(finalPath, byteArray);
            Debug.Log("Screenshot Handler::: Success  - Path -> " + finalPath);

            RenderTexture.ReleaseTemporary(renderTexture);
            _screenshotCamera.targetTexture = null;
        }