internal static int DoMaskField(Rect position, int controlID, int mask, string[] flagNames, int[] flagValues, GUIStyle style, out int changedFlags, out bool changedToValue) { mask = MaskFieldGUI.MaskCallbackInfo.GetSelectedValueForControl(controlID, mask, out changedFlags, out changedToValue); string t; string[] options; int[] array; int[] array2; MaskFieldGUI.GetMenuOptions(mask, flagNames, flagValues, out t, out options, out array, out array2); Event current = Event.current; if (current.type == EventType.Repaint) { GUIContent content = (!EditorGUI.showMixedValue) ? EditorGUIUtility.TempContent(t) : EditorGUI.mixedValueContent; style.Draw(position, content, controlID, false); } else if ((current.type == EventType.MouseDown && position.Contains(current.mousePosition)) || current.MainActionKeyForControl(controlID)) { MaskFieldGUI.MaskCallbackInfo.m_Instance = new MaskFieldGUI.MaskCallbackInfo(controlID); current.Use(); EditorUtility.DisplayCustomMenu(position, options, (!EditorGUI.showMixedValue) ? array2 : new int[0], new EditorUtility.SelectMenuItemFunction(MaskFieldGUI.MaskCallbackInfo.m_Instance.SetMaskValueDelegate), array.Clone()); GUIUtility.keyboardControl = controlID; } return(mask); }
static int DoMaskField(Rect rect, int mask, string[] displayedOptions, GUIStyle popup) { var flagValues = new int[displayedOptions.Length]; for (int i = 0; i < flagValues.Length; ++i) { flagValues[i] = (1 << i); } string buttonText; string[] optionNames; int[] optionMaskValues; int[] selectedOptions; MaskFieldGUI.GetMenuOptions(mask, displayedOptions, 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(mask, displayedOptions, flagValues); 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.mask); } if (m_WindowClosed && s_CurrentControl == id) { s_CurrentControl = 0; m_WindowClosed = false; var result = s_DataSource.mask; s_DataSource = null; return(result); } return(mask); }
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); }