在Unity3D中使用ILRuntime遇到的一些报错问题

Error1:在热更代码中使用button.onClick.AddListener

报错: KeyNotFoundException: Cannot find convertor for UnityEngine.Events.UnityAction
Please add following code:
appdomain.DelegateManager.RegisterDelegateConvertor<UnityEngine.Events.UnityAction>((act) =>
{
return new UnityEngine.Events.UnityAction(() =>
{
((Action<>)act)();
});
});
解决方案:在初始化的时候添加
appdomain.DelegateManager.RegisterDelegateConvertor<UnityEngine.Events.UnityAction>((act) =>
{
returnnew UnityEngine.Events.UnityAction(() =>
{
((Action)act)();
});
});

Error2:在热更中使用Unity的协程
报错:
TypeLoadException: Cannot find Adaptor for:System.Collections.Generic.IEnumerator`1[System.Object]
ILRuntime.CLR.TypeSystem.ILType.InitializeInterfaces () (at
解决方案:参考案例中的CoroutineDemo,添加协程适配器
初始化的时候: appdomain.RegisterCrossBindingAdaptor(new CoroutineAdapter()); // 携程
publicvoid DoCoroutine(IEnumerator coroutine)
{
StartCoroutine(coroutine);
}

Error3:在热更代码中使用异步
报错:
TypeLoadException: Cannot find Adaptor for:System.Runtime.CompilerServices.IAsyncStateMachine
ILRuntime.CLR.TypeSystem.ILType.InitializeInterfaces () (at
解决方案:在Github中的Issues中有说明:链接
在代码中继承了System.Runtime.CompilerServices.IAsyncStateMachine,因此需要添加对应的适配器,Github的master中有async的TestCase,里面有写好的现成的这个接口的适配器.
异步适配器代码:链接
把这个代码放到项目中.
初始化的时候: appdomain.RegisterCrossBindingAdaptor(new IAsyncStateMachineClassInheritanceAdaptor()); // 异步

Error4 在Unity的Editor中提示没有生成适配器
解决方案: 修改Demo中的 ILRuntimeCrossBinding脚本,把生产适配的类名改成自己要生成适配器的类就行:列如下面就是UI_Base_HotFix的适配器,该生成的适配的命名空间是ILRuntimeDemo.
ILRuntimeCrossBinding脚本的内容如下:
publicclassILRuntimeCrossBinding
{
[MenuItem("ILRuntime/生成跨域继承适配器")]
staticvoid GenerateCrossbindAdapter()
{
//由于跨域继承特殊性太多,自动生成无法实现完全无副作用生成,所以这里提供的代码自动生成主要是给大家生成个初始模版,简化大家的工作
//大多数情况直接使用自动生成的模版即可,如果遇到问题可以手动去修改生成后的文件,因此这里需要大家自行处理是否覆盖的问题
using(System.IO.StreamWriter sw = new System.IO.StreamWriter("Assets/Samples/ILRuntime/2.0.2/Demo/Scripts/Examples/04_Inheritance/UI_Base_HotFix_Adapter.cs"))
{
// sw.WriteLine(ILRuntime.Runtime.Enviorment.CrossBindingCodeGenerator.GenerateCrossBindingAdapterCode(typeof(TestClassBase), "ILRuntimeDemo"));
sw.WriteLine(ILRuntime.Runtime.Enviorment.CrossBindingCodeGenerator.GenerateCrossBindingAdapterCode(typeof(UI_Base_HotFix), "ILRuntimeDemo"));
}
AssetDatabase.Refresh();
}
}

Error5 :TypeLoadException: Cannot find Adaptor for:UI_Base_HotFix
ILRuntime.CLR.TypeSystem.ILType.InitializeBaseType () (at
使用editor中的通过自动更新热更DLL生成CLR绑定的是报错提示 Cannot find Adaptor for:XXXXXX
解决方法:先生成适配器 然后在Demo中自带的ILRuntimeCLRBinding脚本中的InitILRuntime方法中注册对应的适配器:
代码如下:
domain.RegisterCrossBindingAdaptor(new TestClassBaseAdapter());
// TestClassBaseAdapter 注册的适配器类

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值