纳金网
标题:
NGUI 3.0后事件的新写法
[打印本页]
作者:
狂风大尉
时间:
2014-7-29 21:36
标题:
NGUI 3.0后事件的新写法
以前NGUI中事件驱动的写法是
{
UIButton btn = gameObject.GetCompenent<UIButton>();
btn.onClick = onClick;
}
void onClick(GameObject sender)
{
Debug.Log(sender.name);
}
复制代码
而新版本NGUI的事件方法都是添加到事件list里的,这样写
{
UIButton btn = gameObject.GetComponent<UIButton>();
EventDelegate.Add(btn.onClick, onSelectRole);
}
public void onSelectRole()
{
Debug.Log(UIButton.current.name);
}
复制代码
或是这样
{
UIButton btn = gameObject.GetComponent<UIButton>();
EventDelegate.Add(btn.onClick, delegate() {
Debug.Log(UIButton.current.name);
});
}
复制代码
作者:
hyui
时间:
2014-7-29 22:04
I always love learn from other scripts !!!
作者:
我不再年轻
时间:
2014-7-29 22:25
好像没有以前的简洁
作者:
HIDEOKOJIMA
时间:
2014-7-29 22:42
Thanks for sharing this !
作者:
libufan
时间:
2014-7-29 23:13
封装的越好,就越来越想Java或者AS3的语法了
作者:
Kadina
时间:
2014-7-30 07:06
Very interesting )
作者:
iam0623
时间:
2014-8-11 11:47
Very Nice . Thanks
欢迎光临 纳金网 (http://go.narkii.com/club/)
Powered by Discuz! X2.5