ILRuntime学习记录 - 跨域委托、跨域继承等


跨域委托注册及转换

  • 注册
	public delegate void TestDelegateMethod(int a);
	public delegate string TestDelegateFunction(int a);
	public static TestDelegateMethod TestMethodDelegate;
    public static TestDelegateFunction TestFunctionDelegate;
	注册无返回值委托
	appdomain.DelegateManager.RegisterMethodDelegate<int>();
	注册带返回值委托(返回string)
	appdomain.DelegateManager.RegisterFunctionDelegate<int, string>();
  • 转换器
	这个方法参数是这样一个委托Func<Delegate, Delegate> action
    appdomain.DelegateManager.RegisterDelegateConvertor<TestDelegateMethod>((action) =>
    {
    	返回正确的委托,并且内部执行Action或Func
        return new TestDelegateMethod((a) =>
        {
            ((System.Action<int>)action)(a);
        });
    });
  • 热更工程订阅委托,主工程调用直接正常函数式调用

跨域继承

  • 注册->实例化->调用
	appdomain.RegisterCrossBindingAdaptor(new TestClassBaseAdapter());
	obj = appdomain.Instantiate<TestClassBase>("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());

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值