Unity 事件2
UIMouseEvent.cs:
using UnityEngine;
using System; public abstract class UIMouseEvent : MonoBehaviour
{
public EventHandler<EventArgs> MouseEvent { get; set; }
}
UIEvent.cs:
using UnityEngine;
using System;
using System.Collections.Generic;
using System.Collections; public class UIEvent
{
public static GameObject FindChild (string objName)
{
GameObject obj = GameObject.Find("quickLoginBtn");
return obj;
} public static void AddChildMouseClickEvent (string objName, EventHandler<EventArgs> action)
{
AddMouseClickEvent (FindChild (objName), action);
} public static void AddMouseClickEvent (GameObject obj, EventHandler<EventArgs> action)
{
if (obj != null) {
AddEvent<UIMouseClick> (obj, action);
}
Debug.Log("111111");
} public static void AddEvent<T> (GameObject obj, EventHandler<EventArgs> action) where T : UIMouseEvent
{
T mouseEvent = obj.GetComponent<T> ();
if (null != mouseEvent) {
GameObject.DestroyImmediate (mouseEvent);
}
mouseEvent = obj.AddComponent<T> ();
mouseEvent.MouseEvent = action;
Debug.Log("22222");
} public static void AttachEvent ()
{
Debug.Log ("AttachEvent");
AddChildMouseClickEvent ("quickLoginBtn", OnClickStart);
} private static void OnClickStart (object sender, EventArgs e)
{
Debug.Log("OnClickStart");
}
}
UIMouseClick.cs:
using UnityEngine;
using System; public class UIMouseClick : UIMouseEvent
{
void OnClick()
{
Debug.Log("hhhhh");
UIEvent.AttachEvent();
if(null != MouseEvent)
MouseEvent(gameObject, null);
}
}
最后把UIMouseClick.cs放到NGUI的button上面就可以了,这个button的名字为“quickLoginBtn”,结果如下:
Unity 事件2的更多相关文章
- Unity事件
unity3d事件函数整理,事件,回调函数,消息处理 Unity3D中所有控制脚本的基类MonoBehaviour有一些虚函数用于绘制中事件的回调,也可以直接理解为事件函数,例如大家都很清楚的Star ...
- unity 事件顺序及功能说明
unity3d中所有控制脚本的基类MonoBehaviour有一些虚函数用于绘制中事件的回调,也可以直接理解为事件函数,例如大家都很清楚的Start,Update等函数,以下做个总结. Awake 当 ...
- C#——Unity事件监听器
事件监听器 事件类型 public enum BaseHEventType { GAME_OVER, GAME_WIN, PAUSE, ENERGY_EMEPTy, GAME_DATA } 事件基类 ...
- Unity可视化数据:创建图表
本文由Aoi翻译,转载请注明出处.文章来自于catlikecoding,原文作者介绍了Unity制作图表.可视化数据的方法.更多的名词解释内容,请点击末尾的“原文链接”查看. 介绍 这个教程里,我 ...
- 喵的Unity游戏开发之路 - 互动环境(有影响的运动)
如图片.视频或代码格式等显示异常,请查看原文: https://mp.weixin.qq.com/s/Sv0FOxZCAHHUQPjT8rUeNw 很多童鞋没有系统的Unity3D游戏开发基础,也不知 ...
- Unity3D心得分享
本篇文章的内容以各种tips为主,不间断更新 系列文章 =========================== "Unity测试系列"文章索引 Unity-Animator深入系列 ...
- gameUnity 网络游戏框架
常常在想,有没有好的方式,让开发变得简单,让团队合作更加容易. 于是,某一天 动手写一个 架构, 目前版本 暂定 0.1 版本.(unity5.0.0f4 版本以上) 我打算 开源出来 0.1有什么功 ...
- 做好Unity4.x开发项目规划
1. 是否要用lua 2. (对于需操作的游戏)客户端游戏如何做战斗验证 下面列举小坑吧.不建议都绕开,毕竟没有那么多时间做前期调研的. 对应版本Unity4.x 1. 客户端程序层面 总的来说C#超 ...
- U3D开发性能优化笔记(待增加版本.x)
http://blog.csdn.net/kaitiren/article/details/45071997 此总结由自己经验及网上收集整理优化内容 包括: .代码方面: .函数使用方面: .ui注意 ...
随机推荐
- bound和unbound方法,类的绑定和非绑定是什么
作者:灵剑链接:https://www.zhihu.com/question/41006598/answer/148994582来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明 ...
- 【BZOJ 3160】 3160: 万径人踪灭 (FFT)
3160: 万径人踪灭 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 1440 Solved: 799 Description Input Outp ...
- [POI2012]Squarks
[POI2012]Squarks 题目大意: 设有\(n\)个互不相同的正整数\(\{X_1,X_2,...,X_n\}\),任取两个\(X_i,X_j(i\ne j)\),能算出\(X_i+X_j\ ...
- VIM选项配置说明
选项配置说明 选项书写格式 选项说明 :se[t] 显示所有被改动的选项 :se[t] all 显示所有非 termcap 选项 :se[t] termcap 显示所有 termcap 选项 :se[ ...
- SQL 语句实现排序问题!
SQL 查询数据时按某列排序后增加排名列,需排名的列值相等时排名相同,即如需排名列数组为:9,9,8,7,7,6 添加的排名列数组需要显示为两种: 第一种:1,1,3,4,4,6 (这种排名方 ...
- MariaDB 10 (MySQL DB) 多主复制并实现读写分离
----本文大纲 简介 资源配置 拓扑图 实现过程 ==================== 一.简介 MMM 即Master-Master Replication Manager for MySQL ...
- BZOJ 2301: [HAOI2011]Problem b (莫比乌斯反演)
2301: [HAOI2011]Problem b Time Limit: 50 Sec Memory Limit: 256 MBSubmit: 436 Solved: 187[Submit][S ...
- 更改CentOS 6.3 yum源为国内 阿里云源
将CentOS的 yum源 更换为 阿里云源 1.备份 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.b ...
- chm TO html 另类方法
因为网上下了很多chmtohtml ,都是试用版的, 转成html网页格式,总是有限制,或是不完整,我现在找到了一种折中方法,供大家参考 一,我的资源里有工具word to chm 里面有转成网页的 ...
- Curvilinear structure detections
此部分参考处 As a structure-based detector, PCBR does not use edges, instead, it uses curvilinear structur ...