예제 #1
0
        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();
                }
            }
        }
예제 #2
0
        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();
        }