栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > .Net

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

.Net 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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


跨域委托注册及转换
  • 注册
	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();
  • 转换器
	这个方法参数是这样一个委托Func action
    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());

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/907478.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号