Exemplo n.º 1
0
            public override void OnGUI(Rect rect)
            {
                switch (Event.current.type)
                {
                case EventType.MouseMove:
                    int newLine = Mathf.Clamp((int)((Event.current.mousePosition.y - rect.y) / EditorGUIUtility.singleLineHeight), 0, _mode == PopupMode.Bit ? (_count - 1) : (_count + 1));
                    if (_hoverLine != newLine)
                    {
                        _hoverLine = newLine;
                        editorWindow.Repaint();
                    }
                    return;

                case EventType.MouseDown:
                    if (_mode == PopupMode.Bit)
                    {
                        value = _bits[_hoverLine];
                    }
                    else
                    {
                        if (_hoverLine == 0)
                        {
                            value = 0;
                        }
                        else if (_hoverLine == 1)
                        {
                            value = ~0;
                        }
                        else
                        {
                            value = BitwiseKit.ReverseBit(value, _bits[_hoverLine - 2]);
                        }
                    }
                    if (_focusedWindow)
                    {
                        _focusedWindow.Repaint();
                    }
                    editorWindow.Repaint();
                    return;

                case EventType.Repaint:
                    OnPaint(rect);
                    return;
                }
            }
Exemplo n.º 2
0
            static void OnPaint(Rect rect)
            {
                EditorGUI.DrawRect(rect, _windowBackground);
                if (_mode == PopupMode.Mask)
                {
                    rect.height = EditorGUIUtility.singleLineHeight * 2;
                    EditorGUI.DrawRect(rect, _headerBackground);
                }
                rect.height = EditorGUIUtility.singleLineHeight;

                float checkSize   = Mathf.Ceil(rect.height * 0.3f);
                float checkOffset = Mathf.Floor((rect.height - checkSize) * 0.5f);
                var   checkRect   = new Rect(rect.x + checkOffset, rect.y + checkOffset, checkSize, checkSize);
                var   textRect    = rect;

                textRect.xMin = checkRect.xMax + checkOffset;

                if (_mode == PopupMode.Mask)
                {
                    // Nothing

                    if (_hoverLine == 0)
                    {
                        EditorGUI.DrawRect(rect, _mouseHoverColor);
                    }
                    if (value == 0)
                    {
                        EditorGUI.DrawRect(checkRect, defaultContentColor);
                        EditorGUI.LabelField(textRect, "Nothing", EditorStyles.boldLabel);
                    }
                    else
                    {
                        EditorGUI.LabelField(textRect, "Nothing");
                    }

                    rect.y      += rect.height;
                    checkRect.y += rect.height;
                    textRect.y  += rect.height;

                    // Everything

                    if (_hoverLine == 1)
                    {
                        EditorGUI.DrawRect(rect, _mouseHoverColor);
                    }
                    if (value == ~0)
                    {
                        EditorGUI.DrawRect(checkRect, defaultContentColor);
                        EditorGUI.LabelField(textRect, "Everything", EditorStyles.boldLabel);
                    }
                    else
                    {
                        EditorGUI.LabelField(textRect, "Everything");
                    }

                    rect.y      += rect.height;
                    checkRect.y += rect.height;
                    textRect.y  += rect.height;
                }

                // Layers

                for (int i = 0; i < _count; i++)
                {
                    if (_mode == PopupMode.Mask)
                    {
                        if ((_hoverLine - 2) == i)
                        {
                            EditorGUI.DrawRect(rect, _mouseHoverColor);
                        }
                        if (BitwiseKit.GetBit(value, _bits[i]))
                        {
                            EditorGUI.DrawRect(checkRect, defaultContentColor);
                            EditorGUI.LabelField(textRect, _names[i], EditorStyles.boldLabel);
                        }
                        else
                        {
                            EditorGUI.LabelField(textRect, _names[i]);
                        }
                    }
                    else
                    {
                        if (_hoverLine == i)
                        {
                            EditorGUI.DrawRect(rect, _mouseHoverColor);
                        }
                        if (value == _bits[i])
                        {
                            EditorGUI.DrawRect(checkRect, defaultContentColor);
                            EditorGUI.LabelField(textRect, _names[i], EditorStyles.boldLabel);
                        }
                        else
                        {
                            EditorGUI.LabelField(textRect, _names[i]);
                        }
                    }

                    rect.y      += rect.height;
                    checkRect.y += rect.height;
                    textRect.y  += rect.height;
                }
            }