当前位置:网站首页>【Unity编辑器扩展基础】、GUI
【Unity编辑器扩展基础】、GUI
2022-06-28 12:00:00 【Unique_849997563】
一、静态属性
1、颜色
改变背景颜色:GUI.backgroundColor
改变内容颜色: GUI.contentColor
改变内容改变内容和背景颜色: GUI.color
//改变背景颜色
GUI.backgroundColor = Color.yellow;
GUI.Button(new Rect(0, 0, 200, 30), "改变背景颜色");
GUI.backgroundColor = Color.white;
GUI.Button(new Rect(0, m_interval, 200, 30), "改变背景颜色");
//改变内容颜色
GUI.contentColor = Color.yellow;
GUI.Button(new Rect(0, m_interval * 2, 200, 30), "改变内容颜色");
GUI.contentColor = Color.white;
GUI.Button(new Rect(0, m_interval * 3, 200, 30), "改变内容颜色");
//改变内容和背景颜色
GUI.color = Color.yellow;
GUI.Button(new Rect(0, m_interval * 4, 200, 30), "改变内容和背景颜色");
GUI.color = Color.white;
GUI.Button(new Rect(0, m_interval * 5, 200, 30), "改变内容和背景颜色");
2、文本输入框:GUI.TextField
GUI.changed:如果有输入控件的值发生改变,就会返回true。
stringToEdit = GUI.TextField(new Rect(0, m_interval * 6, 200, 20), stringToEdit, 25);
if (GUI.changed)
Debug.Log("GUI.TextField 内容有修改");3、 GUI的激活状态:GUI.enabled
GUI.enabled控制之后的GUI的激活状态,未激活的GUI不能接收事件。
toggleGroup = GUI.Toggle(new Rect(0, m_interval * 7, 200, 20), toggleGroup, "ToggleGroup");
GUI.enabled = toggleGroup;
if (GUI.Button(new Rect(0, m_interval * 8, 200, 30), "测试toggleGroup的按钮1"))
{
Debug.Log("点击了button1");
}
if (GUI.Button(new Rect(0, m_interval * 9, 200, 30), "测试toggleGroup的按钮2"))
{
Debug.Log("点击了button2");
}
4、GUI.depth
5、GUI.matrix
6、GUI.skin
二、静态方法
1、GUI.Label
GUI.Label(new Rect(210, 10, 100, 20), "Hello World!");2、 GUI.Box
GUI.Box(new Rect(210, 50, 50, 50), "A BOX");3、GUI.Button
if (GUI.Button(new Rect(210, 110, 70, 30), "A button"))
Debug.Log("点击了按钮!");4、 GUI.BeginGroup
m_beginGroupRect = new Rect(0, 0, Screen.width / 2, Screen.height / 2);
//BeginGroup 可以用来管理UI,UGUI的Panel,组里面的UI元素是相对于组创建的。
GUI.BeginGroup(m_beginGroupRect);
GUI.Box(new Rect(m_beginGroupRect), "自适应的 BeginGroup 测试!");
GUI.EndGroup();5、GUI.BeginScrollView
//滑动区域
scrollPosition = GUI.BeginScrollView(new Rect(10, 10, 200, 200), scrollPosition, new Rect(0, 0, 220, 200));
GUI.Button(new Rect(0, 0, 100, 20), "Top-left");
GUI.Button(new Rect(120, 0, 100, 20), "Top-right");
GUI.Button(new Rect(0, 180, 100, 20), "Bottom-left");
GUI.Button(new Rect(120, 180, 100, 20), "Bottom-right");
GUI.EndScrollView();
6、 GUI.DrawTexture、GUI.DrawTextureWithTexCoords
//画一个图片
if (aTexture)
{
GUI.DrawTexture(new Rect(10, 110, 110, 110), aTexture, ScaleMode.StretchToFill, true, 10.0F);
GUI.DrawTextureWithTexCoords(new Rect(10, 240, 110, 110), aTexture, new Rect(10, 240, 110, 110), false);
}7、 GUI.SetNextControlName
为下一个控件设置控件名称。
8、 GUI.FocusControl
通过控件名称设置聚焦,设置聚焦时参数为控件名称,取消聚焦时参数为null。(EditorGUILayout.TextField 控件如果被聚焦,返回的值修改之后,不会马上刷新,需要取消聚焦才能看到刷新之后的值。)
GUI.SetNextControlName("MyTextField");
username = GUI.TextField(new Rect(10, 410, 100, 20), username);
pwd = GUI.TextField(new Rect(10, 440, 100, 20), pwd);
if (GUI.Button(new Rect(10, 470, 80, 20), "设置聚焦"))
GUI.FocusControl("MyTextField");
if (GUI.Button(new Rect(10, 500, 80, 20), "取消聚焦"))
GUI.FocusControl(null);//取消聚焦9、GUI.HorizontalSlider、GUI.VerticalSlider、GUI.HorizontalScrollbar、GUI.VerticalScrollbar
hSliderValue = GUI.HorizontalSlider(new Rect(210, 150, 100, 30), hSliderValue, 0.0F, 10.0F);
vSliderValue = GUI.VerticalSlider(new Rect(210, 170, 100, 30), vSliderValue, 10.0F, 0.0F);
hSValue = GUI.HorizontalScrollbar(new Rect(210, 210, 100, 30), hSValue, 1.0F, 0.0F, 10.0F);
vSValue = GUI.VerticalScrollbar(new Rect(210, 230, 100, 30), vSValue, 1.0F, 10.0F, 0.0F);10、GUI.GetNameOfFocusedControl
获取当前聚焦的控件名称,如果没有聚焦或者没有控件命名返回空字符串。
11、GUI.Window、 GUI.FocusWindow、GUI.DragWindow
GUI.BringWindowToBack、GUI.BringWindowToFront
//GUI.depth、GUI.BringWindowToBack、GUI.BringWindowToFront都可以改变窗口的层级
//GUI.BringWindowToBack GUI.BringWindowToFront
private Rect windowRect = new Rect(20, 20, 120, 120);
private Rect windowRect2 = new Rect(80, 20, 120, 120);
private Rect windowRect3 = new Rect(150, 20, 120, 120);
// GUI.depth
int guiDepth1 = 0;
int guiDepth2 = 0;
//
string m_focusedControlName = "";
void OnGUI()
{
windowRect = GUI.Window(0, windowRect, DoMyWindow1, "第一个窗口");
windowRect2 = GUI.Window(1, windowRect2, DoMyWindow2, "第二个窗口");
windowRect3 = GUI.Window(2, windowRect3, DoMyWindow3, "第三个窗口");
}
void DoMyWindow1(int windowID)
{
// GUI.depth = guiDepth1;
if (GUI.Button(new Rect(10, 20, 100, 20), "Window1"))
{
//GUI.BringWindowToBack(1);//将窗口id为1的窗口设置到最后
//guiDepth1 = 1;
//guiDepth2 = 0;
//GUI.BringWindowToFront(1);//将窗口id为1的窗口设置到最前
GUI.FocusWindow(1); //聚焦到id为1的窗口
}
//DragWindow 可拖动的窗口
GUI.DragWindow(new Rect(0, 0, 10000, 20));
}
void DoMyWindow2(int windowID)
{
//GUI.depth = guiDepth2;
if (GUI.Button(new Rect(10, 20, 100, 20), "Window2"))
{
//GUI.BringWindowToBack(2);
//guiDepth1 = 0;
//guiDepth2 = 1;
GUI.BringWindowToFront(2);
}
GUI.DragWindow(new Rect(0, 0, 10000, 20));
}
void DoMyWindow3(int windowID)
{
// GUI.depth = guiDepth2;
if (GUI.Button(new Rect(10, 20, 100, 20), "Window3"))
{
//GUI.BringWindowToBack(0);
//guiDepth1 = 0;
//guiDepth2 = 1;
GUI.BringWindowToFront(0);
}
GUI.DragWindow(new Rect(0, 0, 10000, 20));
}
边栏推荐
- Necessary for beginners PR 2021 quick start tutorial, PR green screen matting operation method
- 6.A-B
- In less than an hour, apple destroyed 15 startups
- Asynctask experience summary
- 【C语言】判断三角形
- 1. print hourglass
- 建立自己的网站(18)
- 零基础C语言(一)
- day23 js笔记 2021.09.14
- Come on, yuanuniverse. Sure enough, the heat won't pass for a while
猜你喜欢

Packaging and publishing application of jetpack compose desktop version

SEO优化的许多好处是与流量有直接关系

Multi dimensional monitoring: the data base of intelligent monitoring

Day37 JS note motion function 2021.10.11

【C语言】二叉树的实现及三种遍历

Ali three sides: what is the difference between using on or where in the left join associated table and the condition

RemoteViews的作用及原理

Redis 原理 - List

Redis principle - List

深度学习又有新坑了!悉尼大学提出全新跨模态任务,用文本指导图像进行抠图...
随机推荐
如何获取泛型的类型
Using MySQL database in the express framework of node
Daily practice of C language - day 4: find the sum of all even numbers within 100
Redis principle - List
Interview skills for interview steps
day23 js笔记 2021.09.14
AGCO AI frontier promotion (2.16)
Packaging and publishing application of jetpack compose desktop version
Difference (one dimension)
Day36 JS notes ecma6 syntax 2021.10.09
Excel import / export convenience tool class
[Beijing University of Aeronautics and Astronautics] information sharing for the first and second examinations of postgraduate entrance examination
ArrayList源码解析
SoapUI rookie tutorial
Zero basic C language (I)
KDD 2022 | 图“预训练、提示、微调”范式下的图神经网络泛化框架
SEO优化的许多好处是与流量有直接关系
Android应用安全之JNI混淆
Unity screenshot function
Redis hash hash type string (5)