using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

// 利用委托来进行按钮组的管理
public class test07 : MonoBehaviour {
// 脚本挂在一个Canvas上,其子物体上有两个Button:Button 喝 Button(1)
delegate void argument(string str);
void Start () {
argument arg = new argument(test);
arg = arg + test1;
for (int i = 0; i < gameObject.GetComponentsInChildren<Button>().Length; i++)
{
Button btn = gameObject.GetComponentsInChildren<Button>()[i];
btn.onClick.RemoveAllListeners();
btn.onClick.AddListener(() =>
{
if(arg != null){
arg(btn.name);
}
});
}
}

void onclicked(){

}
public void test(string str){
switch(str){
case "Button":
print("button");
break;
case "Button(1)":
print("button");
break;
default: print("nothing");
break;
}
}
public void test1(string str)
{
print(str);
}
}

最新文章

  1. 集成学习之Adaboost算法原理小结
  2. sublime
  3. WCF实现客户端自动更新
  4. Android SDK Manager 更新代理配置 ,蛋碎了
  5. thinkphp 模板中赋值
  6. Sublime text3 JS语法检测工具安装及使用
  7. hdu Diophantus of Alexandria(素数的筛选+分解)
  8. Concurrent usage detected
  9. linux--磁盘及文件系统管理
  10. android ViewPager之PagerAdapter中View的重用
  11. Jenkins知识地图
  12. Luogu P1533 可怜的狗狗
  13. java对象流与序列化
  14. Django基础四之模板系统
  15. appcmd创建站点、应用程序、虚拟目录批处理程序
  16. Python Monitoring UPS with SNMPWALK
  17. 第六章在U盘上运行openwrt(引导)--补
  18. 11-09SQLserver 基础-数据库之汇总练习45题
  19. URAL 1934 spfa算法
  20. [置顶] docker1.12--docker命令行帮助文档

热门文章

  1. App 打包
  2. webpack学习笔记 (一)
  3. Day 5内存管理,定义变量
  4. Java8:Lambda表达式增强版Comparator和排序
  5. Java核心技术卷一 &#183; 笔记(1)
  6. MongDB 批量更新
  7. HIT2019春软件构造-&gt;Git&amp;Github学习笔记
  8. 基于VC++的网络扫描器设计与实现
  9. ACM 第十一届 河南省省赛A题 计划日
  10. 移动端根据dpr适配