private static int DoSearchablePopup(Rect position, int controlID, int selected, string[] popupValues, Func <int, bool> checkEnabled, GUIStyle style)
        {
            selected = PopupCallbackInfo.GetSelectedValueForControl(controlID, selected);

            Event evt = Event.current;

            switch (evt.type)
            {
            case EventType.Repaint:

                GUIContent buttonContent;
                if (EditorGUI.showMixedValue)
                {
                    buttonContent = s_mixedValueContent;
                }
                else if (selected < 0 || selected >= popupValues.Length)
                {
                    buttonContent = GUIContent.none;
                }
                else
                {
                    buttonContent = EditorGUIUtilityX.TempContent(popupValues[selected]);
                }

                BeginHandleMixedValueContentColor();
                style.Draw(position, buttonContent, controlID, false, position.Contains(Event.current.mousePosition));
                EndHandleMixedValueContentColor();
                break;

            case EventType.MouseDown:
                if (evt.button == 0 && position.Contains(evt.mousePosition))
                {
                    if (Application.platform == RuntimePlatform.OSXEditor)
                    {
                        position.y = position.y - selected * 16 - 19;
                    }

                    PopupCallbackInfo.instance = new PopupCallbackInfo(controlID);
                    EditorUtilityX.DisplaySearchableCustomMenu(position, popupValues, checkEnabled, EditorGUI.showMixedValue ? -1 : selected, PopupCallbackInfo.instance.SetEnumValueDelegate, null);
                    GUIUtility.keyboardControl = controlID;
                    evt.Use();
                }
                break;

            case EventType.KeyDown:
                if (evt.MainActionKeyForControl(controlID))
                {
                    if (Application.platform == RuntimePlatform.OSXEditor)
                    {
                        position.y = position.y - selected * 16 - 19;
                    }

                    PopupCallbackInfo.instance = new PopupCallbackInfo(controlID);
                    EditorUtilityX.DisplaySearchableCustomMenu(position, popupValues, checkEnabled, EditorGUI.showMixedValue ? -1 : selected, PopupCallbackInfo.instance.SetEnumValueDelegate, null);
                    evt.Use();
                }
                break;
            }
            return(selected);
        }
        private static void OnHierarchyItemGUI(int instanceID, Rect selectionRect)
        {
            InitializeIfNeeded();

            GameObject gameObject = (GameObject)EditorUtility.InstanceIDToObject(instanceID);

            if (gameObject != null && PrefabUtility.IsAnyPrefabInstanceRoot(gameObject))
            {
                var originalPrefab = AssetDatabase.LoadAssetAtPath <GameObject>(PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(gameObject));
                if (originalPrefab != null)
                {
                    string cleanedGOName = StripGameObjectCloneNumberFromName(gameObject.name); // remove (1) from "PFB_MyElement(1)"

                    if (cleanedGOName != originalPrefab.name)
                    {
                        var  goLabel     = EditorGUIUtilityX.TempContent(gameObject.name);
                        Rect goLabelRect = GUILayoutUtility.GetRect(goLabel, EditorStyles.label, GUILayout.ExpandWidth(false));
                        selectionRect.position += Vector2.right * (goLabelRect.width + 20);
                        GUI.Label(selectionRect, $"({originalPrefab.name})", s_style);
                    }
                }
            }
        }
Exemple #3
0
        private static void DrawSymbolList()
        {
            EditorGUILayout.BeginVertical(EditorStyles.helpBox);

            EditorGUILayout.LabelField("Symbols", EditorStyles.boldLabel);

            {
                List <string> symbolsToRemove = ListPool <string> .Take();

                foreach (var symbol in ScriptDefineSymbolManager.GetSymbols())
                {
                    if (!s_symbolFoldStates.ContainsKey(symbol))
                    {
                        s_symbolFoldStates.Add(symbol, false);
                    }

                    s_symbolFoldStates[symbol] = EditorGUILayout.BeginFoldoutHeaderGroup(s_symbolFoldStates[symbol], symbol.Name, menuAction: (Rect rect) =>
                    {
                        Rect screenRect = GUIUtility.GUIToScreenRect(rect);
                        var genericMenu = new GenericMenu();

                        if (symbol.ProvidedByCode)
                        {
                            genericMenu.AddDisabledItem(new GUIContent("Delete"));
                            genericMenu.AddDisabledItem(new GUIContent("Edit"));
                        }
                        else
                        {
                            genericMenu.AddItem(new GUIContent("Delete"), false, () =>
                            {
                                if (EditorUtility.DisplayDialog("Delete Symbol", $"Are you sure you want to delete the symbol \"{symbol}\" ?", "Yes", "Cancel"))
                                {
                                    ScriptDefineSymbolManager.DeleteSymbol(symbol.Name);
                                }
                            });
                            genericMenu.AddItem(new GUIContent("Edit"), false, () =>
                            {
                                PopupEditSymbol.Get(screenRect, symbol.Name, symbol.Description);
                            });
                        }
                        genericMenu.ShowAsContext();
                    });

                    if (s_symbolFoldStates[symbol])
                    {
                        if (symbol.ProvidedByCode)
                        {
                            var content = EditorGUIUtilityX.TempContent($"(provided by '{symbol.CodeAssembly.GetName().Name}' assembly)");
                            var size    = EditorStyles.miniLabel.CalcSize(content);
                            EditorGUILayout.LabelField(content, EditorStyles.miniLabel, GUILayout.Width(size.x));
                        }

                        EditorGUI.indentLevel++;
                        if (!string.IsNullOrEmpty(symbol.Description))
                        {
                            EditorGUILayout.LabelField(symbol.Description, EditorStylesX.LongText);
                        }
                        else
                        {
                            EditorGUILayout.LabelField("No description", EditorStylesX.LongText);
                        }
                        EditorGUI.indentLevel--;
                    }

                    EditorGUILayout.EndFoldoutHeaderGroup();
                }

                foreach (var symbol in symbolsToRemove)
                {
                    ScriptDefineSymbolManager.DeleteSymbol(symbol);
                }

                ListPool <string> .Release(symbolsToRemove);
            }

            if (GUILayout.Button("New Symbol"))
            {
                PopupCreateSymbol.Get(s_createSymbolButtonRect);
            }

            if (Event.current.type == EventType.Repaint)
            {
                s_createSymbolButtonRect = GUIUtility.GUIToScreenRect(GUILayoutUtility.GetLastRect());
            }


            EditorGUILayout.EndVertical();
        }
        public static void SearchablePopupString(Rect position, SerializedProperty property, string[] displayedOptions, Func <int, bool> checkEnabled, GUIStyle style)
        {
            GUIContent label = EditorGUIUtilityX.TempContent(property.displayName);

            SearchablePopupString(position, property, label, displayedOptions, checkEnabled, style);
        }