当前位置:网站首页>【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));
}
边栏推荐
- Chendanqi, Fang Fei, guquanquan and Li Bo won the prize, and the list of Sloan research award in 2022 was released
- 来吧元宇宙,果然这热度一时半会儿过不去了
- ProCAST finite element casting process simulation software
- Many benefits of SEO optimization are directly related to traffic
- FTP protocol for Wireshark packet capture analysis
- Cohere, a large model company, completed the round B financing of US $125million
- 多维度监控:智能监控的数据基础
- fatal: unsafe repository (‘/home/anji/gopath/src/gateway‘ is owned by someone else)
- Pre parsing, recursive functions and events in day25 JS 2021.09.16
- Day37 JS note motion function 2021.10.11
猜你喜欢

多维度监控:智能监控的数据基础

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

Leetcode 48. 旋转图像(可以,已解决)

Web3安全连载(3) | 深入揭秘NFT钓鱼流程及防范技巧
Using MySQL database in the express framework of node

【C语言】如何产生正态分布或高斯分布随机数

携手Cigent:群联为SSD主控固件引入高级网络安全防护特性

.NET混合开发解决方案24 WebView2对比CefSharp的超强优势

赛尔号抽奖模拟求期望

Why do many people want to change careers as programmers, while some programmers want to change careers as others?
随机推荐
Necessary for beginners PR 2021 quick start tutorial, PR green screen matting operation method
AcWing 606. Average 1 (implemented in C language)
MapReduce项目案例3——温度统计
Daily practice of C language - day 4: find the sum of all even numbers within 100
水果FL Studio/Cubase/Studio one音乐宿主软件对比
AcWing 608. Poor (implemented in C language)
Bisection (integer bisection and floating point bisection)
Deployment and optimization of vsftpd service
Is it feasible to be a programmer at the age of 26?
ArrayList源码解析
Redis principle - List
CDC synchronization if the primary key of a database table changes, will it be synchronized into two data or will it be synchronized to update the primary key?
Swin, three degrees! Eth open source VRT: a transformer that refreshes multi domain indicators of video restoration
AcWing 610. Salary and bonus (implemented in C language)
Vivo手机的权限管理
fatal: unsafe repository (‘/home/anji/gopath/src/gateway‘ is owned by someone else)
Source code analysis of ArrayList
3. seat number
Why do many people want to change careers as programmers, while some programmers want to change careers as others?
Still using simpledateformat for time formatting? Be careful that the project collapses!