Unity3.5.7 GUI.skin vs GUIStyle

Hello,

I searched on forum and i found that the GUI.skin is not recommend because is to heavy and is better to use pre-defined gui styles that load once when script start.

I make a small test but i don’t found any difference.

Here is GUI.skin = someSkin;

Here is GUIStyle

Here is the code

using UnityEngine;
using System.Collections;

public class UIMainMenu : MonoBehaviour 
{
    public GUISkin gSkin;
    public Texture2D Background;

    Rect bgPos;

    void Start()
    {
		// The window will not be resized! (We calculate it once)
        bgPos = new Rect(Screen.width / 2 - Background.width / 2,
                         Screen.height / 2 - Background.height / 2,
                         Background.width,
                         Background.height);
    }

    void OnGUI()
    {
        GUI.skin = gSkin;
        
        GUI.BeginGroup(bgPos, Background);
        {
            GUI.Button(new Rect(244, 100, 152, 32), "Start Game");
            GUI.Button(new Rect(244, 150, 152, 32), "Game Options");
            GUI.Button(new Rect(244, 200, 152, 32), "About");
            GUI.Button(new Rect(244, 250, 152, 32), "Exit Game");
        }
        GUI.EndGroup();
    }
}

GUIStyle

using UnityEngine;
using System.Collections;

public class UIMainMenu : MonoBehaviour 
{
    public Texture2D Background;
    public Texture2D ButtonNormal;
    public Texture2D ButtonHover;
    public Font Font1;
    public Font Font2;

    private GUIStyle gStyle;
    private bool drawMainMenu = true;
    private Rect bgPos;

    void Start()
    {
        // Style Initialization
        gStyle = new GUIStyle();
        gStyle.normal.background = ButtonNormal;
        gStyle.hover.background = ButtonHover;
        gStyle.active.background = ButtonNormal;

        gStyle.normal.textColor = Color.white;
        gStyle.hover.textColor = Color.white;
        gStyle.active.textColor = Color.white;

        gStyle.alignment = TextAnchor.MiddleCenter;
        gStyle.padding.top = 1;
        gStyle.font = Font1;

        bgPos = new Rect (  Screen.width / 2 - Background.width / 2,
                            Screen.height / 2 - Background.height / 2,
                            Background.width,
                            Background.height   );
    }

    void OnGUI()
    {

        GUI.BeginGroup(bgPos, Background);
        {
            GUI.Button(new Rect(244, 100, 152, 32), "Start Game", gStyle);
            GUI.Button(new Rect(244, 150, 152, 32), "Game Options", gStyle);
            GUI.Button(new Rect(244, 200, 152, 32), "About", gStyle);
            GUI.Button(new Rect(244, 250, 152, 32), "Exit Game", gStyle);
        }
        GUI.EndGroup();

    }


}

That doesn’t really make any sense. (As you seem to have discovered.)

–Eric

Testing a single setter like that isn’t going to be very useful anyway, but I would have expected that when people say GUISkin is ‘heavy’ that they’re really talking about memory usage and ease-of-use rather than CPU time.

Well, what you suggest me?

I’m thinking to use GUI.skin and deactivate objects to have less Draw Calls.

About deactivation of objects, will this really help? or better to use boolean variables where i will allow drawing or not.

Example: I have a “Message Draw” script for my game, i always draw empty string and when i want to draw something i just change the text (yeap i know, bad tactic)

Sorry for my bad english.

Pay attention to what they’re called, it pretty much says it all.

A GUI style is the presentation data for a single type of widget within a GUI. Use this if you only want to have or store presentation data for one thing used in one place.

A GUI skin is a complete skin. It’s the entire set of styles used to skin all of a GUI. It is a collection of styles rather than a single style. Use this if you are storing presentation data for many things. It’s also stored as a resource, so it’s easier to re-use in multiple places.