Esempio n. 1
0
        private static void CatchGlobalKeyEvents(Event current)
        {
            if (current.type != EventType.KeyUp)
            {
                return;
            }
            ModifierKey modifier    = ExtShortCutEditor.GetModifierKey(UnityEssentialsPreferences.SHORTCUT_MODIFIER_KEY_FOR_PREVIOUS_NEXT_SELECTION, (int)UnityEssentialsPreferences.DEFAULT_MODIFIER_KEY);
            KeyCode     previousKey = ExtShortCutEditor.GetKey(UnityEssentialsPreferences.SHORTCUT_KEY_FOR_PREVIOUS_SELECTION, (int)UnityEssentialsPreferences.DEFAULT_PREVIOUS_KEY);
            KeyCode     nextKey     = ExtShortCutEditor.GetKey(UnityEssentialsPreferences.SHORTCUT_KEY_FOR_NEXT_SELECTION, (int)UnityEssentialsPreferences.DEFAULT_NEXT_KEY);

            bool shortCutPrevious = ExtShortCutEditor.IsModifierEnumMatch(Event.current, modifier) && current.keyCode == previousKey;
            bool shortCutNext     = ExtShortCutEditor.IsModifierEnumMatch(Event.current, modifier) && current.keyCode == nextKey;

            if (shortCutPrevious)
            {
                if (Selection.objects.Length != 0)
                {
                    AddToIndex(-1);
                }
                ForceSelection(PeekSerializeObject.SelectedObjectsIndex(PeekSerializeObject.CurrentIndex));
            }
            else if (shortCutNext)
            {
                AddToIndex(1);
                ForceSelection(PeekSerializeObject.SelectedObjectsIndex(PeekSerializeObject.CurrentIndex));
            }
        }
        /// <summary>
        /// display inside preferences
        /// </summary>
        /// <param name="serialized"></param>
        private static void PreferenceGUI()
        {
            EditorGUILayout.HelpBox(SHORT_NAME_PREFERENCE + " Preferences", MessageType.Info);

            if (!ExtGUILayout.Section("Peek Toolbar", "Slider Icon", true, "Peek toolbar fold options", PADDING_BOTTOM_SECTION))
            {
                ManageBool(SHOW_PEEK_MENU, "Show Peek menu", "Show main toolbar menu", true);
                ManageSlider(POSITION_IN_TOOLBAR, "Position in toolbar: ", "Desired Position on unity toolbar", DEFAULT_TOOLBAR_POSITION, 0f, 1f);
                GUILayout.Space(SPACING_SECTION);
            }

            if (!ExtGUILayout.Section("Shortcuts", "PreTextureAlpha", true, "Shortcut Peek Toolbar fold options", PADDING_BOTTOM_SECTION))
            {
                ExtShortCutEditor.ShortCutOneModifier2Keys("Selection Back & Forward: ",
                                                           "Shortcut to browse through previous selections",
                                                           SHORTCUT_MODIFIER_KEY_FOR_PREVIOUS_NEXT_SELECTION, DEFAULT_MODIFIER_KEY,
                                                           SHORTCUT_KEY_FOR_PREVIOUS_SELECTION, DEFAULT_PREVIOUS_KEY,
                                                           SHORTCUT_KEY_FOR_NEXT_SELECTION, DEFAULT_NEXT_KEY);

                GUILayout.Space(SPACING_SECTION);
            }

            if (!ExtGUILayout.Section("Peek Window", "winbtn_win_rest_h", true, "Peek window fold options", PADDING_BOTTOM_SECTION))
            {
                EditorGUI.BeginChangeCheck();
                {
                    ManagePositiveInt(MAX_SELECTED_OBJECT_STORED, "Max global storage", "max previous selection saved", 1000);
                    ManagePositiveInt(MAX_SELECTED_OBJECT_SHOWN, "Max previously selected shown", "max item shown inside the previously selected section", 100);
                    ManagePositiveInt(MAX_PINNED_OBJECT, "Max bookmark", "Max Bookmarked objects", 20);
                }
                if (EditorGUI.EndChangeCheck())
                {
                    if (PeekSerializeObject.ShrunkListIfNeeded())
                    {
                        PeekSerializeObject.Save();
                    }
                }
                ManageBool(SHOW_GAMEOBJECTS_FROM_OTHER_SCENE, "Show GameOjbects from other scene", "the reference may be recover if user change scene, or Undo deletion", true);
                EditorGUI.BeginChangeCheck();
                {
                    ManageSliderInt(FONT_SIZE_PEEK_WINDOW, "Font of gameObject's name: ", "Font of the text inside each items", DEFAULT_FONT_PEEK_WINDOW_ITEMS, 6, 20);
                }
                if (EditorGUI.EndChangeCheck())
                {
                    ExtGUIStyles.MicroButtonLeftCenter.fontSize = EditorPrefs.GetInt(FONT_SIZE_PEEK_WINDOW, 14);
                }
                DisplayClearListButton();
                GUILayout.Space(SPACING_SECTION);
            }
        }
        /// <summary>
        /// display the content of the peek toolBar
        /// </summary>
        public bool DisplayPeekToolBar()
        {
            if (PeekSaveDatas.Instance == null)
            {
                return(false);
            }

            if (PeekSerializeObject.CurrentIndex >= PeekSerializeObject.SelectedObjectsCount)
            {
                PeekSerializeObject.SetCurrentIndex(PeekSerializeObject.SelectedObjectsCount - 1);
                PeekSerializeObject.Save(30);
            }

            using (VerticalScope vertical = new VerticalScope())
            {
                GUILayout.Label("Browse selections", ExtGUIStyles.MiniTextCentered, GUILayout.Height(_heightText));
                using (HorizontalScope horizontal = new HorizontalScope())
                {
                    if (GUILayout.Button(EditorGUIUtility.IconContent(OPEN_EDITOR_WINDOW_ICON), ExtGUIStyles.MicroButton, GUILayout.Width(28), GUILayout.Height(EditorGUIUtility.singleLineHeight)) && Event.current.button == 0)
                    {
                        PeekLogic.ManageOpenPeekEditorWindow();
                    }
#if UNITY_2018_3_OR_NEWER
                    if (IsRightClickContext())
                    {
                        return(true);
                    }
#endif


                    EditorGUI.BeginDisabledGroup(PeekSerializeObject.SelectedObjectsCount == 0);
                    {
                        float         delta           = 0;
                        bool          isScrollingDown = ExtMouse.IsScrollingDown(Event.current, ref delta);
                        StringBuilder previousTip     = new StringBuilder();
                        previousTip.Append("Go to previous selection (");
                        previousTip.Append(ExtShortCutEditor.GetModifierKey(UnityEssentialsPreferences.SHORTCUT_MODIFIER_KEY_FOR_PREVIOUS_NEXT_SELECTION, (int)UnityEssentialsPreferences.DEFAULT_MODIFIER_KEY));
                        previousTip.Append("+");
                        previousTip.Append(ExtShortCutEditor.GetKey(UnityEssentialsPreferences.SHORTCUT_KEY_FOR_PREVIOUS_SELECTION, (int)UnityEssentialsPreferences.DEFAULT_PREVIOUS_KEY));
                        previousTip.Append(")");

                        if ((GUILayout.Button(new GUIContent(PREVIOUS_ICON, previousTip.ToString()), ExtGUIStyles.MicroButton, GUILayout.Width(23), GUILayout.Height(EditorGUIUtility.singleLineHeight)) && Event.current.button == 0) || isScrollingDown)
                        {
                            if (Selection.objects.Length != 0)
                            {
                                PeekLogic.AddToIndex(-1);
                            }
                            PeekLogic.ForceSelection(PeekSerializeObject.SelectedObjectsIndex(PeekSerializeObject.CurrentIndex));
                        }
#if UNITY_2018_3_OR_NEWER
                        if (IsRightClickContext())
                        {
                            return(true);
                        }
#endif
                        bool          isScrollingUp = ExtMouse.IsScrollingUp(Event.current, ref delta);
                        StringBuilder nextTip       = new StringBuilder();
                        nextTip.Append("Go to next selection (");
                        nextTip.Append(ExtShortCutEditor.GetModifierKey(UnityEssentialsPreferences.SHORTCUT_MODIFIER_KEY_FOR_PREVIOUS_NEXT_SELECTION, (int)UnityEssentialsPreferences.DEFAULT_MODIFIER_KEY));
                        nextTip.Append("+");
                        nextTip.Append(ExtShortCutEditor.GetKey(UnityEssentialsPreferences.SHORTCUT_KEY_FOR_NEXT_SELECTION, (int)UnityEssentialsPreferences.DEFAULT_NEXT_KEY));
                        nextTip.Append(")");

                        if ((GUILayout.Button(new GUIContent(NEXT_ICON, nextTip.ToString()), ExtGUIStyles.MicroButton, GUILayout.Width(23), GUILayout.Height(EditorGUIUtility.singleLineHeight)) && Event.current.button == 0) || isScrollingUp)
                        {
                            PeekLogic.AddToIndex(1);
                            PeekLogic.ForceSelection(PeekSerializeObject.SelectedObjectsIndex(PeekSerializeObject.CurrentIndex));
                        }
#if UNITY_2018_3_OR_NEWER
                        if (IsRightClickContext())
                        {
                            return(true);
                        }
#endif

                        if (PeekSerializeObject.SelectedObjectsCount == 0)
                        {
                            GUIContent gUIContent = new GUIContent("-/-", "there is no previously selected objects");
                            GUILayout.Label(gUIContent);
                        }
                        else
                        {
                            string     showCount  = (PeekSerializeObject.CurrentIndex + 1).ToString() + "/" + (PeekSerializeObject.SelectedObjectsCount);
                            GUIContent gUIContent = new GUIContent(showCount, "Scroll Up/Down to browse previous/next");
                            GUILayout.Label(gUIContent);
                        }
                    }
                    EditorGUI.EndDisabledGroup();
                }
            }
            GUILayout.FlexibleSpace();
            return(false);
        }