Пример #1
0
        /// <summary>
        /// Get all the displays which are attached to the desktop (As a List)
        /// </summary>
        public static List <EditorDisplay> GetAllDisplays()
        {
            EWFDebugging.StartTimer("GetAllDisplays");
            List <EditorDisplay> allDisplays = new List <EditorDisplay>();

            try
            {
#if UNITY_EDITOR_OSX
                //Get system displays
                allDisplays = FromSystemDisplays(SystemDisplay.GetAllDisplays());
#else
                allDisplays = FromSystemDisplays(SystemDisplay.GetAllDisplays());

                //If couldn't find system displays, use backup method
                if (allDisplays == null || allDisplays.Count < 1)
                {
                    var desktopBounds = PrimaryDesktopResolution;
                    allDisplays = new List <EditorDisplay>();
                    //Find all the displays
                    var display = AddDisplayAtPoint(allDisplays, desktopBounds.center, true);
                    if (display != null)
                    {
                        AddContiguousDisplays(allDisplays, display);
                    }
                }
#endif
            }
            catch (Exception e)
            {
                if (EWFDebugging.Enabled)
                {
                    string err = "Failed to find all possible displays. " + e;
                    Debug.LogError(err);
                    EWFDebugging.LogError(err);
                }
            }

            if (allDisplays.Count == 0)
            {
                /*Failed to find the displays, so add the primary Screen as a display*/
                var display = new EditorDisplay(new Rect(0, 0, Screen.currentResolution.width, Screen.currentResolution.height));
                allDisplays.Add(display);
            }

            //Sort screens by top-left to bottom-right
            allDisplays.Sort(delegate(EditorDisplay a, EditorDisplay b)
            {
                bool aIsLess;
                if (a.Bounds.y != b.Bounds.y)
                {
                    aIsLess = a.Bounds.y < b.Bounds.y;
                }
                else
                {
                    if (a.Bounds.x == b.Bounds.x)
                    {
                        return(0); //Equal
                    }
                    else
                    {
                        aIsLess = a.Bounds.x < b.Bounds.x;
                    }
                }
                return(aIsLess ? -1 : 1);
            });

            EWFDebugging.LogTime("GetAllDisplays", false);
            EditorDisplay.allDisplays = allDisplays;
            return(allDisplays);
        }
Пример #2
0
        /// <summary>
        /// Triggers a Fullscreen Hotkey.
        /// </summary>
        /// <param name="keyCode">The key code of the hotkey to be triggered.</param>
        /// <param name="modifiers">The modifiers of the hotkey to be triggered.</param>
        /// <returns></returns>
        internal static bool TriggerFullscreenHotkey(KeyCode keyCode, EventModifiers modifiers)
        {
            if (EditorInput.performedHotkeyActionThisUpdate)
            {
                return(false);                                             //Already triggered the hotkey
            }
            EWFDebugging.Begin();
            bool setFullscreen             = false;
            bool fullscreenHotkeyTriggered = true;
            var  settings = EditorFullscreenSettings.settings;

            if (settings.debugModeEnabled)
            {
                EWFDebugging.LogLine("Triggered hotkey: " + EditorInput.GetKeysDownString(keyCode, modifiers) + " (key " + keyCode.ToKeyString() + " modifiers " + modifiers.ToString() + ")");
            }
            EditorDisplay.ClearCachedDisplays();

            EWFDebugging.StartTimer("Check hotkey and fullscreen");
            if (CheckHotkeyTriggered(keyCode, modifiers, settings.closeAllFullscreenWindows))
            {
                setFullscreen = CloseAllEditorFullscreenWindows();                                                                               //In this case setFullscreen is set to true if at least one fullscreen was closed.
            }
            else if (CheckHotkeyTriggered(keyCode, modifiers, settings.mainUnityWindow))
            {
                setFullscreen = ToggleMainWindowFullscreen();
            }
            else if (CheckHotkeyTriggered(keyCode, modifiers, settings.sceneWindow))
            {
                setFullscreen = ToggleSceneViewFullscreen();
            }
            else if (CheckHotkeyTriggered(keyCode, modifiers, settings.gameWindow))
            {
                setFullscreen = ToggleGameViewFullscreen(false, settings.gameWindow.OptionID);
            }
            else if (CheckHotkeyTriggered(keyCode, modifiers, settings.currentlyFocusedWindow))
            {
                setFullscreen = ToggleFocusedWindowFullscreen();
            }
            else if (CheckHotkeyTriggered(keyCode, modifiers, settings.windowUnderCursor))
            {
                setFullscreen = ToggleWindowUnderCursorFullscreen();
            }
            else if (CheckHotkeyTriggered(keyCode, modifiers, settings.toggleTopToolbar))
            {
                ToggleTopToolbar();
            }
            else
            {
                fullscreenHotkeyTriggered = false;

                //Check if a custom window hotkey is triggered
                if (settings.customWindows != null)
                {
                    for (int i = 0; i < settings.customWindows.Count; i++)
                    {
                        if (CheckHotkeyTriggered(keyCode, modifiers, settings.customWindows[i]))
                        {
                            if (settings.customWindows[i].isGameView)
                            {
                                setFullscreen = ToggleGameViewFullscreen(false, settings.customWindows[i].OptionID);
                            }
                            else
                            {
                                setFullscreen = EditorFullscreenState.ToggleFullscreenUsingOptions(settings.customWindows[i].WindowType, settings.customWindows[i]);
                            }
                            fullscreenHotkeyTriggered = true;
                            break;
                        }
                    }
                }
            }

            EWFDebugging.LogTime("Check hotkey and fullscreen");

            if (fullscreenHotkeyTriggered)
            {
                triggeredHotkey = null; //Reset the triggered hotkey after fullscreen is toggled.
            }
            if (FullscreenHotkeyEventHandler != null && fullscreenHotkeyTriggered)
            {
                FullscreenHotkeyEventHandler.Invoke(keyCode, modifiers, setFullscreen);
            }
            EWFDebugging.LogLine("fullscreenHotkeyTriggered: " + fullscreenHotkeyTriggered + ", setFullscreen: " + setFullscreen);
            if (fullscreenHotkeyTriggered)
            {
                EWFDebugging.PrintLog();
                EditorInput.performedHotkeyActionThisUpdate = true;
            }
            return(fullscreenHotkeyTriggered);
        }