Exemplo n.º 1
0
        public static bool SpriteButton(Sprite sprite, bool respectRatio = false, params GUILayoutOption[] options)
        {
            GUIStyle style       = UnityEngine.GUI.skin.button;
            Rect     controlRect = GUILayoutUtility.GetRect(GUIContent.none, style, options);

            return(GUIEx.SpriteButton(sprite, controlRect, style, respectRatio));
        }
Exemplo n.º 2
0
        public static bool WasClicked(Rect rect, int button)
        {
            var clicked = GUIEx.IsHovering(rect) &&
                          Event.current.type == EventType.MouseDown &&
                          Event.current.button == button;

            if (clicked)
            {
                Event.current.Use();
            }
            return(clicked);
        }
Exemplo n.º 3
0
 public static void DrawBorder(Rect area, float left, float right, float top, float bottom, Color color)
 {
     GUIEx.PushColor(color);
     // Top
     UnityEngine.GUI.DrawTexture(new Rect(area.xMin + top, area.yMin, area.width - top * 2.0f, top), GUIEx.White);
     // Bottom
     UnityEngine.GUI.DrawTexture(new Rect(area.xMin + bottom, area.yMax - bottom, area.width - bottom * 2.0f, bottom),
                                 GUIEx.White);
     // Left
     UnityEngine.GUI.DrawTexture(new Rect(area.xMin, area.yMin, left, area.height), GUIEx.White);
     // Right
     UnityEngine.GUI.DrawTexture(new Rect(area.xMax - right, area.yMin, right, area.height), GUIEx.White);
     GUIEx.PopColor();
 }
Exemplo n.º 4
0
        public static void DrawLabelAtCursor(GUIContent content, GUIStyle style, Color background)
        {
            GUIEx.PushBackgroundColor(background);
            var area = new Rect(Event.current.mousePosition, Vector2.zero);

            float width;

            style.CalcMinMaxWidth(content, out width, out width);
            float height = style.CalcHeight(content, width);

            area.width  = width;
            area.height = height;

            UnityEngine.GUI.Label(area, content, style);
            GUIEx.PopBackgroundColor();
        }
Exemplo n.º 5
0
        public static bool ImageButton(Texture2D image, GUIStyle style, params GUILayoutOption[] options)
        {
            Color    color      = Color.black;
            GUIStyle labelStyle = new GUIStyle(style);

            Rect labelRect = GUILayoutUtility.GetRect(new GUIContent(image), style, options);

            if (GUIEx.IsHovering(labelRect))
            {
                color = Color.blue;
            }

            GUIEx.PushColor(color);
            UnityEngine.GUI.DrawTexture(labelRect, image, ScaleMode.ScaleToFit);
            GUIEx.PopColor();

            return(GUIEx.WasClicked(labelRect, 0));
        }
Exemplo n.º 6
0
        public static bool SpriteButton(Sprite sprite, Rect position, GUIStyle style, bool respectRatio = false)
        {
            bool pressed = UnityEngine.GUI.Button(position, GUIContent.none, style);

            position = position.Expand(-style.border.horizontal, -style.border.vertical);

            if (respectRatio)
            {
                float ratio = sprite.textureRect.height / sprite.textureRect.width;
                if (sprite.textureRect.width > sprite.textureRect.height)
                {
                    position.height *= ratio;
                }
                else
                {
                    position.width *= ratio;
                }
            }

            GUIEx.DrawSprite(sprite, position);
            return(pressed);
        }
Exemplo n.º 7
0
        public static void DrawLines(Vector2[] points, Color[] colors, float width)
        {
            ThrowIf.ArgumentIsNull(points, "points");
            ThrowIf.ArgumentIsNull(colors, "colors");
            ThrowIf.False(points.Length == colors.Length, "Points and colors array must be the same length.");

            for (int i = 0; i < points.Length; ++i)
            {
                Vector2 start = points[i];
                Vector2 end   = points[MathEx.Wrap(i + 1, 0, points.Length - 1)];
                Color   color = colors[i];

                if (Mathf.Abs(start.x - end.x) > Mathf.Abs(start.y - end.y))
                {
                    GUIEx.DrawBox(new Rect(start.x, start.y, end.x - start.x, width), color);
                }
                else
                {
                    GUIEx.DrawBox(new Rect(start.x, start.y, width, end.y - start.y), color);
                }
                GUIEx.PopColor();
            }
        }
Exemplo n.º 8
0
        public static bool LabelButton(string label, GUIStyle style)
        {
            Color    color      = Color.black;
            GUIStyle labelStyle = new GUIStyle(style);

            Rect labelRect = GUILayoutUtility.GetRect(new GUIContent(label), style);

            if (GUIEx.IsHovering(labelRect))
            {
                color = Color.blue;
            }

            Rect underlineRect = labelRect;

            underlineRect.y      = underlineRect.yMax - 2.0f;
            underlineRect.height = 1.0f;

            labelStyle.normal.textColor = color;
            UnityEngine.GUI.Label(labelRect, label, labelStyle);
            GUIEx.DrawBox(underlineRect, color);

            return(false);
        }
Exemplo n.º 9
0
 public static bool WasClicked(Rect rect)
 {
     return(GUIEx.IsHovering(rect) && Event.current.type == EventType.MouseDown);
 }
Exemplo n.º 10
0
 public static bool SpriteButton(Sprite sprite, Rect position, bool respectRatio = false)
 {
     return(GUIEx.SpriteButton(sprite, position, UnityEngine.GUI.skin.button, respectRatio));
 }
Exemplo n.º 11
0
 public static void DrawLabelAtCursor(string text, Color background)
 {
     GUIEx.DrawLabelAtCursor(new GUIContent(text), UnityEngine.GUI.skin.label, background);
 }
Exemplo n.º 12
0
 public static void DrawBox(Rect area, float borderSize, Color borderColor, Color backgroundColor)
 {
     GUIEx.DrawBox(area, backgroundColor);
     GUIEx.DrawBorder(area, borderSize, borderColor);
 }
Exemplo n.º 13
0
 public static void DrawBox(Rect area, Color backgroundColor)
 {
     GUIEx.PushColor(backgroundColor);
     UnityEngine.GUI.DrawTexture(area, GUIEx.White);
     GUIEx.PopColor();
 }
Exemplo n.º 14
0
 public static void DrawBorder(Rect area, RectOffset border, Color color)
 {
     GUIEx.DrawBorder(area, border.left, border.right, border.top, border.bottom, color);
 }
Exemplo n.º 15
0
 public static void DrawBorder(Rect area, float border, Color color)
 {
     GUIEx.DrawBorder(area, border, border, border, border, color);
 }
Exemplo n.º 16
0
        public static void DrawSprite(Sprite sprite, params GUILayoutOption[] options)
        {
            Rect controlRect = GUILayoutUtility.GetRect(GUIContent.none, new GUIStyle(), options);

            GUIEx.DrawSprite(sprite, controlRect);
        }