public static IEnumerator CaptureToFileCoroutine(string fileName, int width, int height, TextureExporter.ImageFileFormat fileFormat = TextureExporter.ImageFileFormat.PNG, int JPGQuality = 100, List <Camera> cameras = null, List <Canvas> canvas = null, ScreenshotTaker.CaptureMode captureMode = ScreenshotTaker.CaptureMode.RENDER_TO_TEXTURE, int antiAliasing = 8, bool captureGameUI = true, ScreenshotTaker.ColorFormat colorFormat = ScreenshotTaker.ColorFormat.RGB, bool recomputeAlphaMask = false) { InitScreenshotTaker(); yield return(CaptureToTextureCoroutine(width, height, cameras, canvas, captureMode, antiAliasing, captureGameUI, colorFormat, recomputeAlphaMask)); // EXPORT if (TextureExporter.ExportToFile(m_ScreenshotTaker.m_Texture, fileName, fileFormat, JPGQuality)) { Debug.Log("Screenshot created : " + fileName); } else { Debug.LogError("Failed to create screenshot : " + fileName); } }
public void ExportToFiles(List <ScreenshotResolution> resolutions) { foreach (ScreenshotResolution resolution in resolutions) { UpdateFileName(resolution); if (TextureExporter.ExportToFile(resolution.m_Texture, resolution.m_FileName, m_FileFormat, (int)m_JPGQuality)) { Debug.Log("Image exported : " + resolution.m_FileName); } } }
protected IEnumerator UpdateCoroutine(List <ScreenshotResolution> resolutions, List <ScreenshotCamera> cameras, List <ScreenshotOverlay> overlays, bool export = true, bool playSoundMask = true) { InitScreenshotTaker(); System.DateTime startTime = System.DateTime.Now; // BATCHES var batches = m_Config.GetActiveBatches(); for (int b = 0; m_Config.m_BatchMode == ScreenshotConfig.BatchMode.BATCHES && b < batches.Count || b == 0; ++b) { // Get batches if any ScreenshotBatch currentBatch = null; if (m_Config.m_BatchMode == ScreenshotConfig.BatchMode.BATCHES && batches.Count > 0) { currentBatch = batches [b]; } // Get the resolutions to be captured, if overriden by batches List <ScreenshotResolution> resToCapture = new List <ScreenshotResolution>(); if (currentBatch != null && currentBatch.m_OverrideActiveResolutions) { resToCapture.AddRange(currentBatch.m_ActiveResolutions.Where(x => x.m_Active == true).Select(x => m_Config.m_Resolutions[x.m_Id]).ToList()); } else { resToCapture.AddRange(resolutions); } // Get the composition to be captured, if overriden by batches List <ScreenshotComposition> compositionsToCapture = new List <ScreenshotComposition>(); if (currentBatch != null && currentBatch.m_OverrideActiveComposer) { compositionsToCapture.AddRange(currentBatch.m_ActiveCompositions.Where(x => x.m_Active == true).Select(x => m_Config.m_Compositions[x.m_Id]).ToList()); } else { compositionsToCapture.AddRange(m_Config.GetActiveCompositions()); } // COMPOSERS // Capture each composition for (int c = 0; m_Config.m_CompositionMode == ScreenshotConfig.CompositionMode.COMPOSITION && c < compositionsToCapture.Count || c == 0; ++c) { // Get composer if any ScreenshotComposition currentComposition = null; m_CurrentComposerInstance = null; if (m_Config.m_CompositionMode == ScreenshotConfig.CompositionMode.COMPOSITION && compositionsToCapture.Count > 0 && compositionsToCapture [c].m_Composer != null) { m_CurrentComposerInstance = GameObject.Instantiate <ScreenshotComposer> (compositionsToCapture [c].m_Composer); currentComposition = compositionsToCapture [c]; } // RESOLUTIONS // Capture each resolution foreach (ScreenshotResolution resolution in resToCapture) { // Debug.Log ("Current resolution " + resolution.ToString ()); // LAYERS for (int l = 0; m_Config.m_ExportToDifferentLayers && l < cameras.Count || l == 0; ++l) { // Get layer if any ScreenshotCamera separatedLayerCamera = null; List <ScreenshotCamera> currentCameras; if (m_Config.m_ExportToDifferentLayers && cameras.Count > 1) { // Capture only the current layer camera separatedLayerCamera = cameras [l]; currentCameras = new List <ScreenshotCamera> { separatedLayerCamera }; } else { // Capture all camera currentCameras = new List <ScreenshotCamera> (cameras); } // PRE PROCESS // Debug.Log ("Pre process"); if (currentBatch != null) { foreach (ScreenshotProcess p in currentBatch.m_PreProcess) { if (p == null) { continue; } p.Process(resolution); yield return(StartCoroutine(p.ProcessCoroutine(resolution))); } } // Sound if (m_Config.m_PlaySoundOnCapture && playSoundMask) { PlaySound(); } // CAPTURE // Debug.Log ("Capture"); if (m_CurrentComposerInstance == null) { yield return(StartCoroutine(m_ScreenshotTaker.CaptureAllCoroutine(new List <ScreenshotResolution> { resolution }, currentCameras, overlays, (m_Config.m_CaptureMode == ScreenshotTaker.CaptureMode.GAMEVIEW_RESIZING && m_Config.m_ResolutionCaptureMode == ScreenshotConfig.ResolutionMode.GAME_VIEW) ? ScreenshotTaker.CaptureMode.FIXED_GAMEVIEW : m_Config.m_CaptureMode, (int)m_Config.m_MultisamplingAntiAliasing, m_Config.m_CaptureActiveUICanvas, m_Config.m_ColorFormat, m_Config.m_RecomputeAlphaLayer, m_Config.m_StopTimeOnCapture))); } else { yield return(StartCoroutine(m_CurrentComposerInstance.CaptureCoroutine(resolution, currentCameras, overlays, (m_Config.m_CaptureMode == ScreenshotTaker.CaptureMode.GAMEVIEW_RESIZING && m_Config.m_ResolutionCaptureMode == ScreenshotConfig.ResolutionMode.GAME_VIEW) ? ScreenshotTaker.CaptureMode.FIXED_GAMEVIEW : m_Config.m_CaptureMode, (int)m_Config.m_MultisamplingAntiAliasing, m_Config.m_CaptureActiveUICanvas, m_Config.m_ColorFormat, m_Config.m_RecomputeAlphaLayer, m_Config.m_StopTimeOnCapture))); } // POST PROCESS // Debug.Log ("Post process"); if (currentBatch != null) { foreach (ScreenshotProcess p in currentBatch.m_PostProcess) { if (p == null) { continue; } p.Process(resolution); yield return(StartCoroutine(p.ProcessCoroutine(resolution))); } } // EXPORT if (export) { string currentBatchName = currentBatch == null ? "" : currentBatch.m_Name; string currentComposerName = currentComposition == null ? "" : currentComposition.m_Name; string currentCameraName = separatedLayerCamera == null ? "" : separatedLayerCamera.m_Camera.name; // Update the filenames with the camera name as layer name UpdateFileName(resolution, startTime, currentCameraName, currentBatchName, currentComposerName); // Export if (TextureExporter.ExportToFile(resolution.m_Texture, resolution.m_FileName, m_Config.m_FileFormat, (int)m_Config.m_JPGQuality)) { Debug.Log("Screenshot created : " + resolution.m_FileName); onResolutionExportSuccessDelegate(resolution); } else { Debug.LogError("Failed to create : " + resolution.m_FileName); onResolutionExportFailureDelegate(resolution); } } } } if (m_CurrentComposerInstance != null) { GameObject.DestroyImmediate(m_CurrentComposerInstance.gameObject); } } } }
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; }
public static IEnumerator CaptureCoroutine(string fileName, int width, int height, TextureExporter.ImageFileFormat fileFormat = TextureExporter.ImageFileFormat.PNG, int JPGQuality = 100, List <Camera> cameras = null, List <Canvas> canvas = null, ScreenshotTaker.CaptureMode captureMode = ScreenshotTaker.CaptureMode.RENDER_TO_TEXTURE, int antiAliasing = 8, bool captureGameUI = true, ScreenshotTaker.ColorFormat colorFormat = ScreenshotTaker.ColorFormat.RGB, bool recomputeAlphaMask = false) { // Create resolution item ScreenshotResolution captureResolution = new ScreenshotResolution(); captureResolution.m_Width = width; captureResolution.m_Height = height; 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(c); screenshotCanvas.Add(scanvas); } } // Capture yield return(m_ScreenshotTaker.StartCoroutine(m_ScreenshotTaker.CaptureAllCoroutine(new List <ScreenshotResolution> { captureResolution }, screenshotCameras, screenshotCanvas, captureMode, antiAliasing, captureGameUI, colorFormat, recomputeAlphaMask))); // EXPORT if (TextureExporter.ExportToFile(captureResolution.m_Texture, fileName, fileFormat, JPGQuality)) { Debug.Log("Screenshot created : " + fileName); } else { Debug.LogError("Failed to create : " + fileName); } }