public static void LoadPresets() { List <ScreenshotResolutionAsset> presets = AssetUtils.LoadAll <ScreenshotResolutionAsset> (); foreach (ScreenshotResolutionAsset preset in presets) { if (preset.m_Resolution == null) { continue; } var res = new ScreenshotResolution(preset.m_Resolution); res.m_ResolutionName = preset.name.Replace(".asset", ""); var cat = AssetDatabase.GetAssetPath(preset); if (cat.Contains("Resources/")) { cat = cat.Substring(cat.LastIndexOf("Resources"), cat.LastIndexOf("/") - cat.LastIndexOf("Resources")); } if (cat.Contains("Presets/")) { cat = cat.Substring(cat.LastIndexOf("Presets"), cat.LastIndexOf("/") - cat.LastIndexOf("Presets")); } cat = cat.Replace("Presets/", ""); cat = cat.Replace("Resources/", ""); res.m_Category = cat; m_ResolutionPresets.Add(res); } }
public void Copy(ScreenshotResolution res) { m_Active = res.m_Active; m_Width = res.m_Width; m_Height = res.m_Height; m_Scale = res.m_Scale; m_Orientation = res.m_Orientation; m_ResolutionName = res.m_ResolutionName; m_Category = res.m_Category; m_Platform = res.m_Platform; m_PPI = res.m_PPI; m_ForcedUnityPPI = res.m_ForcedUnityPPI; m_Ratio = res.m_Ratio; m_DeviceCanvas = res.m_DeviceCanvas; m_FileName = res.m_FileName; m_SafeAreaPortrait = res.m_SafeAreaPortrait; m_SafeAreaLandscapeLeft = res.m_SafeAreaLandscapeLeft; // m_SafeAreaLandscapeRight = res.m_SafeAreaLandscapeRight; // m_ReferenceAsset = res.m_ReferenceAsset; }
public string UpdateFileName(ScreenshotResolution resolution) { string filename = ""; #if UNITY_EDITOR || !UNITY_WEBGL // Destination Folder filename += GetPath(); #endif // File name filename += ParseNameSymbols(m_Config.m_FileName, resolution); // Get the file extension string extension = GetExtension(); // Increment the file number if a file already exist if (!m_Config.m_OverrideFiles && File.Exists(filename + extension)) { int i = 1; while (File.Exists(filename + " (" + i.ToString() + ")" + extension)) { i++; } return(filename + " (" + i.ToString() + ")" + extension); } else { return(filename + extension); } }
protected void InitPreviewResolution() { m_PreviewResolution = new ScreenshotResolution(); m_PreviewResolution.m_Width = 200; m_PreviewResolution.m_Height = 100; m_PreviewResolution.m_Scale = 1; }
void OnResolutionSelectCallback(object target) { ScreenshotResolution selection = (ScreenshotResolution)target; m_Config.m_Resolutions.Add(new ScreenshotResolution(selection)); m_Config.UpdateRatios(); EditorUtility.SetDirty(m_Obj); }
protected void InitGameViewResolution() { m_GameViewResolution = new ScreenshotResolution(); m_GameViewResolution.m_Active = true; m_GameViewResolution.m_ResolutionName = "GameView"; m_GameViewResolution.m_Width = Screen.width; m_GameViewResolution.m_Height = Screen.height; m_GameViewResolution.m_Scale = 1; }
public IEnumerator CaptureCompositionCoroutine(ScreenshotResolution desiredCaptureResolution) { yield return(m_ScreenshotTaker.StartCoroutine(m_ScreenshotTaker.CaptureResolutionCoroutine(desiredCaptureResolution, new List <Camera> { m_Camera }, new List <Canvas> { m_Canvas }, ScreenshotTaker.CaptureMode.GAMEVIEW_RESIZING, 8, false, ScreenshotTaker.ColorFormat.RGB, false))); }
public static Texture2D GetOrCreateTexture(ScreenshotResolution resolution, ColorFormat colorFormat, bool noScale = false) { // Compute real dimensions int width = noScale ? resolution.m_Width : resolution.ComputeTargetWidth(); int height = noScale ? resolution.m_Height : resolution.ComputeTargetHeight(); // Init the texture GetOrCreateTexture(ref resolution.m_Texture, width, height, colorFormat); return(resolution.m_Texture); }
void StartCallback(ScreenshotResolution res) { if (m_SelectionArea == null) { return; } if (m_HideSelectionAreaDuringCapture) { Hide(); } }
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))); }
void EndCallback(ScreenshotResolution res) { if (m_SelectionArea == null) { return; } if (m_HideSelectionAreaDuringCapture) { Show(); } CropTexture(res); }
public ScreenshotResolution(ScreenshotResolution res) { m_Active = res.m_Active; m_Width = res.m_Width; m_Height = res.m_Height; m_Scale = res.m_Scale; m_PPI = res.m_PPI; m_ForcedUnityPPI = res.m_ForcedUnityPPI; m_ResolutionName = res.m_ResolutionName; m_Ratio = res.m_Ratio; m_Stats = res.m_Stats; m_Category = res.m_Category; }
public void UpdateFileName(ScreenshotResolution resolution, System.DateTime time, string currentCamera = "", string currentBatch = "", string currentComposer = "") { // Update the filenames m_Config.UpdateFileName(resolution, time); // Parse symbols etc. resolution.m_FileName = resolution.m_FileName.Replace("{layer}", currentCamera); resolution.m_FileName = resolution.m_FileName.Replace("{batch}", currentBatch); resolution.m_FileName = resolution.m_FileName.Replace("{composer}", currentComposer); if (!m_Config.m_OverrideFiles) { resolution.m_FileName = ScreenshotNameParser.PreventOverride(resolution.m_FileName); } }
protected string ParseNameSymbols(string name, ScreenshotResolution resolution) { // Add a 0 before numbers if < 10 if (System.DateTime.Now.Month < 10) { name = name.Replace("{month}", "0{month}"); } if (System.DateTime.Now.Day < 10) { name = name.Replace("{day}", "0{day}"); } if (System.DateTime.Now.Hour < 10) { name = name.Replace("{hour}", "0{hour}"); } if (System.DateTime.Now.Minute < 10) { name = name.Replace("{minute}", "0{minute}"); } if (System.DateTime.Now.Second < 10) { name = name.Replace("{second}", "0{second}"); } // Date name = name.Replace("{year}", System.DateTime.Now.Year.ToString()); name = name.Replace("{month}", System.DateTime.Now.Month.ToString()); name = name.Replace("{day}", System.DateTime.Now.Day.ToString()); name = name.Replace("{hour}", System.DateTime.Now.Hour.ToString()); name = name.Replace("{minute}", System.DateTime.Now.Minute.ToString()); name = name.Replace("{second}", System.DateTime.Now.Second.ToString()); // Dimensions name = name.Replace("{width}", resolution.m_Width.ToString()); name = name.Replace("{height}", resolution.m_Height.ToString()); name = name.Replace("{scale}", resolution.m_Scale.ToString()); name = name.Replace("{ratio}", resolution.m_Ratio).Replace(":", "_"); // Resolution name = name.Replace("{orientation}", resolution.m_Orientation.ToString()); name = name.Replace("{name}", resolution.m_ResolutionName); name = name.Replace("{ppi}", resolution.m_PPI.ToString()); name = name.Replace("{category}", resolution.m_Category); name = name.Replace("{percent}", resolution.m_Stats.ToString()); return(name); }
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; }
void CropTexture(ScreenshotResolution res) { // Get the selection image coordinates Vector3[] corners = new Vector3[4]; m_SelectionArea.GetWorldCorners(corners); // Create cropped texture int x0 = (int)corners [0].x + m_CropBorder; int y0 = (int)corners [0].y + m_CropBorder; int width = (int)(corners [2].x - corners [0].x) - 2 * m_CropBorder; int height = (int)(corners [1].y - corners [0].y) - 2 * m_CropBorder; Texture2D cropped = new Texture2D(width, height, res.m_Texture.format, false); if (width <= 2 || height <= 2) { return; } // Copy the content Color col; for (int x = 0; x < width; ++x) { for (int y = 0; y < height; ++y) { if (x0 + x >= 0 && x0 + x < res.m_Texture.width && y0 + y >= 0 && y0 + y < res.m_Texture.height) { col = res.m_Texture.GetPixel(x0 + x, y0 + y); } else { col = Color.black; } cropped.SetPixel(x, y, col); } } cropped.Apply(); Debug.Log("Screenshot cropped to (" + x0 + ", " + y0 + ", " + (x0 + width - 1) + ", " + (y0 + height - 1) + ")"); // Replace the texture res.m_Texture = cropped; }
RenderTexture GetOrCreateRenderTexture(ScreenshotResolution resolution, int antiAliasing = 0, int depth = 32) { // Compute real resolutions int width = resolution.ComputeTargetWidth(); int height = resolution.ComputeTargetHeight(); // Get from cache RenderTexture rt = null; if (m_RenderTextureCache.ContainsKey(resolution)) { rt = m_RenderTextureCache[resolution]; } // Create render texture if needed GetOrCreateRenderTexture(ref rt, width, height, antiAliasing, depth); // Save to cache m_RenderTextureCache[resolution] = rt; return(rt); }
public IEnumerator CaptureResolutionCoroutine(ScreenshotResolution captureResolution, 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 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); } } yield return(StartCoroutine(CaptureAllCoroutine(new List <ScreenshotResolution> { captureResolution }, screenshotCameras, screenshotCanvas, captureMode, antiAliasing, captureGameUI, colorFormat, recomputeAlphaMask))); }
public ScreenshotResolution(ScreenshotResolution res) { m_Active = res.m_Active; m_Width = res.m_Width; m_Height = res.m_Height; m_Scale = res.m_Scale; m_Orientation = res.m_Orientation; m_ResolutionName = res.m_ResolutionName; m_Category = res.m_Category; m_PPI = res.m_PPI; m_ForcedUnityPPI = res.m_ForcedUnityPPI; m_Ratio = res.m_Ratio; // m_Stats = res.m_Stats; m_DeviceCanvas = res.m_DeviceCanvas; m_FileName = res.m_FileName; }
public virtual IEnumerator CaptureCoroutine(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) { m_ScreenshotTaker = GameObject.FindObjectOfType <ScreenshotTaker> (); // Capture all inner textures foreach (RawImage texture in m_Textures) { yield return(m_ScreenshotTaker.StartCoroutine(CaptureInnerTextureCoroutine(texture, desiredCaptureResolution, cameras, overlays, captureMode, antiAliasing, captureGameUI, colorFormat, recomputeAlphaMask, stopTime))); } // Capture the composition at the desired resolution size yield return(m_ScreenshotTaker.StartCoroutine(CaptureCompositionCoroutine(desiredCaptureResolution))); }
public static void LoadCollections() { List <PresetCollectionAsset> collections = AssetUtils.LoadAll <PresetCollectionAsset> (); foreach (PresetCollectionAsset collection in collections) { foreach (var preset in collection.m_Presets) { if (preset == null) { continue; } if (preset.m_Resolution == null) { continue; } var res = new ScreenshotResolution(preset.m_Resolution); res.m_ResolutionName = preset.name.Replace(".asset", ""); res.m_Category = "Collections/" + collection.name; m_ResolutionPresets.Add(res); } } }
public static void LoadPopularityPresets() { List <PopularityPresetAsset> popularities = AssetUtils.LoadAll <PopularityPresetAsset> (); foreach (PopularityPresetAsset popularity in popularities) { foreach (var stat in popularity.m_Stats) { if (stat == null) { continue; } if (stat.m_Resolution == null) { continue; } var res = new ScreenshotResolution(stat.m_Resolution.m_Resolution); res.m_ResolutionName = stat.m_Frequency + "% " + stat.m_Resolution.name; res.m_Category = "Popularity/" + popularity.name; m_ResolutionPresets.Add(res); } } }
/// <summary> /// Captures the game with the specified width, height. /// The texture will be resized if needed to match the capture settings. /// </summary> public IEnumerator CaptureToTextureCoroutine(Texture2D texture, 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) { // Check texture if (texture == null) { Debug.LogError("The texture can not be null. You must provide a texture initialized with any width and height."); yield break; } // Update resolution item ScreenshotResolution captureResolution = new ScreenshotResolution(width, height); captureResolution.m_Texture = texture; yield return(StartCoroutine(CaptureResolutionCoroutine(captureResolution, cameras, canvas, captureMode, antiAliasing, captureGameUI, colorFormat, recomputeAlphaMask))); }
/// <summary> /// Returns the parsed screenshot filename using the symbols, extensions and special folders. /// </summary> public static string ParseFileName(string screenshotName, ScreenshotResolution resolution, DestinationFolder destination, string customPath, TextureExporter.ImageFileFormat format, bool overwriteFiles, System.DateTime time) { string filename = ""; #if UNITY_EDITOR || !UNITY_WEBGL // Destination Folder can not be parsed in webgl filename += ParsePath(destination, customPath); #endif // File name filename += ParseSymbols(screenshotName, resolution, time); // Get the file extension filename += ParseExtension(format); // Increment the file number if a file already exist if (!overwriteFiles) { return(PathUtils.PreventOverwrite(filename)); } return(filename); }
/// <summary> /// Captures the resolution texture. /// </summary> IEnumerator CaptureResolutionTextureCoroutine(ScreenshotResolution resolution, CaptureMode captureMode, int antiAliasing, ColorFormat colorFormat) { // Init texture m_Texture = GetOrCreateTexture(resolution, colorFormat, captureMode == CaptureMode.FIXED_GAMEVIEW ? true : false); if (captureMode == CaptureMode.GAMEVIEW_RESIZING) { // Debug.Log ("Resize "); // Force screen size change GameViewController.SetGameViewSize(m_Texture.width, m_Texture.height); yield return(new WaitForEndOfFrame()); // Force wait if (!Application.isPlaying) { // Useless texture update in editor mode when game is not running, // that takes some computational times to be sure that the UI is updated at least one time before the capture if (MultiDisplayUtils.IsMultiDisplay()) { yield return(MultiDisplayCopyRenderBufferToTextureCoroutine(m_Texture)); } else { CopyScreenToTexture(m_Texture); } } // Delegate call to notify screen is resized onResolutionScreenResizedDelegate(resolution); // Wait several frames // Particularly needed for special effects using several frame to compute their effects, like temporal anti aliasing if (m_GameViewResizingWaitingMode == GameViewResizingWaitingMode.FRAMES || !Application.isPlaying) { for (int i = 0; i < m_GameViewResizingWaitingFrames; ++i) { // Debug.Log ("Wait " + i); //GameViewController.SetGameViewSize(m_Texture.width, m_Texture.height); #if UNITY_EDITOR if (!Application.isPlaying) { GameViewUtils.GetGameView().Repaint(); } #endif yield return(new WaitForEndOfFrame()); #if UNITY_EDITOR if (!Application.isPlaying && i < 2) { CopyScreenToTexture(m_Texture); // Useless update to force waiting for the gamview to be correctly updated } #endif // Debug.Log ("Wait " + i + " end"); } } else { #if (UNITY_5_4_OR_NEWER) yield return(new WaitForSecondsRealtime(m_GameViewResizingWaitingTime)); #else if (Time.timeScale > 0f) { yield return(new WaitForSeconds(m_GameViewResizingWaitingTime)); } #endif yield return(new WaitForEndOfFrame()); } // Debug.Log ("Capture"); // Capture the screen content if (MultiDisplayUtils.IsMultiDisplay()) { yield return(MultiDisplayCopyRenderBufferToTextureCoroutine(m_Texture)); } else { CopyScreenToTexture(m_Texture); } // Debug.Log ("End Capture"); } else if (captureMode == CaptureMode.RENDER_TO_TEXTURE) { // Wait for the end of rendering yield return(new WaitForEndOfFrame()); /* #if UNITY_EDITOR * if (Application.isPlaying) { * yield return new WaitForEndOfFrame (); * } else { * // We need to force a gameview repaint * Vector2 current = GameViewController.GetCurrentGameViewSize (); * GameViewController.SetGameViewSize ((int)current.x, (int)current.y); * yield return new WaitForEndOfFrame (); * } #endif */ // Do not need to wait anything, just capture the cameras RenderTexture renderTexture = GetOrCreateRenderTexture(resolution, antiAliasing); RenderCamerasToTexture(m_Cameras, m_Texture, renderTexture); } else if (captureMode == CaptureMode.FIXED_GAMEVIEW) { #if UNITY_EDITOR // Force repaint in case the gameview is not focus to prevent a lock if (!Application.isPlaying) { GameViewUtils.GetGameView().Repaint(); } #endif // Wait for the end of rendering yield return(new WaitForEndOfFrame()); // Capture the screen content if (MultiDisplayUtils.IsMultiDisplay()) { yield return(MultiDisplayCopyRenderBufferToTextureCoroutine(m_Texture)); } else { CopyScreenToTexture(m_Texture); } } // Alpha mask // if (colorFormat == ColorFormat.RGBA && recomputeAlphaMask) // { // // Capture the screen content // yield return StartCoroutine(RecomputeAlphaMask(resolution, m_Cameras, captureMode)); // } }
/// <summary> /// Override that coroutine if you want to create a process requiring several frames. /// Note that in editor mode, if the game is not playing, you may have to force a gameview repaint with ForceGameViewRepaint() or the coroutine will be stuck. /// Time related coroutines will not work if the game is not playing. It is advised to have a fallback with ForceGameViewRepaint() or the coroutine will be stuck. /// </summary> public virtual IEnumerator ProcessCoroutine(ScreenshotResolution res) { ForceGameViewRepaint(); yield return(new WaitForEndOfFrame()); }
IEnumerator CaptureAlphaMaskCoroutine(ScreenshotResolution resolution, CaptureMode captureMode, int antiAliasing, ColorFormat colorFormat) { // Backup first camera clear mode var firstCamera = GetFirstActiveCamera(); var clearMode = firstCamera.clearFlags; var clearColor = firstCamera.backgroundColor; // Set clear white alpha firstCamera.clearFlags = CameraClearFlags.Color; firstCamera.backgroundColor = new Color(1f, 1f, 1f, 0.1f); // Capture the texture yield return(StartCoroutine(CaptureResolutionTextureCoroutine(resolution, captureMode, antiAliasing, colorFormat))); // Copy white texture Texture2D whiteTexture = new Texture2D(resolution.m_Texture.width, resolution.m_Texture.height, resolution.m_Texture.format, false, false); CopyTexture(resolution.m_Texture, whiteTexture); // Set clear black alpha firstCamera.clearFlags = CameraClearFlags.Color; firstCamera.backgroundColor = new Color(0f, 0f, 0f, 0.1f); // Capture the texture, again yield return(StartCoroutine(CaptureResolutionTextureCoroutine(resolution, captureMode, antiAliasing, colorFormat))); // Copy black texture Texture2D blackTexture = new Texture2D(resolution.m_Texture.width, resolution.m_Texture.height, resolution.m_Texture.format, false, false); CopyTexture(resolution.m_Texture, blackTexture); // Compute diff Color color; for (int x = 0; x < resolution.m_Texture.width; ++x) { for (int y = 0; y < resolution.m_Texture.height; ++y) { var alpha = whiteTexture.GetPixel(x, y).r - blackTexture.GetPixel(x, y).r; alpha = 1f - alpha; if (alpha == 0) { color = Color.clear; } else { // color = whiteTexture.GetPixel(x, y) / alpha; color = whiteTexture.GetPixel(x, y); } color.a = alpha; resolution.m_Texture.SetPixel(x, y, color); } } resolution.m_Texture.Apply(); // Clean DestroyImmediate(whiteTexture); DestroyImmediate(blackTexture); // Restore clear settings firstCamera.clearFlags = clearMode; firstCamera.backgroundColor = clearColor; }
public string ParseFileName(ScreenshotResolution resolution, System.DateTime time) { string path = m_DestinationFolder == ScreenshotNameParser.DestinationFolder.CUSTOM_FOLDER ? m_RootedPath : m_RelativePath; return(ScreenshotNameParser.ParseFileName(m_FileName, resolution, m_DestinationFolder, path, m_FileFormat, m_OverwriteFiles, time)); }
public void UpdateFileName(ScreenshotResolution resolution, System.DateTime time) { resolution.m_FileName = ParseFileName(resolution, time); }
// public ScreenshotResolution (ScreenshotResolutionAsset preset) // { // m_Preset = preset; // Copy (m_Preset.m_Resolution); // } public ScreenshotResolution(ScreenshotResolution res) { Copy(res); }