/// <summary> /// Captures the specified resolutions with custom parameters. /// </summary> public void Capture(List <ScreenshotResolution> resolutions, List <ScreenshotCamera> cameras, List <ScreenshotOverlay> overlays, CaptureMode captureMode, int antiAliasing = 8, bool export = true, TextureExporter.ImageFormat imageFormat = TextureExporter.ImageFormat.PNG, int JPGQuality = 100, bool renderUI = true, bool playSound = false, ColorFormat colorFormat = ColorFormat.RGB, bool recomputeAlphaMask = false) { StartCoroutine(CaptureScreenshotsCoroutine(resolutions, cameras, overlays, captureMode, antiAliasing, export, imageFormat, JPGQuality, renderUI, playSound, colorFormat, recomputeAlphaMask)); }
/// <summary> /// Captures the game with the specified width, height, resolution upscale, and export it to the file fileName. /// </summary> public void Capture(int width, int height, int upscale, string fileName, List <Camera> cameras = null, List <Canvas> canvas = null, CaptureMode captureMode = CaptureMode.RENDER_TO_TEXTURE, int antiAliasing = 8, TextureExporter.ImageFormat imageFormat = TextureExporter.ImageFormat.PNG, int JPGQuality = 100, bool renderUI = true, bool playSound = false, ColorFormat colorFormat = ColorFormat.RGB, bool recomputeAlphaMask = false) { // Update resolution item m_CaptureResolution.m_Width = width; m_CaptureResolution.m_Height = height; m_CaptureResolution.m_Scale = upscale; m_CaptureResolution.m_FileName = fileName; // Create camera items List <ScreenshotCamera> screenshotCameras = new List <ScreenshotCamera>(); if (cameras != null) { foreach (Camera camera in cameras) { ScreenshotCamera scamera = new ScreenshotCamera(camera); screenshotCameras.Add(scamera); } } // Create the overlays items List <ScreenshotOverlay> screenshotCanvas = new List <ScreenshotOverlay>(); if (canvas != null) { foreach (Canvas c in canvas) { ScreenshotOverlay scanvas = new ScreenshotOverlay(true, c); screenshotCanvas.Add(scanvas); } } Capture(new List <ScreenshotResolution> { m_CaptureResolution }, screenshotCameras, screenshotCanvas, captureMode, antiAliasing, true, imageFormat, JPGQuality, renderUI, playSound, colorFormat, recomputeAlphaMask); }
/// <summary> /// Captures the scene with the specified width, height, resolution upscale, and export it to the file fileName, /// using the mode RENDER_TO_TEXTURE. /// No UI is captured with this mode. /// </summary> public void CaptureScene(int width, int height, int upscale, string fileName, List <Camera> cameras, int antiAliasing = 8, TextureExporter.ImageFormat imageFormat = TextureExporter.ImageFormat.PNG, int JPGQuality = 100, bool playSound = false, ColorFormat colorFormat = ColorFormat.RGB, bool recomputeAlphaMask = false) { Capture(width, height, upscale, fileName, cameras, null, CaptureMode.RENDER_TO_TEXTURE, antiAliasing, imageFormat, JPGQuality, false, playSound, colorFormat, recomputeAlphaMask); }
/// <summary> /// Captures the current screen at its current resolution, including UI. /// </summary> public void CaptureScreen(string fileName, TextureExporter.ImageFormat imageFormat = TextureExporter.ImageFormat.PNG, int JPGQuality = 100, bool renderUI = true, bool playSound = false, ColorFormat colorFormat = ColorFormat.RGB, bool recomputeAlphaMask = false) { Vector2 size = GameViewController.GetCurrentGameViewSize(); Capture((int)size.x, (int)size.y, 1, fileName, null, null, CaptureMode.FIXED_GAMEVIEW, 8, imageFormat, JPGQuality, renderUI, playSound, colorFormat, recomputeAlphaMask); }
public IEnumerator CaptureScreenshotsCoroutine(List <ScreenshotResolution> resolutions, List <ScreenshotCamera> cameras, List <ScreenshotOverlay> overlays, CaptureMode captureMode, int antiAliasing = 8, bool export = false, TextureExporter.ImageFormat imageFormat = TextureExporter.ImageFormat.PNG, int JPGQuality = 100, bool renderUI = true, bool playSound = false, ColorFormat colorFormat = ColorFormat.RGB, bool recomputeAlphaMask = false, bool stopTime = true, bool restore = true) { if (resolutions == null) { Debug.LogError("Resolution list is null."); yield break; } if (cameras == null) { Debug.LogError("Cameras list is null."); yield break; } if (overlays == null) { Debug.LogError("Overlays list is null."); yield break; } if (m_IsRunning == true) { Debug.LogError("A capture process is already running."); yield break; } if (captureMode == CaptureMode.RENDER_TO_TEXTURE && !UnityVersion.HasPro()) { Debug.LogError("RENDER_TO_TEXTURE requires Unity Pro or Unity 5.0 and later."); yield break; } #if (!UNITY_EDITOR && !UNITY_STANDALONE_WIN) if (captureMode == CaptureMode.GAMEVIEW_RESIZING) { Debug.LogError("GAMEVIEW_RESIZING capture mode is only available for Editor and Windows Standalone."); yield break; } #endif // Init m_IsRunning = true; // Stop the time so all screenshots are exactly the same if (Application.isPlaying && stopTime) { StopTime(); } // Apply settings: enable and disable the cameras and canvas ApplySettings(cameras, overlays, captureMode, renderUI); // Save the screen config to be restored after the capture process if (captureMode == CaptureMode.GAMEVIEW_RESIZING) { GameViewController.SaveCurrentGameViewSize(); #if !UNITY_EDITOR && UNITY_STANDALONE_WIN yield return(null); yield return(new WaitForEndOfFrame()); #endif } // Capture all resolutions foreach (ScreenshotResolution resolution in resolutions) { // Play the shot sound if (playSound) { PlaySound(); } // Update the texture yield return(StartCoroutine(CaptureResolutionTextureCoroutine(resolution, captureMode, antiAliasing, colorFormat, recomputeAlphaMask))); // Export to file if (export) { if (TextureExporter.ExportToFile(resolution.m_Texture, resolution.m_FileName, imageFormat, JPGQuality)) { Debug.Log("Screenshot created : " + resolution.m_FileName); onResolutionExportSuccessDelegate(resolution); } else { Debug.LogError("Failed to create : " + resolution.m_FileName); onResolutionExportFailureDelegate(resolution); } } } // Restore screen config if (restore && captureMode == CaptureMode.GAMEVIEW_RESIZING) { GameViewController.RestoreGameViewSize(); } #if (UNITY_EDITOR && !UNITY_5_4_OR_NEWER) // Call restore layout for old unity versions if (restore && captureMode == CaptureMode.GAMEVIEW_RESIZING) { m_NeedRestoreLayout = true; } #endif #if UNITY_EDITOR // Dirty hack, try to force an editor Update() to get the gameview back to normal if (captureMode == CaptureMode.FIXED_GAMEVIEW || captureMode == CaptureMode.GAMEVIEW_RESIZING) { if (!Application.isPlaying) { GameViewUtils.GetGameView().Repaint(); } } #endif // Restore everything if (Application.isPlaying && stopTime) { RestoreTime(); } if (Application.isEditor || restore) { RestoreSettings(); } // End m_IsRunning = false; }