1.NGUI通过lua层为按钮设置lua中点击回调方法时,需要把存储当前回调事件的脚本记录到list中,并在该LuaEnv Dispose()之前将所有onClick = null,否则会导致xlua抛出”try to dispose a LuaEnv with C# callback!” 异常
参考链接:http://www.cnblogs.com/ghl_carmack/p/7350530.html
参考代码:
private List<UIEventListener> ButtonEventListener = new List<UIEventListener>();
/// <summary>
/// 添加单击事件
/// </summary>
public void AddClick(GameObject go,UIEventListener.VoidDelegate luafunc)
{
if (go == null || luafunc == null) return;
UIEventListener uievent = UIEventListener.Get(go);
uievent.onClick = delegate(GameObject o) {
luafunc(go);
};
ButtonEventListener.Add(uievent);
}
/// <summary>
/// 清除单击事件