Beispiel #1
0
            public static int GetSelectedValueForControl(int controlID, int mask, out int changedFlags, out bool changedToValue)
            {
                var evt = Event.current;

                // No flags are changed by default
                changedFlags   = 0;
                changedToValue = false;

                if (evt.type == EventType.ExecuteCommand && evt.commandName == kMaskMenuChangedMessage)
                {
                    if (m_Instance == null)
                    {
                        Debug.LogError("Mask menu has no instance");
                        return(mask);
                    }
                    if (m_Instance.m_ControlID == controlID)
                    {
                        changedFlags   = mask ^ m_Instance.m_NewMask;
                        changedToValue = (m_Instance.m_NewMask & changedFlags) != 0;

                        if (changedFlags != 0)
                        {
                            mask        = m_Instance.m_NewMask;
                            GUI.changed = true;
                        }

                        m_Instance = null;
                        evt.Use();
                    }
                }
                return(mask);
            }
Beispiel #2
0
        /// Make a field for a generic mask.
        /// This version also gives you back which flags were changed and what they were changed to.
        /// This is useful if you want to make the same change to multiple objects.
        internal static int DoMaskField(Rect position, int controlID, int mask, string[] flagNames, int[] flagValues, GUIStyle style, out int changedFlags, out bool changedToValue)
        {
            mask = MaskCallbackInfo.GetSelectedValueForControl(controlID, mask, out changedFlags, out changedToValue);

            string buttonText;

            string[] optionNames;
            int[]    optionMaskValues;
            int[]    selectedOptions;
            GetMenuOptions(mask, flagNames, flagValues, out buttonText, out optionNames, out optionMaskValues, out selectedOptions);

            Event evt = Event.current;

            if (evt.type == EventType.Repaint)
            {
                GUIContent buttonContent = EditorGUI.showMixedValue ? EditorGUI.mixedValueContent : EditorGUIUtility.TempContent(buttonText);
                style.Draw(position, buttonContent, controlID, false, position.Contains(evt.mousePosition));
            }
            else if ((evt.type == EventType.MouseDown && position.Contains(evt.mousePosition)) || evt.MainActionKeyForControl(controlID))
            {
                MaskCallbackInfo.m_Instance = new MaskCallbackInfo(controlID);
                evt.Use();
                EditorUtility.DisplayCustomMenu(position, optionNames,
                                                // Only show selections if we are not multi-editing
                                                EditorGUI.showMixedValue ? new int[] {} : selectedOptions,
                                                // optionMaskValues is from the pool so use a clone of the values for the current control
                                                MaskCallbackInfo.m_Instance.SetMaskValueDelegate, optionMaskValues.Clone());
                EditorGUIUtility.keyboardControl = controlID;
            }

            return(mask);
        }
Beispiel #3
0
        internal static int DoMaskField(Rect position, int controlID, int mask, string[] flagNames, GUIStyle style, out int changedFlags, out bool changedToValue)
        {
            Event event2;

            mask = MaskCallbackInfo.GetSelectedValueForControl(controlID, mask, out changedFlags, out changedToValue);
            List <int>    list  = new List <int>();
            List <string> list2 = new List <string> {
                "Nothing", "Everything"
            };

            for (int i = 0; i < flagNames.Length; i++)
            {
                if ((mask & (((int)1) << i)) != 0)
                {
                    list.Add(i + 2);
                }
            }
            list2.AddRange(flagNames);
            GUIContent mixedValueContent = EditorGUI.mixedValueContent;

            if (!EditorGUI.showMixedValue)
            {
                switch (list.Count)
                {
                case 0:
                    mixedValueContent = EditorGUIUtility.TempContent("Nothing");
                    list.Add(0);
                    goto Label_00F9;

                case 1:
                    mixedValueContent = new GUIContent(list2[list[0]]);
                    goto Label_00F9;
                }
                if (list.Count >= flagNames.Length)
                {
                    mixedValueContent = EditorGUIUtility.TempContent("Everything");
                    list.Add(1);
                    mask = -1;
                }
                else
                {
                    mixedValueContent = EditorGUIUtility.TempContent("Mixed ...");
                }
            }
Label_00F9:
            event2 = Event.current;
            if (event2.type == EventType.Repaint)
            {
                style.Draw(position, mixedValueContent, controlID, false);
                return(mask);
            }
            if (((event2.type == EventType.MouseDown) && position.Contains(event2.mousePosition)) || event2.MainActionKeyForControl(controlID))
            {
                MaskCallbackInfo.m_Instance = new MaskCallbackInfo(controlID);
                event2.Use();
                EditorUtility.DisplayCustomMenu(position, list2.ToArray(), !EditorGUI.showMixedValue ? list.ToArray() : new int[0], new EditorUtility.SelectMenuItemFunction(MaskCallbackInfo.m_Instance.SetMaskValueDelegate), null);
            }
            return(mask);
        }
            public static int GetSelectedValueForControl(int controlID, int mask, out int changedFlags, out bool changedToValue)
            {
                var evt = Event.current;

                // No flags are changed by default
                changedFlags   = 0;
                changedToValue = false;

                if (evt.type == EventType.ExecuteCommand && evt.commandName == kMaskMenuChangedMessage)
                {
                    if (m_Instance == null)
                    {
                        Debug.LogError("Mask menu has no instance");
                        return(mask);
                    }
                    if (m_Instance.m_ControlID == controlID)
                    {
                        if (!m_Instance.m_DoNothing)
                        {
                            if (m_Instance.m_ClearAll)
                            {
                                mask           = 0;
                                changedFlags   = ~0;
                                changedToValue = false;
                            }
                            else if (m_Instance.m_SetAll)
                            {
                                mask           = ~0;
                                changedFlags   = ~0;
                                changedToValue = true;
                            }
                            else
                            {
                                mask          ^= m_Instance.m_Mask;
                                changedFlags   = m_Instance.m_Mask;
                                changedToValue = (mask & m_Instance.m_Mask) != 0;
                            }

                            GUI.changed = true;
                        }
                        m_Instance.m_DoNothing = false;
                        m_Instance.m_ClearAll  = false;
                        m_Instance.m_SetAll    = false;
                        m_Instance             = null;
                        evt.Use();
                    }
                }
                return(mask);
            }
        /// Make a field for a generic mask.
        /// This version also gives you back which flags were changed and what they were changed to.
        /// This is useful if you want to make the same change to multiple objects.
        internal static int DoMaskField(Rect position, int controlID, int mask, string[] flagNames, int[] flagValues, GUIStyle style, out int changedFlags, out bool changedToValue, Type enumType = null)
        {
            mask = MaskCallbackInfo.GetSelectedValueForControl(controlID, mask, out changedFlags, out changedToValue);

            GetMenuOptions(mask, flagNames, flagValues, out var buttonText, out var buttonTextMixed, out var optionNames, out var optionMaskValues, out var selectedOptions, enumType);

            Event evt = Event.current;

            if (evt.type == EventType.Repaint)
            {
                var buttonContent = EditorGUI.showMixedValue ? EditorGUI.mixedValueContent : DoMixedLabel(buttonText, buttonTextMixed, position, style);
                style.Draw(position, buttonContent, controlID, false, position.Contains(evt.mousePosition));
            }
            else if ((evt.type == EventType.MouseDown && position.Contains(evt.mousePosition)) || evt.MainActionKeyForControl(controlID))
            {
                MaskCallbackInfo.m_Instance = new MaskCallbackInfo(controlID);
                PopupWindowWithoutFocus.Show(position, new MaskFieldDropDown(optionNames, optionMaskValues, mask, MaskCallbackInfo.m_Instance.SetMaskValueDelegate));
            }

            return(mask);
        }
        /// Make a field for a generic mask.
        /// This version also gives you back which flags were changed and what they were changed to.
        /// This is useful if you want to make the same change to multiple objects.
        internal static int DoMaskField(Rect position, int controlID, int mask, string[] flagNames, int[] flagValues, GUIStyle style, out int changedFlags, out bool changedToValue)
        {
            mask = MaskCallbackInfo.GetSelectedValueForControl(controlID, mask, out changedFlags, out changedToValue);
            var selectedFlags = new List <int>();
            var fullFlagNames = new List <string> {
                "Nothing", "Everything"
            };

            for (var i = 0; i < flagNames.Length; i++)
            {
                if ((mask & flagValues[i]) != 0)
                {
                    selectedFlags.Add(i + 2);
                }
            }

            fullFlagNames.AddRange(flagNames);

            GUIContent buttonContent = EditorGUI.mixedValueContent;

            if (!EditorGUI.showMixedValue)
            {
                switch (selectedFlags.Count)
                {
                case 0:
                    buttonContent = EditorGUIUtility.TempContent("Nothing");
                    selectedFlags.Add(0);
                    break;

                case 1:
                    buttonContent = new GUIContent(fullFlagNames[selectedFlags[0]]);
                    break;

                default:
                    if (selectedFlags.Count >= flagNames.Length)
                    {
                        buttonContent = EditorGUIUtility.TempContent("Everything");
                        selectedFlags.Add(1);
                        // When every available item is selected, we force to ~0 to keep the mask int value consistent
                        // between the cases where all items are individually selected vs. user clicks "everything"
                        mask = ~0;
                    }
                    else
                    {
                        buttonContent = EditorGUIUtility.TempContent("Mixed ...");
                    }
                    break;
                }
            }
            Event evt = Event.current;

            if (evt.type == EventType.Repaint)
            {
                style.Draw(position, buttonContent, controlID, false);
            }
            else if ((evt.type == EventType.MouseDown && position.Contains(evt.mousePosition)) || evt.MainActionKeyForControl(controlID))
            {
                MaskCallbackInfo.m_Instance = new MaskCallbackInfo(controlID);
                evt.Use();
                EditorUtility.DisplayCustomMenu(position, fullFlagNames.ToArray(),
                                                // Only show selections if we are not multi-editing
                                                EditorGUI.showMixedValue ? new int[] {} : selectedFlags.ToArray(),
                                                MaskCallbackInfo.m_Instance.SetMaskValueDelegate, flagValues);
                EditorGUIUtility.keyboardControl = controlID;
            }
            return(mask);
        }