Пример #1
0
        private static string GetMenuItemScript(string label, string methodName, EditorFullscreenSettings.FullscreenOption fullscreenOptions)
        {
            string hotkeyString = EditorInput.GetKeyMenuItemString(fullscreenOptions.hotkey, fullscreenOptions.modifiers);
            string script       = "        [MenuItem(" + typeof(EditorFullscreenSettings).Name + ".MENU_ITEM_PATH + \"" + label + " " + hotkeyString + "\")]\r\n"
                                  + "        public static void " + methodName + "() {EditorFullscreenController." + methodName + "();}\r\n";

            return(script);
        }
        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);
        }
Пример #3
0
        public void ClearHotkeyConflicts(int optionID, KeyCode hotkey, EventModifiers modifiers)
        {
            if (hotkey == KeyCode.None)
            {
                return;
            }
            var fullscreenOptions = typeof(EditorFullscreenSettings).GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public).Where(field => (field.FieldType == typeof(FullscreenOption))).ToList();

            foreach (var fsOp in fullscreenOptions)
            {
                var fullscreenOption = (FullscreenOption)fsOp.GetValue(this);
                if (optionID != fullscreenOption.OptionID && EditorInput.HotkeysMatch(hotkey, modifiers, fullscreenOption.hotkey, fullscreenOption.modifiers))
                {
                    //Clear the conflicting hotkey
                    fullscreenOption.hotkey    = KeyCode.None;
                    fullscreenOption.modifiers = EventModifiers.None;
                }
                fsOp.SetValue(this, fullscreenOption);
            }
        }
Пример #4
0
        private static void InitializeInputWin()
        {
            //Close existing input wins except for one
            var allInputWins = (EditorInput[])Resources.FindObjectsOfTypeAll(typeof(EditorInput));

            for (int i = 0; i < allInputWins.Length; i++)
            {
                if (i == allInputWins.Length - 1)
                {
                    //Keep the last one
                    inputWin = allInputWins[i];
                }
                else
                {
                    allInputWins[i].Close();
                }
            }

            if (inputWin == null)
            {
                //If couldn't find an existing one, create a hidden EditorWindow to receive an editor event
                Rect winPos = new Rect(-5000, -5000, 1, 1);
                inputWin = CreateInstance <EditorInput>();
                inputWin.SetWindowTitle("EditorInputWin", true);

                inputWin.minSize  = winPos.size;
                inputWin.maxSize  = winPos.size;
                inputWin.position = winPos;

                inputWin.ShowWithMode(EditorWindowExtensions.ShowMode.NoShadow);
                inputWin.SetSaveToLayout(false);
                EditorMainWindow.Focus();
            }

#if UNITY_STANDALONE_WIN && (UNITY_5_0 || UNITY_5_1)
            inputWin.DisableKeyboardCapture();
            inputWin.InitKeyboardCapture();
#endif
        }
Пример #5
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);
        }
Пример #6
0
 private static bool CheckHotkeyTriggered(KeyCode keyCode, EventModifiers modifiers, EditorFullscreenSettings.FullscreenOption fullscreenOption)
 {
     if (keyCode == KeyCode.None)
     {
         return(false);
     }
     if (EditorInput.HotkeysMatch(keyCode, modifiers, fullscreenOption.hotkey, fullscreenOption.modifiers))
     {
         if (EditorFullscreenSettingsWindow.window != null && EditorFullscreenSettingsWindow.window.IsFocusedOnHotkeyField())
         {
             //Don't trigger the fullscreen hotkey if currently focused on the hotkey field in the settings window.
             EditorFullscreenSettingsWindow.window.HotkeyConflictResendEvent(keyCode, modifiers); //Resend the hotkey event to the settings window so the hotkey can be changed.
             return(false);
         }
         else
         {
             //Trigger the fullscreen hotkey
             triggeredHotkey = fullscreenOption;
             return(true);
         }
     }
     return(false);
 }
Пример #7
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);
        }
Пример #8
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);
        }