public static IEnumerator CaptureToTextureCoroutine(int width, int height, 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(); // Create resolution item ScreenshotResolution captureResolution = new ScreenshotResolution(); captureResolution.m_Width = width; captureResolution.m_Height = height; // 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))); }
public virtual IEnumerator CaptureInnerTextureCoroutine(RawImage texture, ScreenshotResolution desiredCaptureResolution, List <ScreenshotCamera> cameras, List <ScreenshotOverlay> overlays, ScreenshotTaker.CaptureMode captureMode, int antiAliasing = 8, bool captureGameUI = true, ScreenshotTaker.ColorFormat colorFormat = ScreenshotTaker.ColorFormat.RGB, bool recomputeAlphaMask = false, bool stopTime = false, bool restore = true) { // Compute the texture resolution ScreenshotResolution tempRes = new ScreenshotResolution(); yield return(m_ScreenshotTaker.StartCoroutine(ComputeInnerTextureSizeCoroutine(texture, desiredCaptureResolution.ComputeTargetWidth(), desiredCaptureResolution.ComputeTargetHeight(), tempRes))); // Capture the game view at the raw image resolution yield return(m_ScreenshotTaker.StartCoroutine(m_ScreenshotTaker.CaptureAllCoroutine(new List <ScreenshotResolution> { tempRes }, cameras, overlays, captureMode, antiAliasing, captureGameUI, colorFormat, recomputeAlphaMask, stopTime))); // Set raw image texture using the previously captured texture texture.texture = tempRes.m_Texture; }
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 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); } }