ILRuntime官方Demo笔记

调用/执行 热更中的方法#

调用热更代码中方法,写在AppDomain中,记录一下主要几个方法:

AppDomain.LoadAssembly 加载热更dll

执行热更代码的方法,有两种方式:

  1. appdomain.Invoke(“HotFix_Project.InstanceClass”, “StaticFunTest”, null, null);
  1. 预先获得IMethod,可以减低每次调用查找方法耗用的时间,代码如下:
//预先获得IMethod,可以减低每次调用查找方法耗用的时间
IType type = appdomain.LoadedTypes["HotFix_Project.InstanceClass"];
//根据方法名称和参数个数获取方法
IMethod method = type.GetMethod("StaticFunTest", 0);

appdomain.Invoke(method, null, null);

监听主工程的委托#

在热更工程中监听主工程的事件,由主工程触发。

如果非Action或Func,则需要在主工程中写适配器,所以建议使用系统自带的Action和F

你可能感兴趣的:(unity精华)