前言
合理使用GUIStyle可以让自定义编辑器界面更加精致美观。
而GUISkin是用于本地化储存GUIStyle的,方便使用。
GUIStyle
代码示例
private GUIStyle _tabStyle;
_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.grey; //默认状态下字体颜色
_tabStyle.onNormal.background = tabSelected;
_tabStyle.onNormal.textColor = Color.black;
_tabStyle.onFocused.background = tabSelected; //选中状态下背景
_tabStyle.onFocused.textColor = Color.black; //选中状态下字体颜色
_tabStyle.border = new RectOffset(18,18,20,4); //设置边界防止图片变形(九宫格)
index = GUILayout.Toolbar(index, _categoryLabels.ToArray(), _tabStyle);
加载的资源
效果图
GUISkin
现在我们知道GUIStyle的大致用法和效果了,而GUISkin就是方便我们使用保存GUIStyle的ScriptObject格式文件。
里面保存了GUIStyle的可调整属性。
使用方法
GUISkin skin = Resources.Load<GUISkin>("LevelCreatorSkin");
_titleStyle = skin.label;
版权声明:本文为qq_39162826原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。