ILRuntime | 学习概要

HuaTuo来了

01_HelloWorld

  • 只是简单调用了一个静态方法,还有很多的疑问。

02_Invocation
通过热更代码InstanceClass进行的演示,不可调用非静态方法?×

  • IType type = appdomain.LoadedTypes[“HotFix_Project.InstanceClass”];
  • method = type.GetMethod(“RefOutMethod”, 3);

03_Delegate
作者注释写的真好!


04_Inheritance 继承

  • 1.ILRuntime -> 生成跨域继承适配器,源代码分析?
  • 2.热更工程是否必须要放在Unity/Assets下,才能分析生成适配器代码?
    • 不是必须,热更工程可以和unity主工程不放在一起,这个已经验证通过啦~
  • 3.生成的适配器路径是怎么设置的?
  • 4.热更工程输出dll到StreamingAssets的visual studio设置?
    • https://docs.microsoft.com/zh-cn/visualstudio/ide/how-to-change-the-build-output-directory?view=vs-2022

05_CLRRedirectior Common Language Runtime重定向器

  • 热更域中的方法需要在Unity引擎中显示其堆栈信息时,需要重定向
  • 此示例演示的是对UnityEngine.Debug.Log方法的重定向,具体的实现步骤可以查看官方文档和示例
  • 编写重定向方法 -> 得到需要重定向的方法信息 -> 注册重定向方法
    • var mi = typeof(Debug).GetMethod(“Log”, new System.Type[] { typeof(object) });
    • appdomain.RegisterCLRMethodRedirection(mi, Log_11);

06_CLRBinding

  • 对热更dll自动生成CLR绑定,可以减少GC Alloc和运行耗时
  • 自动生成是否对路径等有硬性要求?
  • 2021.2.4f1下,有无绑定的情况下GC Alloc测试此示例均为0

07_Coroutine

  • appdomain.Invoke(“HotFix_Project.TestCoroutine”, “RunTest”, null, null);//主工程
  • CoroutineDemo.Instance.DoCoroutine(Coroutine());//热更dll
  • static System.Collections.IEnumerator Coroutine()//热更dll
  • 热更dll中有coroutine,主工程调用

08_MonoBehaviour

  • 主工程调用热更dll中的MonoBehaviour
  • 通过AddComponent和GetComponent做了示例
  • 通过MonoBehaviourAdapterEditor让Mono中的变量能够显示在Inspector面板上
  • 如果不想自己写,可以查看JEngine的ILRuntime的MonoBehaviour相关序列化实现
  • 最好还是不要使用继承于MonoBehaviour相关,尽量保证热更逻辑更纯粹

09_Reflection

  • 热更dll中使用反射与原生C#没有区别
  • 示例展示主工程中反射热更dll的类型
  • IType iType = appdomain.LoadedTypes[“HotFix_Project.InstanceClass”];
  • var t = iType.ReflectionType;

10_LitJson

  • LitJson.JsonMapper.RegisterILRuntimeCLRRedirection(appdomain);
  • 展示了利用LitJson在热更dll中的序列化和反序列化,打印结果可以查看代码简单得出(有种做C++习题的感觉~)

11_ValueTypeBinding

  • 通过绑定解决值类型在ILRuntime中产生较多的CPU开销和GC Alloc,仅主工程中的值类型需要绑定处理
测试cpu:i7-10700 CPU @2.9GHz
Unity2021.2.4f1编辑模式
未绑定绑定
测试Vector3的100000次点乘耗时2145ms97ms
测试Quaternion的100000次点乘耗时1506ms103ms
测试Vector2的100000次点乘耗时2199ms96ms
  • 热更dll中肯定是要使用unity值类型的,那么绑定是必不可少的

12_Performance

加载方式TestMandelbrotTest0Test1Test2Test3Test4Test5Test6Test7Test8Test9Test10Test11
热更DLL(编辑模式)res=3.927128,time:1483
res2=3.927128,time:684
time:1402time:1525time:2017time:112time:237time:789time:1333time:3032res=1999254659255,time:932res=10475520000,time:7859time:884time:3912
热更DLL(寄存器)(编辑模式)res=3.927128,time:452
res2=3.927128,time:370
time:1513time:1662time:922time:115time:240time:649time:1235time:3505res=1999254659255,time:406res=10475520000,time:3585time:699time:2267
xLua(编辑模式)res=3.9271313476562,tim3:138time:2418time:3744time:3259time:134time:308time:2294time:3367time:8463res=1000002499940.7,time:52res=104960000000,time=196time:7294757
热更DLL(Redmi K30 Ultra)res=3.927128,time:614
res2=3.927128,time:287
time:1608time:1657time:2052time:186No Data Printedtime:715time:1167time:2823res=1999254659255,time:516res=10475520000,time:4063time:1361time:3227
热更DLL(寄存器)(Redmi K30 Ultra)res=3.927128,time:210
res2=3.927128,time:226
time:1964time:2017time:1155time:155No Data Printedtime:712time:1382time:3588res=1999254659255,time:305res=10475520000,time:1582time:1419time:2502
xLua(Redmi K30 Ultra)res=3.9271313476562,time:1562time:11919time:14849time:15560time:287No Data Printedtime:10784time:11562time:29784res=1000002499941,time:416res=10496000000,time=2149time:3033time:27215
  • TestMandelbrot:一种在复平面上组成分形的点的集合;
  • Test0:200w次transform.position = transform.position;
  • Test1:200w次transform.Rotate(Vector3.up, 1);
  • Test2:200w次向量的x,y,z分量赋值
  • Test3:2w次创建GameObject再Destroy
  • Test4:2w次创建GameObject -> AddComponent -> 转换为SkinnedMeshRenderer -> receiveShadows = false -> Destroy
  • Test5:200w次var p = Input.mousePosition;
  • Test6:200w次创建三维向量 -> Normalize
  • Test7:200w次创建Quaternion -> *2 -> Slerp
  • Test8:200w次total = total + i - (i / 2) * (i + 3) / (i + 5);
  • Test9:2048w次数值计算赋值,两层循环:外层2w,内层1024
  • Test10:200w次Performance.TestFunc1(1, “123”, transform); TestFunc1是三参数无返回值的空函数
  • Test11:200w次三维向量创建 -> 求和
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值