Toggle
1. 属性详解

Interactable : Will this component will accept input? 是否可用
Transition : Properties that determine the way the control responds visually to user actions. 状态变化(参考Button 里的解释)

Navigation : Properties that determine the sequence of controls. 热键关联
Is On : Is the toggle switched on from the beginning? 默认选中
Toggle Transition : The way the toggle reacts graphically when its value is changed. The options are Noe(ie,the checkmark simply appears or disappears) and Fade(ie,the checkmark fades in or out). 状态切换
Graphic : The image used for the checkmark 选择标识的图像
Group : The Toggle Group(if any) that this Toggle belongs to. 开关组
2. Toggle group 详解
Allow Switch Off : Is it allowed that no toggle is switched on ? If this setting is enabled,pressing the toggle that is currently switched on will switch it off,so that no toggle is switched on. If this setting is disabled ,pressing the toggle that is currently switched on will not change its state. 允许取消选择
新建GameObject,添加Toggle Group 脚本,在各个Toggle中添加ToggleGroup 对象.
ToggleGroup对象
UGUI 学习笔记7 Toggle
Toggle对象
UGUI 学习笔记7 Toggle
这样的是单选框。
UGUI 学习笔记7 Toggle
不用Toggle Group 脚本,则组成复选框。
UGUI 学习笔记7 Toggle
3. 代码控制
复选框控制
UGUI 学习笔记7 Toggle
在toggle On Value Changed 中添加函数showChoice()
UGUI 学习笔记7 Toggle
结果如下图
UGUI 学习笔记7 Toggle
单选框控制
UGUI 学习笔记7 Toggle
在toggle On Value Changed 中添加函数toggleSingleChoice()
结果如下图
UGUI 学习笔记7 Toggle

相关文章: