Exemplo n.º 1
0
        private void DisplayOneItem(Object toDisplay, string nameInListPath, int index, float width, bool disable)
        {
            if (toDisplay == null && string.IsNullOrEmpty(nameInListPath))
            {
                return;
            }

            if (toDisplay == null && !UnityEssentialsPreferences.GetBool(UnityEssentialsPreferences.SHOW_GAMEOBJECTS_FROM_OTHER_SCENE, true))
            {
                return;
            }

            GUI.color = (PeekSerializeObject.LastSelectedObject == toDisplay && toDisplay != null) ? Color.green : Color.white;

            EditorGUI.BeginDisabledGroup(disable);
            {
                using (HorizontalScope horizontalScope = new HorizontalScope(GUILayout.Width(width), GUILayout.Height(_heightLine)))
                {
                    float widthExtent = CalculateWidthExtentOptions.CalculateWidthExtent(width, index, ListToDisplay.arraySize);
                    float widthButtonWithoutExtent = CalculateWidthExtentOptions.CalculateButtonWidthWithoutExtent(widthExtent, _heightLine, _margin);

                    if (_calculateExtent)
                    {
                        GUILayout.Label("", GUILayout.Width(widthExtent), GUILayout.Height(_heightLine));
                    }
                    //display bookmark button
                    bool clicOnBookMark = BookMarkButtonOptions.ButtonImageWithHover(WIDTH_BUTTON_HOVER, toDisplay != null, _heightLine);
                    if (clicOnBookMark)
                    {
                        OnBookMarkClic?.Invoke(index);
                        return;
                    }
                    //display main logo
                    DisplayLogoByTypeOfObject(toDisplay, _heightLine);
                    if (!disable && !_dragSettings.IsDragging)
                    {
                        Rect logoContent = GUILayoutUtility.GetLastRect();
                        if (logoContent.Contains(Event.current.mousePosition))
                        {
                            EditorGUIUtility.AddCursorRect(logoContent, MouseCursor.MoveArrow);
                            if (Event.current.type == EventType.MouseDown)
                            {
                                _listToDisplayCopy = ListToDisplay.ToObjectList();
                                _dragSettings.StartDragging(index, logoContent);
                                Event.current.Use();
                            }
                        }
                    }
                    //display main button
                    EditorGUI.BeginDisabledGroup(toDisplay == null);
                    {
                        string nameObjectToSelect;
                        if (toDisplay == null)
                        {
                            nameObjectToSelect = !string.IsNullOrEmpty(nameInListPath) ? ObjectNames.NicifyVariableName(nameInListPath) : " --- not found --- ";
                        }
                        else
                        {
                            nameObjectToSelect = ObjectNames.NicifyVariableName(toDisplay.name);
                        }


                        GUIContent buttonSelectContent = ShortenNameIfNeeded(nameObjectToSelect, width, widthButtonWithoutExtent);
                        buttonSelectContent.tooltip = "Clic to select, Right clic to Pin only";
                        if (GUILayout.Button(buttonSelectContent, BookMarkButtonOptions.GuiStyle, GUILayout.ExpandWidth(true), GUILayout.Height(_heightLine)))
                        {
                            if (Event.current.button == 0)
                            {
                                OnSelectItem?.Invoke(index);
                            }
                            else
                            {
                                OnPinItem?.Invoke(index);
                            }
                            return;
                        }
                    }
                    EditorGUI.EndDisabledGroup();

                    //display special scene buttons
                    if (toDisplay == null && OnInfoItem != null)
                    {
                        bool selectScene = false;
                        bool goToScene   = false;

                        DisplaySpecialSceneSettings(ref selectScene, ref goToScene);
                        if (goToScene)
                        {
                            OnInfoForceItem?.Invoke(index);
                            return;
                        }
                        else if (selectScene)
                        {
                            OnInfoItem?.Invoke(index);
                            return;
                        }
                    }

                    //display delete button
                    GUIContent buttonDeletContent = EditorGUIUtility.IconContent(DELETE_ICON);
                    buttonDeletContent.tooltip = "Remove from list";
                    if (GUILayout.Button(buttonDeletContent, BookMarkButtonOptions.GuiStyle, GUILayout.ExpandWidth(false), GUILayout.MaxWidth(WIDTH_BUTTON_HOVER), GUILayout.Height(_heightLine)) &&
                        Event.current.button == 0)
                    {
                        OnRemoveItem?.Invoke(index);
                        return;
                    }
                    if (_calculateExtent)
                    {
                        GUILayout.Label("", GUILayout.Width(widthExtent), GUILayout.Height(_heightLine));
                    }
                }
            }
            EditorGUI.EndDisabledGroup();
        }
Exemplo n.º 2
0
        public GenericPeekListDrawer(
            PeekEditorWindow peekWindow,
            string iconList,
            string listDescription,
            bool calculateExtent,
            string foldStateKey,
            bool canReorder,

            SerializedProperty list,
            SerializedProperty listPath,
            SerializedProperty sceneLinked,

            string iconBookMark,
            string iconHoverBookMark,
            string toolTipBookMark,
            float height,

            UnityAction <int> onBookMarkClic,
            UnityAction <int> onSelectItem,
            UnityAction <int> onInfoItem,
            UnityAction <int> onInfoForceItem,
            UnityAction <int> onPinItem,
            UnityAction <int> onRemoveItem,
            UnityAction onClear)
        {
            _peekWindow = peekWindow;

            _iconList                = iconList;
            _listDescription         = listDescription;
            _calculateExtent         = calculateExtent;
            _foldStateKey            = foldStateKey;
            _dragSettings.CanReorder = canReorder;
            _heightLine              = height;
            _margin                  = ExtGUIStyles.MicroButtonLeftCenter.margin.top + ExtGUIStyles.MicroButtonLeftCenter.margin.bottom;
            _sceneButton             = new GUIStyle(ExtGUIStyles.MicroButtonScene);
            _sceneButton.fixedHeight = _heightLine - MARGIN_SCENE_BUTTON * 2;

            ListToDisplay     = list;
            ListToDisplayPath = listPath;
            SceneLinkedPath   = sceneLinked;
            OnBookMarkClic    = onBookMarkClic;
            OnSelectItem      = onSelectItem;
            OnInfoItem        = onInfoItem;
            OnInfoForceItem   = onInfoForceItem;
            OnPinItem         = onPinItem;
            OnRemoveItem      = onRemoveItem;
            OnClear           = onClear;

            BookMarkButtonOptions = new ButtonImageWithHoverOptions(
                iconBookMark,
                iconHoverBookMark,
                ExtGUIStyles.MicroButtonLeftCenter,
                toolTipBookMark,
                _heightLine,
                GUILayout.ExpandWidth(false), GUILayout.MaxWidth(30), GUILayout.Height(_heightLine));

            CalculateWidthExtentOptions = new CalculateWidthExtentOptions(
                0.2f,
                10,
                AnimationCurve.EaseInOut(0f, 0f, 1f, 1f));
        }