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();
}
}