当前位置:   article > 正文

Unity-编辑器拓展之GUILayout,EditorGUILayout布局 { }_unity guilayout

unity guilayout

Unity 脚本 API 中文版

链接: https://docs.unity3d.com/cn/2019.4/ScriptReference/

创建自定义窗口

public class MyWindow : EditorWindow//继承unity内置EditorWindow类
{
   
	[MenuItem("Window/我的自定义窗口")]
	private static void ShowWindow()
	{
   
		//1.用GetWindow方法创建的窗口,只可以打开一个
		MyWindow window = GetWindow<MyWindow>("我的窗口");//字符串为窗口标题
		//2.用CreateWindow方法创建的窗口,可以打开很多个
		MyWindow window = CreateWindow<MyWindow>("我的窗口");
	}
	private void OnGUI()
	{
   
		//GUI布局
	}
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

GUILayout.Label

基础

GUILayout.Label("Label");
  • 1

设置样式和大小

GUIStyle lblStyle = GUI.skin.label;//在unity默认的样式上面修改,如果使用new GUIStyle()的话,绘制出来的Label只有你自己设置的样式
lblStyle.alignment = TextAnchor.MiddleLeft;//
GUILayout.Label("Label", lblStyle, GUILayout.Width(50), GUILayout.Height(50));//必须指定大小,文字位置才有效
  • 1
  • 2
  • 3

使用 GUIContent 代替文字

//无提示写法
GUIContent lblIcon = EditorGUIUtility.IconContent("console.infoicon");//根据icon名字获取unity内置的icon
GUILayout.Label(lblIcon);
//有提示写法
//(1)图标的提示:要加 |
GUIContent lblIcon = EditorGUIUtility.IconContent("console.infoicon", "|这是图标Label"
  • 1
  • 2
  • 3
  • 4
  • 5
声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号