Esempio n. 1
0
        /// <summary> Toggle fullscreen for a window state, on the screen at position </summary>
        private static bool ToggleFullscreen(WindowFullscreenState windowState, bool createNewWindow, Vector2 atPosition)
        {
            if (windowState == null)
            {
                throw new NullReferenceException("windowState is null. Cannot continue.");
            }

            if (!loadedInitialState)
            {
                windowState.CloseOnExitFullscreen = createNewWindow;
                windowState.FullscreenAtPosition  = atPosition;
                queuedStatesToToggleOnLoad.Add(windowState);

                if (LogNonFatalErrors)
                {
                    throw new TypeLoadException("The fullscreen state hasn't been loaded yet. Fullscreen toggle has been queued.");
                }
                else
                {
                    return(false);
                }
            }
            if (windowState.WindowType == mainWindowType)
            {
                return(EditorMainWindow.ToggleFullscreen(windowState.ShowTopToolbar, atPosition));
            }

            if (windowState.EditorWin == null || (!windowState.IsFullscreen && createNewWindow))
            {
                if (windowState.ActualType == typeof(SceneView))
                {
                    windowState.ActualType = typeof(CustomSceneView);
                }                                                                                                      //Always create CustomSceneView for SceneView
                var win = EditorWindowExtensions.CreateWindow(windowState.ActualType);
                windowState.SetEditorWin(win);

                if (windowState.ActualType == typeof(CustomSceneView) || win.GetWindowType() == gameViewType)
                {
                    win.SetWindowTitle(windowState.WindowName, true); //Reset title content on custom Scene and Game views to prevent icon not found error.
                }
                windowState.CloseOnExitFullscreen = true;             //Since we are creating a new window, this window should close when fullscreen is exited

                bool setFullscreen = win.ToggleFullscreen(atPosition);
                return(setFullscreen);
            }
            else
            {
                return(windowState.EditorWin.ToggleFullscreen(atPosition));
            }
        }
Esempio n. 2
0
        private static float GetPixelsPerPointAtPosition(Vector2 atPosition)
        {
            var screenBounds = EditorDisplay.ClosestToPoint(atPosition).Bounds;

            //Use a dummy scene view to get the real pixels per point (Because EditorGUIUtility.pixelsPerPoint is inconsistent).
            var dummySceneView = EditorWindowExtensions.CreateWindow(typeof(SceneView));

            dummySceneView.SetFullscreen(true, atPosition, false);
            var pixelsPerPoint = screenBounds.width / dummySceneView.position.width;

            dummySceneView.SetFullscreen(false);
            if (dummySceneView != null)
            {
                dummySceneView.Close();
            }
            if (dummySceneView != null)
            {
                UnityEngine.Object.DestroyImmediate(dummySceneView);
            }
            return(pixelsPerPoint);
        }