Exemplo n.º 1
0
        public static int Toolbar(int selected, GUIContent[] contents, GUIStyle style, GUI.ToolbarButtonSize buttonSize, params GUILayoutOption[] options)
        {
            GUIStyle gUIStyle;
            GUIStyle gUIStyle2;
            GUIStyle gUIStyle3;

            GUI.FindStyles(ref style, out gUIStyle, out gUIStyle2, out gUIStyle3, "left", "mid", "right");
            Vector2  vector    = default(Vector2);
            int      num       = contents.Length;
            GUIStyle gUIStyle4 = (num <= 1) ? style : gUIStyle;
            GUIStyle gUIStyle5 = (num <= 1) ? style : gUIStyle2;
            GUIStyle gUIStyle6 = (num <= 1) ? style : gUIStyle3;
            float    num2      = 0f;

            for (int i = 0; i < contents.Length; i++)
            {
                if (i == num - 2)
                {
                    gUIStyle5 = gUIStyle6;
                }
                Vector2 vector2 = gUIStyle4.CalcSize(contents[i]);
                if (buttonSize != GUI.ToolbarButtonSize.Fixed)
                {
                    if (buttonSize == GUI.ToolbarButtonSize.FitToContents)
                    {
                        vector.x += vector2.x;
                    }
                }
                else if (vector2.x > vector.x)
                {
                    vector.x = vector2.x;
                }
                if (vector2.y > vector.y)
                {
                    vector.y = vector2.y;
                }
                if (i == num - 1)
                {
                    num2 += (float)gUIStyle4.margin.right;
                }
                else
                {
                    num2 += (float)Mathf.Max(gUIStyle4.margin.right, gUIStyle5.margin.left);
                }
                gUIStyle4 = gUIStyle5;
            }
            if (buttonSize != GUI.ToolbarButtonSize.Fixed)
            {
                if (buttonSize == GUI.ToolbarButtonSize.FitToContents)
                {
                    vector.x += num2;
                }
            }
            else
            {
                vector.x = vector.x * (float)contents.Length + num2;
            }
            return(GUI.Toolbar(GUILayoutUtility.GetRect(vector.x, vector.y, style, options), selected, contents, style, buttonSize));
        }
Exemplo n.º 2
0
        public static int Toolbar(int selected, GUIContent[] contents, GUIStyle style, params GUILayoutOption[] options)
        {
            GUIStyle style2;
            GUIStyle style3;
            GUIStyle style4;

            GUI.FindStyles(ref style, out style2, out style3, out style4, "left", "mid", "right");
            Vector2  vector = new Vector2();
            int      length = contents.Length;
            GUIStyle style5 = (length <= 1) ? style : style2;
            GUIStyle style6 = (length <= 1) ? style : style3;
            GUIStyle style7 = (length <= 1) ? style : style4;
            int      left   = style5.margin.left;

            for (int i = 0; i < contents.Length; i++)
            {
                if (i == (length - 2))
                {
                    style5 = style6;
                    style6 = style7;
                }
                if (i == (length - 1))
                {
                    style5 = style7;
                }
                Vector2 vector2 = style5.CalcSize(contents[i]);
                if (vector2.x > vector.x)
                {
                    vector.x = vector2.x;
                }
                if (vector2.y > vector.y)
                {
                    vector.y = vector2.y;
                }
                if (i == (length - 1))
                {
                    left += style5.margin.right;
                }
                else
                {
                    left += Mathf.Max(style5.margin.right, style6.margin.left);
                }
            }
            vector.x = (vector.x * contents.Length) + left;
            return(GUI.Toolbar(GUILayoutUtility.GetRect(vector.x, vector.y, style, options), selected, contents, style));
        }
Exemplo n.º 3
0
        public static int Toolbar(int selected, GUIContent[] contents, bool[] enabled, GUIStyle style, GUI.ToolbarButtonSize buttonSize, params GUILayoutOption[] options)
        {
            GUIStyle firstStyle, midStyle, lastStyle;

            GUI.FindStyles(ref style, out firstStyle, out midStyle, out lastStyle, "left", "mid", "right");

            Vector2  size         = new Vector2();
            int      count        = contents.Length;
            GUIStyle currentStyle = count > 1 ? firstStyle : style;
            GUIStyle nextStyle    = count > 1 ? midStyle : style;
            GUIStyle endStyle     = count > 1 ? lastStyle : style;
            float    margins      = 0;

            for (int i = 0; i < contents.Length; i++)
            {
                if (i == count - 2)
                {
                    nextStyle = endStyle;
                }

                Vector2 thisSize = currentStyle.CalcSize(contents[i]);
                switch (buttonSize)
                {
                case GUI.ToolbarButtonSize.Fixed:
                    if (thisSize.x > size.x)
                    {
                        size.x = thisSize.x;
                    }
                    break;

                case GUI.ToolbarButtonSize.FitToContents:
                    size.x += thisSize.x;
                    break;
                }

                if (thisSize.y > size.y)
                {
                    size.y = thisSize.y;
                }

                // add spacing
                if (i == count - 1)
                {
                    margins += currentStyle.margin.right;
                }
                else
                {
                    margins += Mathf.Max(currentStyle.margin.right, nextStyle.margin.left);
                }

                currentStyle = nextStyle;
            }

            switch (buttonSize)
            {
            case GUI.ToolbarButtonSize.Fixed:
                size.x = size.x * contents.Length + margins;
                break;

            case GUI.ToolbarButtonSize.FitToContents:
                size.x += margins;
                break;
            }

            return(GUI.Toolbar(GUILayoutUtility.GetRect(size.x, size.y, style, options), selected, contents, null, style, buttonSize, enabled));
        }