private static string GetMenuItemScript(string label, string methodName, EditorFullscreenSettings.FullscreenOption fullscreenOptions, string fullscreenHotkey)
        {
            string hotkeyString = " _" + EditorInput.GetKeyMenuItemString(fullscreenOptions.hotkey, fullscreenOptions.modifiers);

#if UNITY_STANDALONE_WIN && (UNITY_5_0 || UNITY_5_1)
            //Disable menu-item hotkeys for Unity pre-5.4 because of strange bugs which occur when they have no modifier. Instead the hotkeys are handled through EditorInput.
            hotkeyString = "";
            label       += char.ConvertFromUtf32(9) + EditorInput.GetKeysDownString(fullscreenOptions.hotkey, fullscreenOptions.modifiers);
#endif

            string fullscreenOpsString = "EditorFullscreenSettings.settings." + fullscreenHotkey;
            string methodCall          = "EditorFullscreenController.TriggerFullscreenHotkey(" + fullscreenOpsString + ");";

            string script = "        [MenuItem(" + typeof(EditorFullscreenSettings).Name + ".MENU_ITEM_PATH + \"" + label + hotkeyString + "\")]\r\n"
                            + "        public static void " + methodName + "() {" + methodCall + "}\r\n";
            return(script);
        }
예제 #2
0
        private bool AddHotkeyField(string label, ref KeyCode hotkey, ref EventModifiers modifiers)
        {
            bool hotkeyWasSet = false;
            var  guiLabel     = new GUIContent(label);
            var  s            = new GUIStyle(GUIStyle.none);

            s.alignment        = TextAnchor.LowerRight;
            s.fixedHeight      = 15f;
            s.margin.left      = smallHeadingStyle.margin.left;
            s.normal.textColor = EditorStyles.label.normal.textColor;

            EditorGUILayout.BeginHorizontal(new[] { GUILayout.MaxWidth(230f) });
            GUILayout.Label(guiLabel, s, new GUILayoutOption[0]);
            Rect textFieldRect = GUILayoutUtility.GetRect(guiLabel, GUI.skin.textField, new GUILayoutOption[0]);

            //Give the control a unique name using its label and position
            string controlName = label + textFieldRect;

            //Check for Key Press (Must be done before the TextField is set, because it uses the event)
            if (focusedFieldName == controlName && Event.current.type == EventType.KeyDown)
            {
                if (Event.current.keyCode != KeyCode.None && Event.current.keyCode != KeyCode.LeftControl)
                {
                    hotkey       = Event.current.keyCode;
                    modifiers    = Event.current.modifiers;
                    hotkeyWasSet = true;
                }
            }

            //Create the GUI Hotkey Field
            string keysDownString = EditorInput.GetKeysDownString(hotkey, modifiers);

            GUI.SetNextControlName(controlName);
            EditorGUI.SelectableLabel(textFieldRect, "", EditorStyles.textField);
            EditorGUI.LabelField(textFieldRect, keysDownString, EditorStyles.label);
            EditorGUILayout.EndHorizontal();

            return(hotkeyWasSet);
        }
예제 #3
0
        private static string GetMenuItemScript(string label, int tabsInLabel, string methodName, EditorFullscreenSettings.FullscreenOption fullscreenOptions, string fullscreenHotkey, int menuPriority)
        {
            if (fullscreenOptions.hotkey == KeyCode.None)
            {
                return("");                                          //Blank hotkey, so no script required.
            }
            string hotkeyString = " " + EditorInput.GetKeyMenuItemString(fullscreenOptions.hotkey, fullscreenOptions.modifiers);

#if UNITY_EDITOR_OSX
            //Add extra label on macOS for F hotkeys (F hotkeys are labeled incorrectly with modifiers, and some other hotkeys show no label)
            for (int i = 0; i < tabsInLabel; i++)
            {
                label += char.ConvertFromUtf32(9);
            }
            label += EditorInput.GetKeysDownString(fullscreenOptions.hotkey, fullscreenOptions.modifiers);
#endif

            string fullscreenOpsString = "EditorFullscreenSettings.settings." + fullscreenHotkey;
            string methodCall          = "EditorFullscreenController.TriggerFullscreenHotkey(" + fullscreenOpsString + ");";

            string script = "        [MenuItem(" + typeof(EditorFullscreenSettings).Name + ".MENU_ITEM_PATH + \"" + label + hotkeyString + "\", false, " + menuPriority + ")]\r\n"
                            + "        public static void " + methodName + "() {" + methodCall + "}\r\n";
            return(script);
        }
예제 #4
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);
        }