public static void StartScreenshot(ScreenAndLanguages settings, string screenshotName, float timeForLanguageSwitch, float timeForGamePrepare, Format format) { if (settings.Dimensions.Length == 0 || settings.Dimensions[0].Dimensions.Length == 0) { return; } _settings = settings; _timeForGamePrepare = timeForGamePrepare; _timeForLanguageSwitch = timeForLanguageSwitch; WaitForNextStep = false; ScreenshotTime = true; screenshotInfo = new ScreenshotInfo { Format = format, Name = screenshotName }; GameViewUtils.SetSize(0); _lastTime = EditorApplication.timeSinceStartup; _coroutine = CaptureScreenshot(); EditorApplication.update += ExecuteCoroutine; }
private static void CreateDimensions() { foreach (var pDimension in _settings.Dimensions) { foreach (var dimension in pDimension.Dimensions) { if (!GameViewUtils.SizeExists(GameViewSizeGroupType.Standalone, (int)dimension.x, (int)dimension.y)) { GameViewUtils.AddCustomSize(GameViewUtils.GameViewSizeType.FixedResolution, GameViewSizeGroupType.Standalone, (int)dimension.x, (int)dimension.y, "ScreenShot:" + (int)dimension.x + "x" + (int)dimension.y); } } } }
private static void ResetAll() { ChangeSize(1024, 768); GameViewUtils.UpdateZoomAreaAndParent(); ScreenshotTime = false; WaitForNextStep = false; if (string.IsNullOrEmpty(_testPath) && File.Exists(_testPath)) { File.Delete(_testPath); } EditorApplication.update -= ExecuteCoroutine; _coroutine = null; }
private static void ChangeSize(int width, int height) { var gameView = GameViewUtils.GetMainGameView(); var rect = gameView.position; rect.width = width + _offset.x; rect.height = height + _offset.y; rect.x = 0; rect.y = 0; gameView.position = rect; #if UNITY_EDITOR_WIN gameView.minSize = new Vector2(width + _offset.x, height + _offset.y); gameView.maxSize = new Vector2(width + _offset.x, height + _offset.y); #endif gameView.Repaint(); }
private static void ChangeSize(int width, int height) { GameViewUtils.SetSize(GameViewUtils.FindSize(GameViewSizeGroupType.Standalone, width, height)); }
private static IEnumerator CaptureScreenshot() { double delta = 0; #if FREE_RESIZE #region Detect offset ChangeSize((int)_settings.Dimensions[0].Dimensions[0].x, (int)_settings.Dimensions[0].Dimensions[0].y); var compareSize = _settings.Dimensions[0].Dimensions[0]; _testPath = Directory.GetParent(Application.dataPath) + "/test" + UnityEngine.Random.Range(1000, 9999) + ".png"; ScreenCapture.CaptureScreenshot(_testPath); while (!File.Exists(_testPath)) { yield return(null); } var tmpTexture = new Texture2D(1, 1); var tmpBytes = File.ReadAllBytes(_testPath); tmpTexture.LoadImage(tmpBytes); _offset = new Vector2(compareSize.x - tmpTexture.width, compareSize.y - tmpTexture.height); File.Delete(_testPath); #endregion GameViewUtils.SetSize(GameViewUtils.FindSize(GameViewSizeGroupType.Standalone, "Free Aspect")); #else CreateDimensions(); #endif foreach (var language in _settings.Languages) { #region Change language ChangeLanguage(language); screenshotInfo.Language = language; delta = EditorApplication.timeSinceStartup - _lastTime; while (delta < _timeForLanguageSwitch) { yield return(null); delta = EditorApplication.timeSinceStartup - _lastTime; } _lastTime = EditorApplication.timeSinceStartup; #endregion foreach (var pDimension in _settings.Dimensions) { screenshotInfo.Platform = pDimension.PlatformName; foreach (var dimension in pDimension.Dimensions) { screenshotInfo.Resolution = (int)dimension.x + "x" + (int)dimension.y; var path = UniqueFilename(screenshotInfo); ChangeSize((int)dimension.x, (int)dimension.y); yield return(new WaitForEndOfFrame()); Canvas.ForceUpdateCanvases(); EditorApplication.Step(); GameViewUtils.UpdateZoomAreaAndParent(); delta = EditorApplication.timeSinceStartup - _lastTime; File.Delete(path); while (File.Exists(path) || delta < _timeForGamePrepare) { yield return(null); delta = EditorApplication.timeSinceStartup - _lastTime; } _lastTime = EditorApplication.timeSinceStartup; #region Game Change after resize BeforeScreenshot((int)dimension.x, (int)dimension.y); delta = EditorApplication.timeSinceStartup - _lastTime; while (delta < _timeForGamePrepare) { yield return(null); delta = EditorApplication.timeSinceStartup - _lastTime; } _lastTime = EditorApplication.timeSinceStartup; #endregion Canvas.ForceUpdateCanvases(); EditorApplication.Step(); yield return(new WaitForEndOfFrame()); ScreenCapture.CaptureScreenshot(path); yield return(new WaitForEndOfFrame()); while (!File.Exists(path)) { yield return(null); } AfterScreenshot((int)dimension.x, (int)dimension.y); #region Wait action if need if (NeedWaitForNextStep) { WaitForNextStep = true; } while (WaitForNextStep) { yield return(null); } #endregion } } } ResetAll(); }