예제 #1
0
    private static void CaptureScreenshotWithUI(ScreenshotData data)
    {
        RenderTexture temp = RenderTexture.active;

        RenderTexture renderTex  = (RenderTexture)GameView.FetchField("m_TargetTexture");
        Texture2D     screenshot = null;

        int width  = renderTex.width;
        int height = renderTex.height;

        try {
            RenderTexture.active = renderTex;

            screenshot = new Texture2D(width, height, TextureFormat.RGB24, false);
            screenshot.ReadPixels(new Rect(0, 0, width, height), 0, 0, false);

            if (SystemInfo.graphicsUVStartsAtTop)
            {
                Color32[] pixels = screenshot.GetPixels32();
                for (int i = 0; i < height / 2; i++)
                {
                    int startIndex0 = i * width;
                    int startIndex1 = (height - i - 1) * width;
                    for (int x = 0; x < width; x++)
                    {
                        Color32 color = pixels[startIndex0 + x];
                        pixels[startIndex0 + x] = pixels[startIndex1 + x];
                        pixels[startIndex1 + x] = color;
                    }
                }

                screenshot.SetPixels32(pixels);
            }

            screenshot.Apply(false, false);

#if POLYGLOT
            File.WriteAllBytes(ScreenshotTaker.GetUniqueFilePath(width, height, data.targetCamera == ScreenshooterTargetCamera.SceneView, true, data.lang.ToString(), usedOutputFolder, "jpeg"), screenshot.EncodeToJPG(100));
#else
            File.WriteAllBytes(ScreenshotTaker.GetUniqueFilePath(width, height, data.targetCamera == ScreenshooterTargetCamera.SceneView, true, "", usedOutputFolder, "jpeg"), screenshot.EncodeToJPG(100));
#endif
        }
        finally {
            RenderTexture.active = temp;

            if (screenshot != null)
            {
                GameObject.DestroyImmediate(screenshot);
            }
        }
    }
예제 #2
0
    private static void CaptureScreenshotWithoutUI(ScreenshotData data)
    {
        Camera camera = data.targetCamera == ScreenshooterTargetCamera.GameView ? Camera.main : SceneView.lastActiveSceneView.camera;

        RenderTexture temp  = RenderTexture.active;
        RenderTexture temp2 = camera.targetTexture;

        int           width      = Mathf.RoundToInt(data.resolution.x * data.resolutionMultiplier);
        int           height     = Mathf.RoundToInt(data.resolution.y * data.resolutionMultiplier);
        RenderTexture renderTex  = RenderTexture.GetTemporary(width, height, 24);
        Texture2D     screenshot = null;

        try {
            RenderTexture.active = renderTex;

            camera.targetTexture = renderTex;
            camera.Render();

            screenshot = new Texture2D(renderTex.width, renderTex.height, TextureFormat.RGBA32, false);
            screenshot.ReadPixels(new Rect(0, 0, renderTex.width, renderTex.height), 0, 0, false);
            screenshot.Apply(false, false);

#if POLYGLOT
            File.WriteAllBytes(ScreenshotTaker.GetUniqueFilePath(renderTex.width, renderTex.height, data.targetCamera == ScreenshooterTargetCamera.SceneView, false, data.lang.ToString(), usedOutputFolder, "jpeg"), screenshot.EncodeToJPG(100));
#else
            File.WriteAllBytes(ScreenshotTaker.GetUniqueFilePath(renderTex.width, renderTex.height, data.targetCamera == ScreenshooterTargetCamera.SceneView, false, "", usedOutputFolder, "jpeg"), screenshot.EncodeToJPG(100));
#endif
        }
        finally {
            camera.targetTexture = temp2;

            RenderTexture.active = temp;
            RenderTexture.ReleaseTemporary(renderTex);

            if (screenshot != null)
            {
                GameObject.DestroyImmediate(screenshot);
            }
        }
    }
예제 #3
0
        public static string GetMp4FileName(string rootFolder)
        {
            Vector2Int screenSize = new Vector2Int(Screen.currentResolution.width, Screen.currentResolution.height);

            return(ScreenshotTaker.GetUniqueFilePath(screenSize.x, screenSize.y, false, true, Localization.Instance.SelectedLanguage.ToString(), rootFolder, "mp4"));
        }