当前位置:   article > 正文

Unity编辑器扩展: GUILayout、EditorGUILayout 控件整理_editorguilayout.popup

editorguilayout.popup

GUILayout

GUILayoutOption

基本每个控件方法都有一个可选参数是GUILayoutOption[] Options 这是一个可以控制组件大小之类的选项,在GUILayout类中共有8个。

GUILayout.Height()                GUILayout.Width()

GUILayout.MaxHeight()         GUILayout.MaxWidth()

GUILayout.MinHeight()          GUILayout.MinWidth()

GUILayout.ExpandHeight()   GUILayout.ExpandWidth()
 

Box

GUILayout.Box(new GUIContent("一个200x200的BOX"),new []{GUILayout.Height(200),GUILayout.Width(200)});

滚/滑动类控件

num = EditorGUILayout.Slider ("Slider", num, -3, 3);

  1. scrollBarValue1 = GUILayout.HorizontalScrollbar(scrollBarValue1,0,0,100,new[]{GUILayout.Width(100)});
  2. scrollBarValue2 = GUILayout.VerticalScrollbar(scrollBarValue2,0,0,100,new[]{GUILayout.Height(100)});

 

  1. scrollValue1=GUILayout.HorizontalSlider(scrollValue1, 0, 100);
  2. scrollValue2=GUILayout.VerticalSlider(scrollValue2, 0, 100);

按钮类控件 

gridId = GUILayout.SelectionGrid(gridId, new[] {"1", "2", "3","4","5","6"}, 4);

toolbarid=GUILayout.Toolbar(toolbarid, new[] {"1", "2", "3"});

Field类控件

  1. GUILayout.TextField("TextField只能一行");
  2. GUILayout.TextArea("TextArea可以多行\n 第二行");

password = GUILayout.PasswordField(password, '*');

区块布局类控件

  1. //保证块里写的控件只在Area规定的范围内,这里设置放到右下角
  2. GUILayout.BeginArea(new Rect(position.width-250,position.height-150,250,150));
  3. //...
  4. GUILayout.EndArea();
  5. GUILayout.BeginHorizontal();
  6. //...水平布局
  7. GUILayout.EndHorizontal();
  8. GUILayout.BeginVertical();
  9. //...垂直布局
  10. GUILayout.EndVertical();
  11. //显示的范围不够块内控件时可以滑动 这里限制高度75最多同时显示3
  12. scrollPos=GUILayout.BeginScrollView(scrollPos,false,true,GUILayout.Height(75));
  13. //...
  14. GUILayout.EndScrollView();

 

  1. groupEnabled = EditorGUILayout.BeginToggleGroup ("ToogleGroup",groupEnabled);
  2. //...
  3. EditorGUILayout.EndToggleGroup ();

EditorGUILayout

Slider类控件

  1. //可以选择一个最大最小的范围的slider
  2. EditorGUILayout.MinMaxSlider("MinMaxSlider",ref sliderValue2,ref sliderValue3,10,20);
  3. //int类型的slider
  4. intSliderValue=EditorGUILayout.IntSlider(intSliderValue,0,10);
  5. //和guilayout重复的
  6. sliderValue=EditorGUILayout.Slider(sliderValue,0f,1);

弹选框类控件

  1. //这个可以多选 需要枚举类型
  2. flagtype=(flagTestType)EditorGUILayout.EnumFlagsField(flagtype);

 

  1. //这个单选 需要枚举类型
  2. popuptype=(popupTestType)EditorGUILayout.EnumPopup(popuptype);

  1. //一个选择框,每个选择框里表示一个Int数
  2. popupindex=EditorGUILayout.IntPopup("IntPopup", popupindex, new[] {"a", "b"}, new[] {1, 2});

  1. //和IntPopup类似但是可以多选
  2. maskindex=EditorGUILayout.MaskField("Mask",maskindex,new []{"a","b"});

Field类控件

  1. i1=EditorGUILayout.IntField("IntField",i1,GUILayout.Width(100));
  2. d1=EditorGUILayout.DoubleField("DoubleField",d1,GUILayout.Width(100));
  3. //bounds类型输入框 反正就两个三维向量
  4. boundsv=EditorGUILayout.BoundsField("BoundsField",boundsv);
  5. boundintv=EditorGUILayout.BoundsIntField("BoundsIntField",boundintv);
  6. //层级和标签\物体选择,就是unity中的各种layer tag gameboject
  7. EditorGUILayout.LayerField("LayerField", 1);
  8. EditorGUILayout.TagField("TagField", "一个tag");
  9. EditorGUILayout.ObjectField("ObjectField",GameObject.Find("Cube"), typeof(GameObject),true);
  10. //显示序列化属性字段 比如之前的自定义特性里的
  11. EditorGUILayout.PropertyField(p)
  12. EditorGUILayout.RectField(new Rect());
  13. EditorGUILayout.RectIntField(new RectInt());
  14. //delay和一般的区别是只有按下回车或者失去焦点时,才会返回值,就是说你再输入时不会返回
  15. //Note that the return value will not change until the user has pressed enter or focus is moved away from the text field.
  16. delayint=EditorGUILayout.DelayedIntField("DelayedInt",delayint);
  17. delayfloat=EditorGUILayout.DelayedFloatField("DelayedFloat",delayfloat);
  18. delaydouble=EditorGUILayout.DelayedDoubleField("DelayedDouble",delaydouble);
  19. delaystr=EditorGUILayout.DelayedTextField("DelayedTextField",delaystr);
  20. colorv=EditorGUILayout.ColorField("颜色框", colorv);
  21. acurev=EditorGUILayout.CurveField("曲线", acurev);
  22. //还有这几个向量
  23. //EditorGUILayout.Vector2Field();
  24. //EditorGUILayout.Vector2IntField();
  25. //EditorGUILayout.Vector3Field();
  26. //EditorGUILayout.Vector3IntField();
  27. //EditorGUILayout.Vector4Field()

 

 

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

闽ICP备14008679号