/// <summary> /// 添加点击事件 /// </summary> /// <param name="obj">目标控件</param> /// <param name="fun">回调函数</param> public static void OnClick(GameObject obj, LuaFunction fun) { if (obj.GetComponent <Button>()) { Button btn = obj.GetComponent <Button>(); btn.onClick.AddListener(fun.Call); } else { if (obj.GetComponent <ClickListener>() == null) { obj.AddComponent <ClickListener>(); } ClickListener click = obj.GetComponent <ClickListener>(); click.AddClickListener(() => { fun.Call(); }); } }
public static void AddListener(GameObject obj, LuaFunction clickFunc, LuaFunction downFunc, LuaFunction upFunc) { if (obj.GetComponent <ClickListener>() == null) { obj.AddComponent <ClickListener>(); } ClickListener click = obj.GetComponent <ClickListener>(); click.AddClickListener(() => { clickFunc.Call(); }); click.AddListener(() => { downFunc.Call(); }, () => { upFunc.Call(); }); }