Unity模仿TougleGroup编写Button Group
来源:互联网 发布:淘宝在哪改收货地址 编辑:程序博客网 时间:2024/06/03 22:09
最近制作一个VR的DEMO
UGUI 的Button需要加高亮,为了避免两个Button同时高亮,所有写了一个类似于Tougle Group的东西
==ButtonGroup============
public delegate void HighLightOffHandle(GameObject sender);public class ButtonGroup : MonoBehaviour { public event HighLightOffHandle HighLightOffEvent; public void Notify(GameObject sender) { if (HighLightOffEvent != null) { HighLightOffEvent(sender); } }}
==ButtonSingle=============
public class ButtonSingle : MonoBehaviour { public ButtonGroup buttonGroup; private bool m_IsOn; private void Awake() { m_IsOn = false; } private void OnEnable() { //将按钮注册进按钮组 if (buttonGroup == null) return; buttonGroup.HighLightOffEvent += new HighLightOffHandle(HighLightOff); } private void OnDisable() { //将按钮移出按钮组 if (buttonGroup == null) return; buttonGroup.HighLightOffEvent -= new HighLightOffHandle(HighLightOff); } //set方法用于设置是否高亮,并发送事件 public void Set(bool value) { if (m_IsOn == value) return; m_IsOn = value; if (buttonGroup != null) { if (m_IsOn) { buttonGroup.Notify(gameObject); } } ChangeHighlight(true, Color.yellow); Debug.Log("lezi"); } private void HighLightOff(GameObject sender) { m_IsOn = false; ChangeHighlight(false, Color.yellow); } public void ChangeHighlight(bool isHighlight,Color highlightColor) { Highlighter highlighter; if (GetComponent<Highlighter>()) highlighter = GetComponent<Highlighter>(); else highlighter = gameObject.AddComponent<Highlighter>(); if (isHighlight) highlighter.ConstantOnImmediate(highlightColor); else highlighter.ConstantOffImmediate(); }}
阅读全文
0 0
- Unity模仿TougleGroup编写Button Group
- RADIO BUTTON group
- Group Box覆盖Button
- 用button模仿radiobutton布局
- button.less+component animations+dropdowns+button-group
- 按钮组(Button group)
- Unity Toggle image button
- Unity Button 动画
- unity基础UI-Button
- JAVA模仿SQL的group by分组
- List模仿SQL的group by分组
- jquery源码模仿编写01
- LinearLayout模仿Button点击动态缩放效果
- 实现分断Button,模仿MIUI设置页面顶部Button
- 代码编写Button按钮
- Button的xml编写
- NetBeans中拖拽Radio Button组成Button Group的方法
- Warning: skipping non-radio button in group
- LNMP源码安装
- 学习笔记38-进程间通信
- Python 文件 编程
- 二维码介绍
- @SpringBootApplication的使用
- Unity模仿TougleGroup编写Button Group
- BZOJ 1070 [SCOI2007]修车 费用流
- 蓝牙BLE相关知识
- HDU1202
- 取出两个数组不相同的元素并返回到新的数组里面
- Linux下的tar压缩解压缩命令详解
- 23种设计模式(22):组合模式
- Java I/O
- WPF DataGrid Drag