IEnumerator ScreenshoterRoutine()
        {
            isBusy         = true;
            Time.timeScale = 0;

            foreach (var resolution in targetResolutions)
            {
                gameView.CallMethod("SizeSelectionCallback", indexes[resolution], null);
                gameView.Repaint();
                yield return(new WaitForSecondsRealtime(0.1f));

                cameraInstaller.FindOrUse().Resize();
                yield return(new WaitForEndOfFrame());

                CaptureScreenshot(resolution);
                yield return(null);
            }

            gameView.CallMethod("SizeSelectionCallback", index, null);
            gameView.Repaint();
            yield return(null);

            cameraInstaller.FindOrUse().Resize();

            Time.timeScale = 1;
            isBusy         = false;
        }
        private static void ZoomOutGameView()
        {
            EditorWindow gameView = GetGameView();

            // Find the currently active tab on Game view's panel
            EditorWindow activeTab = gameView.FetchField("m_Parent")?.FetchProperty("actualView") as EditorWindow;

            gameView.Focus();
            gameView.CallMethod("UpdateZoomAreaAndParent");
            gameView.CallMethod("SnapZoom", (float)gameView.FetchProperty("minScale"));

            // Restore the active tab
            if (activeTab && activeTab != gameView)
            {
                activeTab.Focus();
            }
        }
        public static void ClearResolution()
        {
            if (CustomResolution != null)
            {
                EditorWindow gameView = GetGameView();
                bool         customResolutionActive = gameView && CustomResolutionIndex == (int)gameView.FetchProperty("selectedSizeIndex");

                GameViewSizes.CallMethod("RemoveCustomSize", CustomResolutionIndex);
                CustomResolution = null;

                if (customResolutionActive)
                {
                    gameView.CallMethod("SizeSelectionCallback", Mathf.Clamp(PlayerPrefs.GetInt(PREVIOUS_RESOLUTION_PREF), 0, (int)GameViewSizes.CallMethod("GetTotalCount") - 1), null);

                    ZoomOutGameView();
                    RefreshMockups();
                }
            }
        }
        public static void SetResolution(int width, int height, bool aspectRatioMode)
        {
            EditorWindow gameView = GetGameView();

            if (!gameView)
            {
#if UNITY_2019_3_OR_NEWER
                // On 2019.3 and later, we can resize canvases even when there is no open Game window. On earlier versions, unfortunately it is not possible
                if (!NotchSolutionUtilityEditor.UnityDeviceSimulatorActive)
                {
                    SceneView sceneView = SceneView.lastActiveSceneView ?? SceneView.currentDrawingSceneView;
                    if (sceneView)
                    {
                        sceneView.CallMethod("SetMainPlayModeViewSize", new Vector2(width, height));
                        RefreshMockups();
                    }
                }
#endif

                return;
            }

            object customResolution = CustomResolution;
            if (customResolution != null)
            {
                bool isModified = false;

                if ((customResolution.FetchProperty("sizeType").Equals(AspectRatioMode)) != aspectRatioMode)
                {
                    customResolution.ModifyProperty("sizeType", aspectRatioMode ? AspectRatioMode : FixedResolutionMode);
                    isModified = true;
                }

                if ((int)customResolution.FetchProperty("width") != width)
                {
                    customResolution.ModifyProperty("width", width);
                    isModified = true;
                }

                if ((int)customResolution.FetchProperty("height") != height)
                {
                    customResolution.ModifyProperty("height", height);
                    isModified = true;
                }

                if (!isModified)
                {
                    return;
                }
                else if (CustomResolutionIndex == (int)gameView.FetchProperty("selectedSizeIndex"))
                {
                    ZoomOutGameView();
                    RefreshMockups();

                    return;
                }
            }
            else
            {
                CustomResolution = customResolution = GetType("GameViewSize").CreateInstance(aspectRatioMode ? AspectRatioMode : FixedResolutionMode, width, height, TEMPORARY_RESOLUTION_LABEL);
                GameViewSizes.CallMethod("AddCustomSize", customResolution);
            }

            PlayerPrefs.SetInt(PREVIOUS_RESOLUTION_PREF, (int)gameView.FetchProperty("selectedSizeIndex"));
            gameView.CallMethod("SizeSelectionCallback", CustomResolutionIndex, null);

            ZoomOutGameView();
            RefreshMockups();
        }