using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;
public class EventTriggerListener : UnityEngine.EventSystems.EventTrigger{
public delegate void VoidDelegate (GameObject go);
public VoidDelegate onClick;
public VoidDelegate onDown;
public VoidDelegate onEnter;
public VoidDelegate onExit;
public VoidDelegate onUp;
public VoidDelegate onSelect;
public VoidDelegate onUpdateSelect; static public EventTriggerListener Get (GameObject go)
{
EventTriggerListener listener = go.GetComponent<EventTriggerListener>();
if (listener == null) listener = go.AddComponent<EventTriggerListener>();
return listener;
}
public override void OnPointerClick(PointerEventData eventData)
{
if(onClick != null) onClick(gameObject);
}
public override void OnPointerDown (PointerEventData eventData){
if(onDown != null) onDown(gameObject);
}
public override void OnPointerEnter (PointerEventData eventData){
if(onEnter != null) onEnter(gameObject);
}
public override void OnPointerExit (PointerEventData eventData){
if(onExit != null) onExit(gameObject);
}
public override void OnPointerUp (PointerEventData eventData){
if(onUp != null) onUp(gameObject);
}
public override void OnSelect (BaseEventData eventData){
if(onSelect != null) onSelect(gameObject);
}
public override void OnUpdateSelected (BaseEventData eventData){
if(onUpdateSelect != null) onUpdateSelect(gameObject);
}
}
 using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using UnityEngine.Events;
public class UIMain : MonoBehaviour {
Button button;
Image image;
void Start ()
{
button = transform.Find("Button").GetComponent<Button>();
image = transform.Find("Image").GetComponent<Image>();
EventTriggerListener.Get(button.gameObject).onClick =OnButtonClick;
EventTriggerListener.Get(image.gameObject).onClick =OnButtonClick;
} private void OnButtonClick(GameObject go){
//在这里监听按钮的点击事件
if(go == button.gameObject){
Debug.Log ("DoSomeThings");
}
}
}

链接: http://www.xuanyusong.com/archives/3325

UGUI之控件以及按钮的监听事件系统的更多相关文章

  1. UGUI研究院之控件以及按钮的监听事件系统

    继续学习,我相信大家在做NGUI开发的时候处理事件都会用到UIEventListener,那么UGUI中怎么办呢?先看UGUI的事件有那些吧 Supported Events The Eventsys ...

  2. 背水一战 Windows 10 (66) - 控件(WebView): 监听和处理 WebView 的事件

    [源码下载] 背水一战 Windows 10 (66) - 控件(WebView): 监听和处理 WebView 的事件 作者:webabcd 介绍背水一战 Windows 10 之 控件(WebVi ...

  3. Spinner控件:Spinner绑定的监听是SetOnItemSelectedListener

    (一) 1.效果图:ArrayAdapter可以不用设置 arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_it ...

  4. Silverlight项目笔记5:Oracle归档模式引起的异常&&表格控件绑定按钮

    1.Oracle归档模式产生日志文件引起数据库异常 连接数据库失败,提示监听错误,各种检查监听配置文件,删除再添加监听,无果. sqlplus下重启数据库数据库依然无果,期间碰到多个错误提示: ORA ...

  5. Ionic控件之——按钮(Button)

    Ionic提供丰富的按钮特性,足以满足大部分的按钮实现需求. 一.HTML实现一个简单按钮: <button class="button"> 我是按钮 </but ...

  6. 背水一战 Windows 10 (31) - 控件(按钮类): ButtonBase, Button, HyperlinkButton, RepeatButton, ToggleButton, AppBarButton, AppBarToggleButton

    [源码下载] 背水一战 Windows 10 (31) - 控件(按钮类): ButtonBase, Button, HyperlinkButton, RepeatButton, ToggleButt ...

  7. C# 如何定义让PropertyGrid控件显示[...]按钮,并且点击后以下拉框形式显示自定义控件编辑属性值

    关于PropertyGrid控件的详细用法请参考文献: 1.C# PropertyGrid控件应用心得 2.C#自定义PropertyGrid属性 首先定义一个要在下拉框显示的控件: using Sy ...

  8. 控件(按钮类): ButtonBase, Button, HyperlinkButton, RepeatButton, ToggleButton, AppBarButton, AppBarToggleButton

    介绍背水一战 Windows 10 之 控件(按钮类) ButtonBase Button HyperlinkButton RepeatButton ToggleButton AppBarButton ...

  9. Duilib 鼠标在某控件例如按钮上悬停后,对目标控件操作

    其实对WM_MOUSEHOVER消息的处理,因为WindowImplBase基类中对此消息未处理,所以在自己的窗口类中实现: .h文件中加入 LRESULT OnMouseHover( UINT uM ...

随机推荐

  1. Oracle 报错:PLS-00201: 必须声明标识符

    原因:调用其他用户的包或存储过程. 解决方法:在被调用的包或存储过程的用户下授权执行权限给调用用户: grant execute on 包名 to 用户名;

  2. ython strip lstrip rstrip使用方法

    Python中的strip用于去除字符串的首尾字符,同理,lstrip用于去除左边的字符,rstrip用于去除右边的字符. 这三个函数都可传入一个参数,指定要去除的首尾字符. 需要注意的是,传入的是一 ...

  3. 【WPF】ListBox嵌套与事件冒泡

    问题:两个ListBox嵌套后,当鼠标位于内部ListBox上,鼠标滚轮事件会被内部ListBox接收,导致外层ListBox不能用鼠标滚轮滑动!现在的需求是该事件要能给外部ListBox处理,即嵌套 ...

  4. andorid——自定义seekbar(转)

    xml 新建=>xml=>values <?xml version="1.0" encoding="utf-8"?> <resou ...

  5. Redis (1) —— 安装

    Redis (1) -- 安装 摘要 介绍Mac OS X安装Redis基本方法 版本 Redis版本: 2.8.24 内容 下载Redis包 地址:http://download.redis.io/ ...

  6. 在 Android studio 中 配置Gradle 做到 “根据命令行提示符生成指定versionCode, versionName,指定apk的打包输出路径”

    需求: 1. 使用 Android studio ,使用 gradle 进行构建 2. 在实际开发中,我们需要使用jenkins进行打包.就需要配置我们的 gradle 脚本以支持参数化的方式. 3. ...

  7. SQL Server 2012 自动增长列,值跳跃问题(自增增加1000)

    介绍 从 SQL Server 2012 版本开始, 当SQL Server 实例重启之后,表格的自动增长列的值会发生跳跃,而具体的跳跃值的大小是根据增长列的数据类型而定的.如果数据类型是 整型(in ...

  8. Java嵌入式数据库H2学习总结

    H2数据库使用总结 —— 孤傲苍狼

  9. XXXXX

    http://www.java-gaming.org/topics/laser-fx-opengl-libgdx/25402/view.html Libgdx游戏引擎之Dialog组件 http:// ...

  10. Q_UNUSED() 方法的使用

    Q_UNUSED() 没有实质性的作用,用来避免编译器警告 //比如说 int testFunc(int a, int b, int c, int d) { int e; return a+b+c; ...