//------------------------------------------------------------------------/ // Methods //------------------------------------------------------------------------/ /// <summary> /// Displays an searchable enum popup /// </summary> /// <param name="position"></param> /// <param name="label"></param> /// <param name="selected"></param> /// <returns></returns> public static void EnumPopup(Rect position, string label, Enum selected, System.Action <Enum> onSelected) { int id = GUIUtility.GetControlID(hash, FocusType.Keyboard, position); // Prefix GUIContent labelContent = new GUIContent(label); position = EditorGUI.PrefixLabel(position, id, labelContent); int index = 0; // Enum Drawer Type enumType = selected.GetType(); string[] displayedOptions = GetEnumDisplayNames(enumType); GUIContent enumValueContent = new GUIContent(selected.ToString()); if (StratusSearchablePopup.DropdownButton(id, position, enumValueContent)) { System.Action <int> onSelectIndex = i => { Enum value = GetEnumValue(enumType, i); StratusDebug.Log($"Selected {value}"); onSelected(value); }; StratusSearchablePopup.EditorGUI(position, index, displayedOptions, onSelectIndex); } }
/// <summary> /// Displays an searchable enum popup /// </summary> /// <param name="position"></param> /// <param name="label"></param> /// <param name="selected"></param> /// <returns></returns> public static void EnumPopup(Rect position, GUIContent label, SerializedProperty property) { int id = GUIUtility.GetControlID(hash, FocusType.Keyboard, position); // Prefix position = EditorGUI.PrefixLabel(position, id, label); // Enum Drawer string[] displayedOptions = property.enumDisplayNames; GUIContent enumValueContent = new GUIContent(displayedOptions[property.enumValueIndex]); if (StratusSearchablePopup.DropdownButton(id, position, enumValueContent)) { System.Action <int> onSelect = i => { property.enumValueIndex = i; property.serializedObject.ApplyModifiedProperties(); }; StratusSearchablePopup.EditorGUI(position, property.enumValueIndex, displayedOptions, onSelect); } }