须知:
ILRuntime的委托跨域 需要 注册该委托作一个互转
按钮消息获取:
首先说一下按钮那个方便的onClick怎么弄. 他是UnityAction的消息 没有参数的.所以很方便.只需要UnityAction和系统的Action互转一下就好了.
//放到Unity主程序能执行到的地方.(不是热更新的DLL里注意!!!)
//注册UnityAction
g_appdomain.DelegateManager.RegisterDelegateConvertor<UnityAction>((action) =>
{
return new UnityAction(() =>
{
((System.Action)action)();
});
});
使用UGUI消息系统:
消息系统具体怎么用的参见相关的文档这里不赘述了. 由于用到了BaseEventData类所以需要注册这个先.然后就是UnityAction的参数BaseEventData 的互转了.
//放到Unity主程序能执行到的地方.(不是热更新的DLL里注意!!!)
//注册UnityAction
g_appdomain.DelegateManager.RegisterMethodDelegate<BaseEventData>();
g_appdomain.DelegateManager.RegisterMethodDelegate<System.Object, ILRuntime.Runtime.Intepreter.ILTypeInstance>();
g_appdomain.DelegateManager.RegisterDelegateConvertor<UnityAction<BaseEventData>>((action) =>
{
return new UnityAction<BaseEventData>((a) =>
{
((System.Action<BaseEventData>)action)(a);
});
});
如果你注册了上面的这些委托 应该UGUI就能随便用消息了.都和正常使用一样.祝您成功!