示例#1
0
        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);
            }

            MaskFieldGUI.GetMenuOptions(mask, displayedOptions, flagValues, out var buttonText, out var buttonTextMixed, out var optionNames, out var optionMaskValues, out var selectedOptions);

            var id = EditorGUIUtility.GetControlID("AdvancedDropdown".GetHashCode(), FocusType.Keyboard, rect);

            var buttonContent = MaskFieldGUI.DoMixedLabel(buttonText, buttonTextMixed, rect, EditorStyles.popup);

            if (EditorGUI.DropdownButton(id, rect, buttonContent, 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);
        }
示例#2
0
        public static Enum DoEnumMaskPopup(Rect rect, Enum options, GUIStyle style)
        {
            var enumData    = EnumDataUtility.GetCachedEnumData(options.GetType());
            var optionValue = EnumDataUtility.EnumFlagsToInt(enumData, options);

            MaskFieldGUI.GetMenuOptions(optionValue, enumData.displayNames, enumData.flagValues, out var buttonText, out var buttonTextMixed, out var optionNames, out var optionMaskValues, out var selectedOptions);

            var id = EditorGUIUtility.GetControlID("AdvancedDropdown".GetHashCode(), FocusType.Keyboard, rect);

            var buttonContent = MaskFieldGUI.DoMixedLabel(buttonText, buttonTextMixed, rect, EditorStyles.popup);

            if (EditorGUI.DropdownButton(id, rect, buttonContent, 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);
        }