Unity热更新ILRuntime UGUI消息系统

须知:

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就能随便用消息了.都和正常使用一样.祝您成功!

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值