当前位置:网站首页>【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));
}
边栏推荐
- 携手Cigent:群联为SSD主控固件引入高级网络安全防护特性
- [Beijing University of Aeronautics and Astronautics] information sharing for the first and second examinations of postgraduate entrance examination
- fatal: unsafe repository (‘/home/anji/gopath/src/gateway‘ is owned by someone else)
- MapReduce project case 1
- 案例驱动 :从入门到掌握Shell编程详细指南
- AcWing 606. Average 1 (implemented in C language)
- Practice and Thinking on the architecture of a set of 100000 TPS im integrated message system
- Why do many people want to change careers as programmers, while some programmers want to change careers as others?
- Three ways to implement LRU cache (recommended Collection)
- Bisection (integer bisection and floating point bisection)
猜你喜欢

KDD 2022 | 图“预训练、提示、微调”范式下的图神经网络泛化框架

Many benefits of SEO optimization are directly related to traffic

Chendanqi, Fang Fei, guquanquan and Li Bo won the prize, and the list of Sloan research award in 2022 was released
Using MySQL database in the express framework of node

Swin, three degrees! Eth open source VRT: a transformer that refreshes multi domain indicators of video restoration
![Connectionreseterror: [winerror 10054] the remote host forced an existing connection to be closed](/img/9a/97813f5ac4d7c15711891cff25b9dd.jpg)
Connectionreseterror: [winerror 10054] the remote host forced an existing connection to be closed

Android应用安全之JNI混淆

Prefix and (2D)

RemoteViews布局和类型限制源码分析

开源项目维权成功案例: spug 开源运维平台成功维权
随机推荐
Privilege management of vivo mobile phone
Remote login sshd service
RemoteViews布局和类型限制源码分析
Apache2 configuration denies access to the directory, but can access the settings of the files inside
Ali three sides: what is the difference between using on or where in the left join associated table and the condition
赛尔号抽奖模拟求期望
Research on personalized product search
Timestamp and date conversion "suggested collection"
Which programming language will attract excellent talents?
Data analysis learning notes
Using soapUI to obtain freemaker's FTL file template
fatal: unsafe repository (‘/home/anji/gopath/src/gateway‘ is owned by someone else)
Remoteviews layout and type restriction source code analysis
AcWing 604. Area of circle (implemented in C language)
Contract quantification system development (construction explanation) - contract quantification system development (source code analysis and ready-made cases)
Practice and Thinking on the architecture of a set of 100000 TPS im integrated message system
【C语言】如何产生正态分布或高斯分布随机数
Day37 JS note motion function 2021.10.11
FTP protocol for Wireshark packet capture analysis
【北京航空航天大学】考研初试复试资料分享