跨域委托注册及转换
- 注册
public delegate void TestDelegateMethod(int a);
public delegate string TestDelegateFunction(int a);
public static TestDelegateMethod TestMethodDelegate;
public static TestDelegateFunction TestFunctionDelegate;
注册无返回值委托
appdomain.DelegateManager.RegisterMethodDelegate();
注册带返回值委托(返回string)
appdomain.DelegateManager.RegisterFunctionDelegate();
- 转换器
这个方法参数是这样一个委托Funcaction appdomain.DelegateManager.RegisterDelegateConvertor ((action) => { 返回正确的委托,并且内部执行Action或Func return new TestDelegateMethod((a) => { ((System.Action )action)(a); }); });
- 热更工程订阅委托,主工程调用直接正常函数式调用
跨域继承
- 注册->实例化->调用
appdomain.RegisterCrossBindingAdaptor(new TestClassBaseAdapter()); obj = appdomain.Instantiate("HotFix_Project.TestInheritance"); obj.TestAbstract(123);
CLR重定向
- (官方原话)当需要劫持原方法,并添加一些热更dll的特殊处理时,需要重定向。例如在热更dll中Debug.Log是无法显示热更dll内堆栈的。
CLR绑定
- ILRuntime.Runtime.Generated.CLRBindings.Initialize(appdomain);
- 热更dll调用主工程方法,是通过反射进行的。存在很大的开销
Litjson使用
- LitJson.JsonMapper.RegisterILRuntimeCLRRedirection(appdomain);
值类型绑定
- (官方原话)Vector3等Unity常用值类型如果不做任何处理,在ILRuntime中使用会产生较多额外的CPU开销和GC Alloc,我们通过值类型绑定可以解决这个问题
appdomain.RegisterValueTypeBinder(typeof(Vector3), new Vector3Binder());
appdomain.RegisterValueTypeBinder(typeof(Quaternion), new QuaternionBinder());
appdomain.RegisterValueTypeBinder(typeof(Vector2), new Vector2Binder());



