Unity Editor knowledge point finishing (GUI appearance GUIStyle and GUISkin)

GUIStyle
customizes the style of a control in the GUI

private GUIStyle _titleStyle;

//初始化GUI Style
private void InitStyles()
{
    
    
    _titleStyle = new GUIStyle();
    //对齐方式居中
    _titleStyle.alignment = TextAnchor.MiddleCenter;
    //字体大小
    _titleStyle.fontSize = 16;
}

For textures set its type to EditorGUI
insert image description here

//初始化GUI Style
private void InitStyles()
{
    
    
    _titleStyle = new GUIStyle();
    //对齐方式居中
    _titleStyle.alignment = TextAnchor.MiddleCenter;
    //字体大小
    _titleStyle.fontSize = 16;
    //背景图
    Texture2D titleBg = Resources.Load<Texture2D>("Color_Bg");
    //字体
    Font titleFont = Resources.Load<Font>("Oswald-Regular");

    //文本只有normal状态
    _titleStyle.normal.background = titleBg;
    _titleStyle.normal.textColor = Color.white;
    _titleStyle.font = titleFont;
}

Set the tab style

private GUIStyle _tabStyle;

//初始化 调色板页签样式
private void InitStyles()
{
    
    
    _tabStyle = new GUIStyle();
    //对齐方式居中
    _tabStyle.alignment = TextAnchor.MiddleCenter;
    //字体大小
    _tabStyle.fontSize = 16;

    //页签状态
    Texture2D tabNormal = Resources.Load<Texture2D>("Tab_Normal");
    Texture2D tabSelected = Resources.Load<Texture2D>("Tab_Selected");
   
    //字体
    Font tabFont = Resources.Load<Font>("Oswald-Regular");

    //字体
    _tabStyle.font = tabFont;
    //高度
    _tabStyle.fixedHeight = 40;

    //未选中状态 
    _tabStyle.normal.background = tabNormal;
    _tabStyle.normal.textColor = Color.gray;
    //选中状态
    _tabStyle.onNormal.background = tabSelected;
    _tabStyle.onNormal.textColor = Color.black;
    _tabStyle.onFocused.background = tabSelected;
    _tabStyle.onFocused.textColor = Color.black;

	//设置border 分割出九个区域 定义可拉伸区域
    _tabStyle.border = new RectOffset(18,18,20,4);
}

When creating a tab, pass in the style

 index = GUILayout.Toolbar(index, _CategoryLabels.ToArray(),_tabStyle);

GUISkin
Because GUI Style is only applicable to a single space, in order to solve the need for many styles, or to reuse a written style, you can use GUISkin

GUISkin is a resource that needs to be created
insert image description here

Set the label property in GUISkin
insert image description here

//初始化GUI Skin
        private void InitStylesSkin()
        {
    
    
            GUISkin skin = Resources.Load<GUISkin>("LevelCreatorSkin");
            _titleStyle = skin.label;
        }

Guess you like

Origin blog.csdn.net/qq_43388137/article/details/122299065