前两篇分别讲解了创建菜单https://www.cnblogs.com/xiaoyulong/p/10115053.html和创建窗口https://www.cnblogs.com/xiaoyulong/p/10120565.html

这一篇我们讲解使用 GUI 来绘制我们的窗口,使窗口内容更丰富、美观

绘制窗口我们一般会使用下面四个类:GUI、GUILayout、EditorGUI、EditorGUILayout。

这四个类大同小异,基本上没什么差别,和我们经常使用的 UGUINGUI 相比,UGUI 和 NGUI 有图形化的操作,而这四个类是纯代码操作。

GUI、EditorGUI  GUILayout、EditorGUILayout 的区别是:前者是固定布局,布局需要我们写代码控制,后者是自动布局。

GUI、GUILayout EditorGUI、EditorGUILayout 的区别是:前者更多的用在平常调试中,后者在编辑器中使用。前者也可以使用在编辑器中。

其他的也不多说了,全是一些 API 的使用,下面我就用 EditorGUI 和 EditorGUILayout 写个小例子,给大家看一下

代码:

 using UnityEngine;
using UnityEditor; public class EditorGUILayoutTest : EditorWindow
{
private Vector3 startPoint;//起点
private Vector3 endPoint;//终点
private float distance = 0f;//起点到终点的距离 private bool val;
private Color color = Color.red; private AnimationCurve curveX = AnimationCurve.Linear(, , , );
private AnimationCurve curveY = AnimationCurve.Linear(, , , );
private AnimationCurve curveZ = AnimationCurve.Linear(, , , ); private int sliderValue = ;
private bool showClose = true;
private bool showToggleLeft = true;
private string textfieldtest = "textfieldtest";
private string password = "pwd123456"; private float minVal = -10.0f;
private float minLimit = -20.0f;
private float maxVal = 10.0f;
private float maxLimit = 20.0f; [MenuItem("MyWindow/WindowTest")]
private static void Init()
{
EditorGUILayoutTest window = (EditorGUILayoutTest)EditorWindow.GetWindow(typeof(EditorGUILayoutTest));
window.Show();
} private void OnGUI()
{
//Vector3类型数据的显示
startPoint = EditorGUILayout.Vector3Field("Start Point:", startPoint);
endPoint = EditorGUILayout.Vector3Field("End Point:", endPoint);
//只读的标签
EditorGUILayout.LabelField("Distance:", Vector3.Distance(startPoint, endPoint).ToString("f2"));
//勾选框
val = EditorGUILayout.Toggle("Can Jump", val);
//是否开启禁用功能。false表示禁用关闭,true表示开启禁用--灰色状态
EditorGUI.BeginDisabledGroup(val);//
//float类型文本Text
EditorGUILayout.FloatField("跳跃高度:", 100.0f);
//结束禁用
EditorGUI.EndDisabledGroup();
EditorGUILayout.FloatField("跳跃频率:", 1.85f);
//Bounds输入框
EditorGUILayout.BoundsField("BoundsField", new Bounds(new Vector3(, , ), new Vector3(, , )));
//颜色选择框
color = EditorGUILayout.ColorField("颜色:", color);
//按钮
if (GUILayout.Button("Close"))
{
this.Close();
}
//带有阴影的Label
EditorGUI.DropShadowLabel(new Rect(, , position.width, ), "带有阴影的Label");
//动画曲线
curveX = EditorGUI.CurveField(new Rect(, , position.width - , ), "Animation on X", curveX);
curveY = EditorGUI.CurveField(new Rect(, , position.width - , ), "Animation on Y", curveY);
curveZ = EditorGUI.CurveField(new Rect(, , position.width - , ), "Animation on Z", curveZ);
//数字输入
EditorGUI.DelayedDoubleField(new Rect(, , position.width - , ), "DelayedDoubleField1", 25.0);
EditorGUI.DelayedFloatField(new Rect(, , position.width - , ), "DelayedFloatField", 25.0f);
EditorGUI.DelayedIntField(new Rect(, , position.width - , ), "DelayedIntField", );
EditorGUI.DelayedTextField(new Rect(, , position.width - , ), "DelayedTextField");
//绘画矩形
EditorGUI.DrawRect(new Rect(, , position.width - , ), Color.green);
//滑动条。输入框(值不能滑动): 注意左边必须要有值接收这个值,否则不能滑动
sliderValue = EditorGUI.IntSlider(new Rect(, , position.width - , ), sliderValue, , );
//帮助盒子信息框
EditorGUI.HelpBox(new Rect(, , position.width - , ), "HelpBox帮助盒子", MessageType.Info);
//Toggle 开关
showClose = EditorGUI.Toggle(new Rect(, , position.width - , ), "Toggle", showClose);
showToggleLeft = EditorGUI.ToggleLeft(new Rect(, , position.width - , ), "ToggleLeft", showToggleLeft);
textfieldtest = EditorGUI.TextField(new Rect(, , position.width - , ), "TextField", textfieldtest);
password = EditorGUI.PasswordField(new Rect(, , position.width - , ), "密码框:", password);
//最大值和最小值滑块
EditorGUI.MinMaxSlider(new Rect(, , position.width - , ), ref minVal, ref maxVal, minLimit, maxLimit);
} private void OnInspectorUpdate()
{
this.Repaint();
}
}

效果图:

Unity3D编辑器扩展(三)——使用GUI绘制窗口的更多相关文章

  1. Unity3D编辑器扩展(六)——模态窗口

    前面我们已经写了5篇关于编辑器的,这是第六篇,也是最后一篇: Unity3D编辑器扩展(一)——定义自己的菜单按钮 Unity3D编辑器扩展(二)——定义自己的窗口 Unity3D编辑器扩展(三)—— ...

  2. Unity3D编辑器扩展(五)——常用特性(Attribute)以及Selection类

    前面写了四篇关于编辑器的: Unity3D编辑器扩展(一)——定义自己的菜单按钮 Unity3D编辑器扩展(二)——定义自己的窗口 Unity3D编辑器扩展(三)——使用GUI绘制窗口 Unity3D ...

  3. Unity3D编辑器扩展(四)——扩展自己的组件

    前面已经写了三篇: Unity3D编辑器扩展(一)——定义自己的菜单按钮 Unity3D编辑器扩展(二)——定义自己的窗口 Unity3D编辑器扩展(三)——使用GUI绘制窗口 今天写第四篇,扩展自己 ...

  4. Unity3D编辑器扩展(二)——定义自己的窗口

    上一篇我们讲了如何定义菜单按钮 https://www.cnblogs.com/xiaoyulong/p/10115053.html 这一篇我们讲如何定义自己的窗口. 定义窗口我们需要继承 Edito ...

  5. unity3D编辑器扩展

    编辑器扩展只是在编辑项目中运行,发布出来是不会运行的. 固定创建一个文件夹Editor:所有的资源或者代码都不会被打包进去. 01.使用MenuItem添加菜单栏按钮 脚本不需要作为组件存在,可以不用 ...

  6. Unity3d编辑器扩展学习笔记

    编辑器扩展 1.添加菜单栏:把特性应用于静态方法 参数1:菜单名的空格后面是定义快捷键(单符号得用"_"开头,组合键%=Ctrl,#=Shift,&=Alt) 参数2:通过 ...

  7. Unity3D编辑器扩展(一)——定义自己的菜单按钮

    Unity3D 引擎的编辑器拥有很强的扩展性,用的好可以帮我们省很多事情.在这里记录下如何去扩展 Unity3D 的编辑器,定制属于我们自己的开发环境. 本篇主要讲解在 Unity3D 引擎的各个窗口 ...

  8. unity编辑器扩展_08(创建自定义窗口)

    代码: using UnityEngine;using UnityEditor; public class MyWidow : EditorWindow{    [MenuItem("Win ...

  9. [Unity3D]编辑器扩展之数组或List显示

    效果如下: 源码如下: using System.Collections.Generic; using UnityEditor; using UnityEngine; namespace XM.Edi ...

随机推荐

  1. phxpaxos实现状态机CAS操作

    看过了phxpaxos的实现,发现选主逻辑中非主也能够调用Propose.因此即使开启了选主功能,也可能会出现两个人同时Propose的场景.而Propose时,InstanceID只是作为输出而非输 ...

  2. ElasticSearch 2.X升级到6.X遇到的几个问题

    1.IndexExists检测索引是否存在,更简洁了,可以这样 _ElasticClient.IndexExists(indices : indexName).Exists 2.索引数据的时候,如果数 ...

  3. 简单搭建一个SpringBoot

    1.SpringBoot下载 https://start.spring.io/ 选择工程类型,编译语言,版本,工程名称,需要支持组件等:选择好了以后点击生成项目. 之后会下载一个压缩文件,解压之后导入 ...

  4. springMVC设计模式和javaWeb三层框架

    一.springMVC  设计模式 MVC模式是软件工程中的一种能够软件架构模式,把软件分为三个基本部分,模型(model).视图(view)和控制器(controller).使程序简化,更加直观. ...

  5. [Solution] 821. Shortest Distance to a Character

    Difficulty: Easy Problem Given a string S and a character C, return an array of integers representin ...

  6. innodb_flush_log_at_trx_commit与sync_binlog理解

    innodb_flush_log_at_trx_commit该参数控制重做日志写入磁盘的过程.我们知道 InnoDB 使用“Write Ahead Log”策略来避免数据丢失问题,即依靠重做日志来保证 ...

  7. python的单元测试unittest模块

    首先需要导入unittest模块 import unittest import  HTMLTestRunner # TestCase 也就是测试用例## TestSuite 多个测试用例集合在一起,就 ...

  8. centos7 使用ss和Privoxy 实现命令行访问google

    1.更新yum 这里可能更新时间有点长,,稳住~别急 yum -y upgrade 2.安装 epel-release 这个必须先安装,因为: python-pip 和 privoxy 都在EPEL源 ...

  9. angular 键盘事件绑定与过滤

    方便的angular按钮绑定 如 <input (keyup.enter)="keyUpSearch($event)" value="按下回车键触发"&g ...

  10. dskinlite(uieasy mfc界面库)使用记录2:绘制动态元素(按钮控件绘制元素动态控制,改变图片和文字)

    效果图:这4个分别是按钮按下后4种状态的效果 第88行是显示默认的按钮文字,没有id,SetWindowText改的就是它了 第87行是左边的图片,id是ico,可以通过程序控制 第89行是蓝色的文字 ...