Exemplo n.º 1
0
        public static void      Invoke(string name, Type type, string staticMethod)
        {
            if (NGHotkeys.DetectDiff(false) == true)
            {
                return;
            }

            if (type != null)
            {
                MethodInfo method = type.GetMethod(staticMethod, BindingFlags.Public | BindingFlags.Static);

                if (method != null)
                {
                    method.Invoke(null, null);
                    return;
                }
            }

            if (NGHotkeys.failedOnce == name)
            {
                EditorWindow.GetWindow <NGSettingsWindow>(true, NGSettingsWindow.Title, true).Focus("Hotkeys");
            }
            else
            {
                NGHotkeys.failedOnce = name;
                InternalNGDebug.LogWarning("Calling MenuItem \"" + name + "\" has failed. Please regenerate hotkeys file. (Go to Window/NG Tools/NG Settings/Hotkeys or recall this shortcut)");
            }
        }
Exemplo n.º 2
0
        private static void     OnGUISettings()
        {
            if (HQ.Settings == null)
            {
                return;
            }

            EditorGUILayout.Space();

            EditorGUILayout.BeginHorizontal();
            {
                EditorGUILayout.BeginVertical(GUILayoutOptionPool.ExpandWidthTrue);
                GUILayout.Label("Bind a MenuItem with a custom hotkey.", GeneralStyles.SmallLabel);
                if (GUILayout.Button("Help", GUILayoutOptionPool.Width(50F)) == true)
                {
                    Application.OpenURL("https://docs.unity3d.com/ScriptReference/MenuItem.html");
                }
                EditorGUILayout.EndVertical();

                EditorGUILayout.BeginVertical(GUILayoutOptionPool.Width(130F));
                if (EditorApplication.isCompiling == true)
                {
                    using (BgColorContentRestorer.Get(GeneralStyles.HighlightResultButton))
                    {
                        GUILayout.Button("Compiling...", GeneralStyles.BigButton);
                    }
                }
                else
                {
                    EditorGUI.BeginDisabledGroup(NGHotkeys.DetectDiff(true) == false);
                    if (GUILayout.Button("Save", GeneralStyles.BigButton) == true)
                    {
                        NGHotkeys.Generate();
                        HQ.InvalidateSettings(HQ.Settings, true);
                    }
                    EditorGUI.EndDisabledGroup();
                }
                EditorGUILayout.EndVertical();
            }
            EditorGUILayout.EndHorizontal();

            Rect r2 = GUILayoutUtility.GetLastRect();

            r2.x      = 2F;
            r2.width += 13F;
            r2.yMin   = r2.yMax - 1F;
            EditorGUI.DrawRect(r2, Color.gray);

            CustomHotkeysSettings settings = HQ.Settings.Get <CustomHotkeysSettings>();

            NGHotkeys.scrollPosition = EditorGUILayout.BeginScrollView(NGHotkeys.scrollPosition);
            {
                for (int i = 0; i < NGHotkeys.shortcuts.Count; i++)
                {
                    EditorGUILayout.BeginHorizontal();
                    {
                        MenuItemShortcut shortcut = NGHotkeys.shortcuts[i];
                        CustomHotkeysSettings.MethodHotkey hotkey = null;

                        for (int j = 0; j < settings.hotkeys.Count; j++)
                        {
                            if (settings.hotkeys[j].staticMethod == [email protected] + '.' + shortcut.staticMethod)
                            {
                                hotkey = settings.hotkeys[j];
                                break;
                            }
                        }

                        Utility.content.text = shortcut.name;
                        Rect r = GUILayoutUtility.GetRect(Utility.content, GUI.skin.label, GUILayoutOptionPool.Width(170F));
                        EditorGUI.PrefixLabel(r, Utility.content);

                        if (hotkey != null && string.IsNullOrEmpty(hotkey.bind) == false)
                        {
                            float w = r.width;
                            r.x    -= 1F;
                            r.width = 1F;
                            EditorGUI.DrawRect(r, Color.cyan);
                            r.x    += 1F;
                            r.width = w;
                        }

                        bool hasChanged = false;

                        EditorGUI.BeginChangeCheck();
                        r.x    += r.width;
                        r.width = 50F;
                        string bind = EditorGUI.TextField(r, hotkey != null ? hotkey.bind : string.Empty);
                        if (EditorGUI.EndChangeCheck() == true)
                        {
                            hasChanged = true;
                        }
                        r.x += r.width;

                        r.width = 50F;
                        EditorGUI.BeginChangeCheck();
                        GUI.Toggle(r, bind.Contains("%"), "Ctrl", GeneralStyles.ToolbarToggle);
                        if (EditorGUI.EndChangeCheck() == true)
                        {
                            GUI.FocusControl(null);

                            hasChanged = true;

                            int n = bind.IndexOf('%');

                            if (n != -1)
                            {
                                bind = bind.Remove(n, 1);
                            }
                            else
                            {
                                bind = '%' + bind;
                            }
                        }
                        r.x += r.width;

                        EditorGUI.BeginChangeCheck();
                        GUI.Toggle(r, bind.Contains("#"), "Shift", GeneralStyles.ToolbarToggle);
                        if (EditorGUI.EndChangeCheck() == true)
                        {
                            GUI.FocusControl(null);

                            hasChanged = true;

                            int n = bind.IndexOf('#');

                            if (n != -1)
                            {
                                bind = bind.Remove(n, 1);
                            }
                            else
                            {
                                bind = '#' + bind;
                            }
                        }
                        r.x += r.width;

                        EditorGUI.BeginChangeCheck();
                        GUI.Toggle(r, bind.Contains("&"), "Alt", GeneralStyles.ToolbarToggle);
                        if (EditorGUI.EndChangeCheck() == true)
                        {
                            GUI.FocusControl(null);

                            hasChanged = true;

                            int n = bind.IndexOf('&');

                            if (n != -1)
                            {
                                bind = bind.Remove(n, 1);
                            }
                            else
                            {
                                bind = '&' + bind;
                            }
                        }

                        if (hasChanged == true)
                        {
                            if (string.IsNullOrEmpty(bind) == true)
                            {
                                if (hotkey != null)
                                {
                                    settings.hotkeys.Remove(hotkey);
                                }
                            }
                            else
                            {
                                if (hotkey == null)
                                {
                                    settings.hotkeys.Add(new CustomHotkeysSettings.MethodHotkey {
                                        staticMethod = [email protected] + '.' + shortcut.staticMethod, bind = bind
                                    });
                                }
                                else
                                {
                                    hotkey.bind = bind;
                                }
                            }
                        }

                        GUILayout.FlexibleSpace();
                    }
                    EditorGUILayout.EndHorizontal();

                    GUILayout.Space(5F);
                }
            }
            EditorGUILayout.EndScrollView();
        }