当前位置:   article > 正文

【Unity编辑器扩展基础】、EditorGUILayout(二)_unity guilayout 分割线

unity guilayout 分割线

小结: 

1、类似BeginFadeGroup、BeginHorizontal布局函数都有与之对应的EndFadeGroup、EndHorizontal,他们是一一对应的;

2、创建ToggleGroup,关闭之后该ToggleGroup下的内容都不能在该组下面修改。

3、BeginScrollView返回值是该滑动区域的位置,需要将它存下来,才能改变BeginScrollView的位置。

  1. using UnityEngine;
  2. using UnityEditor;
  3. using UnityEditor.AnimatedValues;
  4. /// <summary>
  5. /// Unity 5.6
  6. /// </summary>
  7. public class EditorGUILayoutExample : EditorWindow
  8. {
  9. #region BeginFadeGroup
  10. AnimBool m_ShowExtraFields;
  11. string m_String;
  12. Color m_Color = Color.white;
  13. int m_Number = 0;
  14. #endregion
  15. #region BeginScrollView
  16. Vector2 scrollPos;
  17. string m_content = "";
  18. string t = "这 是 一 个 测 试 Scroll view 的 文 本 !\n";
  19. #endregion
  20. #region BeginToggleGroup
  21. bool[] pos = new bool[3] { true, true, true };
  22. bool posGroupEnabled = true;
  23. #endregion
  24. #region Foldout
  25. bool showFoldout = true;
  26. #endregion
  27. [MenuItem("EditorGUILayout/EditorGUILayoutExample")]
  28. static void Init()
  29. {
  30. EditorGUILayoutExample window = (EditorGUILayoutExample)EditorWindow.GetWindow(typeof(EditorGUILayoutExample));
  31. window.Show();
  32. }
  33. void OnEnable()
  34. {
  35. #region BeginFadeGroup
  36. m_ShowExtraFields = new AnimBool(true);//创建一个AnimBool对象,true是默认显示。
  37. m_ShowExtraFields.valueChanged.AddListener(Repaint);//监听重绘
  38. #endregion
  39. }
  40. void OnGUI()
  41. {
  42. #region BeginFadeGroup
  43. m_ShowExtraFields.target = EditorGUILayout.ToggleLeft("显示折叠内容", m_ShowExtraFields.target);//选择框在左边的开关
  44. m_ShowExtraFields.target = EditorGUILayout.Toggle("显示折叠内容", m_ShowExtraFields.target);//选择框在右边的开关
  45. //创建带渐显动画的折叠块 返回值bool,参数float
  46. if (EditorGUILayout.BeginFadeGroup(m_ShowExtraFields.faded))
  47. {
  48. EditorGUI.indentLevel++;//缩进深度增加,以下的GUI会增加缩进
  49. EditorGUILayout.LabelField("ColorColorColorColorColorColorColorColorColorColor");//标签栏
  50. EditorGUILayout.PrefixLabel("ColorColorColorColorColorColorColorColorColorColor");//前缀标签
  51. m_Color = EditorGUILayout.ColorField(m_Color);
  52. EditorGUILayout.PrefixLabel("Text");
  53. m_String = EditorGUILayout.TextField(m_String);//文本框
  54. EditorGUILayout.PrefixLabel("Number");
  55. m_Number = EditorGUILayout.IntSlider(m_Number, 0, 10);//Int滑动条
  56. EditorGUI.indentLevel--;//缩进深度减少,以下的GUI会减少缩进
  57. }
  58. EditorGUILayout.EndFadeGroup();
  59. #endregion
  60. #region Foldout
  61. showFoldout = EditorGUILayout.Foldout(showFoldout, "折叠子物体:");
  62. if (showFoldout)
  63. {
  64. EditorGUI.indentLevel++;
  65. EditorGUILayout.LabelField("折叠块内容1");
  66. EditorGUI.indentLevel++;
  67. EditorGUILayout.LabelField("折叠块内容2");
  68. EditorGUI.indentLevel--;
  69. EditorGUI.indentLevel--;
  70. EditorGUILayout.LabelField("折叠块内容3");
  71. }
  72. #endregion
  73. #region BeginHorizontal 水平布局
  74. Rect r = EditorGUILayout.BeginHorizontal("Button");
  75. if (GUI.Button(r, GUIContent.none))
  76. Debug.Log("Go here");
  77. GUILayout.Label("I'm inside the button");
  78. GUILayout.Label("So am I");
  79. EditorGUILayout.EndHorizontal();
  80. EditorGUILayout.BeginHorizontal();
  81. GUILayout.Label("第一个内容");
  82. GUILayout.Label("第二个内容");
  83. if (GUILayout.Button("第三个按钮"))
  84. {
  85. Debug.Log("GUILayout的按钮");
  86. }
  87. EditorGUILayout.EndHorizontal();
  88. #endregion
  89. #region BeginVertical 垂直布局
  90. EditorGUILayout.BeginVertical();
  91. GUILayout.Label("第一个内容");
  92. GUILayout.Label("第二个内容");
  93. if (GUILayout.Button("第三个按钮"))
  94. {
  95. Debug.Log("GUILayout的按钮");
  96. }
  97. EditorGUILayout.EndVertical();
  98. #endregion
  99. #region BeginScrollView
  100. //需要将返回值赋值到临时变量,不然拖不动
  101. //可以添加GUILayoutOption参数控制大小
  102. scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Width(200), GUILayout.Height(100));
  103. GUILayout.Label(m_content);
  104. EditorGUILayout.EndScrollView();
  105. EditorGUILayout.BeginHorizontal();
  106. if (GUILayout.Button("添加内容"))
  107. m_content += t;
  108. if (GUILayout.Button("清空内容"))
  109. m_content = "";
  110. EditorGUILayout.EndHorizontal();
  111. #endregion
  112. #region BeginToggleGroup
  113. posGroupEnabled = EditorGUILayout.BeginToggleGroup("ToggleGroup", posGroupEnabled);
  114. EditorGUILayout.BeginVertical();
  115. pos[0] = EditorGUILayout.Toggle("Toggle1", pos[0]);
  116. pos[1] = EditorGUILayout.Toggle("Toggle2", pos[1]);
  117. pos[2] = EditorGUILayout.Toggle("Toggle3", pos[2]);
  118. if (GUILayout.Button("添加内容"))
  119. m_content += t;
  120. m_String = EditorGUILayout.TextField(m_String);
  121. EditorGUILayout.EndVertical();
  122. EditorGUILayout.EndToggleGroup();
  123. #endregion
  124. //画一个居中的分割线
  125. EditorGUILayout.BeginHorizontal();
  126. GUILayout.FlexibleSpace();
  127. GUILayout.Label("-----------------分割线-----------------");
  128. GUILayout.FlexibleSpace();
  129. EditorGUILayout.EndHorizontal();
  130. }
  131. }

 以上就是EditorGUILayout中各种布局函的的用法了。

效果图:

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/92933
推荐阅读
相关标签
  

闽ICP备14008679号