GUI-单选框和多选框
private bool isSel;
private bool isSel2;
public GUIStyle style;
private int nowSelIndex = 1;
一 多选框
普通样式
isSel = GUI.Toggle(new Rect(0, 0, 100, 30), isSel, "效果开关");
这里关键是isSel这个值
Toggle方法每次会根据isSel的真假来显示是否被选中
自定义样式 显示问题
在Inspector的style中
修改固定宽高 fixedWidth和fixedHeight
修改从GUIStyle边缘到内容起始处的空间 padding
isSel2 = GUI.Toggle(new Rect(0, 40, 100, 30), isSel2, "音效开关", style);
二 单选框
单选框是基于 多选框的实现
关键:通过一个int标识来决定是否选中
if(GUI.Toggle(new Rect(0, 100, 100, 30), nowSelIndex == 1, "选项一"))
{
nowSelIndex = 1;
}
if(GUI.Toggle(new Rect(0, 140, 100, 30), nowSelIndex == 2, "选项二"))
{
nowSelIndex = 2;
}
if(GUI.Toggle(new Rect(0, 180, 100, 30), nowSelIndex == 3, "选项三"))
{
nowSelIndex = 3;
}