private static Enum DoEnumPopup(Rect rect, Enum selected, GUIStyle style, params GUILayoutOption[] options) { var enumType = selected.GetType(); var enumData = EnumDataUtility.GetCachedEnumData(enumType); var i = Array.IndexOf(enumData.values, selected); using (new UnityEditor.Localization.Editor.LocalizationGroup(enumType)) { i = DoPopup(rect, i, EditorGUIUtility.TrTempContent(enumData.displayNames, enumData.tooltip)); } return((i < 0 || i >= enumData.flagValues.Length) ? selected : enumData.values[i]); }
public static Enum DoEnumMaskPopup(Rect rect, Enum options, GUIStyle style) { var enumData = EnumDataUtility.GetCachedEnumData(options.GetType()); var optionValue = EnumDataUtility.EnumFlagsToInt(enumData, options); string buttonText; string[] optionNames; int[] optionMaskValues; int[] selectedOptions; MaskFieldGUI.GetMenuOptions(optionValue, enumData.displayNames, enumData.flagValues, out buttonText, out optionNames, out optionMaskValues, out selectedOptions); var id = EditorGUIUtility.GetControlID("AdvancedDropdown".GetHashCode(), FocusType.Keyboard, rect); if (EditorGUI.DropdownButton(id, rect, GUIContent.Temp(buttonText), EditorStyles.popup)) { s_CurrentControl = id; ResetAndCreateWindow(); var dataSource = new MultiselectDataSource(options); InitMultiselectPopupWindow(rect, dataSource); s_Instance.selectionChanged += dataSource.UpdateSelectedId; s_Instance.selectionChanged += i => { m_ShouldReturnValue = true; }; s_Instance.windowClosed += w => { m_WindowClosed = true; }; } if (m_ShouldReturnValue && s_CurrentControl == id) { m_ShouldReturnValue = false; return(s_DataSource.enumFlags); } if (m_WindowClosed && s_CurrentControl == id) { s_CurrentControl = 0; m_WindowClosed = false; var result = s_DataSource.enumFlags; s_DataSource = null; return(result); } return(options); }