现在的位置: 首页 > 综合 > 正文

delegate的一个很常用的用法

2017年05月24日 ⁄ 综合 ⁄ 共 394字 ⁄ 字号 评论关闭

在购买物品的时候我们需要显示金币的数目,金币充足的时候一般是白色,不足为红色,红色的时候需要跳转到商店去购买金币之类(响应某个事件),结束后返回我们需要金币的颜色重新编程白色,那么这时候需要回调。

在商店类中:

	public delegate void StoreDelegate ();

public Class Store : Layer { public StoreDelegate onfinish;<span style="white-space:pre"> </span> public void Close () { if (onFinish != null) onFinish (); base.Close (); } }

在调用的时候:

	Store abc = new Store ();

abc.Show ();

abc.onFinish = delegate ()

{

if (requireGold < gold)

label.color = Color.White

};

抱歉!评论已关闭.