Exemple #1
0
        public void Button(string buttonText, string tooltipDescription, SwatDelegate invoker, GUIStyle style = null, params GUILayoutOption[] options)
        {
            if (style == null)
            {
                style = new GUIStyle(GUI.skin.button);
                style.normal.textColor = Swat.WindowDefaultTextColor;
            }

            if (DefaultButtonTexture == style.normal.background)
            {
                style.normal.background = TabButtonBackgroundTexture;
            }

            if (GUILayout.Button(buttonText, style, options))
            {
                invoker.Invoke();
            }

            if (!string.IsNullOrEmpty(tooltipDescription))
            {
                if (MouseOver())
                {
                    SetToolTip(tooltipDescription, _tabsOffsetY);
                }
            }
        }
Exemple #2
0
        public void ToggleButton(bool isToggledOn, string buttonText, string tooltipDescription, SwatDelegate invoker, int buttonWidth = 175, int statusTextAreaWidth = 55, RectOffset offset = null, string[] onOffText = null, bool invertBooleanColorIndication = false)
        {
            GUIStyle style = new GUIStyle(GUI.skin.button);

            style.padding           = offset == null ? new RectOffset(10, 0, 0, 0) : offset;
            style.normal.background = Swat.ActionButtonTexture;
            style.normal.textColor  = Swat.ActionButtonTextColor;
            style.fixedHeight       = 35;
            style.fixedWidth        = buttonWidth;
            style.fontSize          = 14;

            if (DefaultButtonTexture == style.normal.background)
            {
                style.normal.background = TabButtonBackgroundTexture;
            }

            GUIStyle text = new GUIStyle(GUI.skin.label);

            text.fontStyle        = FontStyle.Bold;
            text.normal.textColor = Color.white;

            GUIStyle activeness = new GUIStyle(GUI.skin.box);

            if (style.fixedHeight > 0)
            {
                text.fontSize    = (int)(style.fixedHeight / 1.75f);
                text.fixedHeight = style.fixedHeight;
            }
            int paddingTopBottom = (int)((style.fixedHeight - text.fontSize) / 2 - 1);

            text.padding = new RectOffset(5, 5, paddingTopBottom, paddingTopBottom);

            if (style.fixedWidth > 0)
            {
                activeness.fixedWidth = style.fixedWidth + statusTextAreaWidth;
            }
            activeness.normal.background = MakeTextureFromColor((invertBooleanColorIndication ? !isToggledOn : isToggledOn) ? (Color) new Color32(0, 135, 0, 255) : (Color) new Color32(135, 0, 0, 255));

            EditorGUILayout.BeginHorizontal(activeness);
            GUILayout.Space(-0.25f);
            if (GUILayout.Button(buttonText, style))
            {
                invoker.Invoke();
            }
            string[] textAlts = onOffText == null ? new string[] { "On", "Off" } : onOffText;
            EditorGUILayout.LabelField((invertBooleanColorIndication ? !isToggledOn : isToggledOn) ? textAlts[0] : textAlts[1], text);
            EditorGUILayout.EndHorizontal();

            if (!string.IsNullOrEmpty(tooltipDescription))
            {
                if (MouseOver())
                {
                    SetToolTip(tooltipDescription, _tabsOffsetY);
                }
            }
        }