Ejemplo n.º 1
0
    /// <summary>
    /// 判断组合按键
    /// </summary>
    /// <param name="prekey"></param>
    /// <param name="postkey"></param>
    /// <param name="postkeyevent"></param>
    /// <returns></returns>
    private bool IsCombinationKey(EventModifiers prekey, KeyCode postkey, EventType postkeyevent)
    {
        if (prekey != EventModifiers.None)
        {
            bool eventDown = (Event.current.modifiers & prekey) != 0;
            if (eventDown && Event.current.rawType == postkeyevent && Event.current.keyCode == postkey)
            {
                Event.current.Use();

                if (postkey != KeyCode.None)
                {
                    Debug.Log(string.Format("{0} + {1}", prekey.ToString(), postkey.ToString()));
                }
                else
                {
                    Debug.Log(string.Format("{0} + {1}", prekey.ToString(), postkeyevent.ToString()));
                }

                return(true);
            }
        }
        else
        {
            if (Event.current.rawType == postkeyevent && Event.current.keyCode == postkey)
            {
                Event.current.Use();

                if (postkey != KeyCode.None)
                {
                    Debug.Log(string.Format("{0}", postkey.ToString()));
                }
                else
                {
                    Debug.Log(string.Format("{0}", postkeyevent.ToString()));
                }

                return(true);
            }
        }
        return(false);
    }
 public override string ToString()
 {
     return(string.Format("{0}: {1}, {2} ({3})", action, key.ToString(), eventModifiers.ToString(), (int)eventModifiers));
 }
Ejemplo n.º 3
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);
        }