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次点乘耗时 | 2145ms | 97ms | 测试Quaternion的100000次点乘耗时 | 1506ms | 103ms | 测试Vector2的100000次点乘耗时 | 2199ms | 96ms |
- 热更dll中肯定是要使用unity值类型的,那么绑定是必不可少的
12_Performance
加载方式 | TestMandelbrot | Test0 | Test1 | Test2 | Test3 | Test4 | Test5 | Test6 | Test7 | Test8 | Test9 | Test10 | Test11 |
---|
热更DLL(编辑模式) | res=3.927128,time:1483 res2=3.927128,time:684 | time:1402 | time:1525 | time:2017 | time:112 | time:237 | time:789 | time:1333 | time:3032 | res=1999254659255,time:932 | res=10475520000,time:7859 | time:884 | time:3912 | 热更DLL(寄存器)(编辑模式) | res=3.927128,time:452 res2=3.927128,time:370 | time:1513 | time:1662 | time:922 | time:115 | time:240 | time:649 | time:1235 | time:3505 | res=1999254659255,time:406 | res=10475520000,time:3585 | time:699 | time:2267 | xLua(编辑模式) | res=3.9271313476562,tim3:138 | time:2418 | time:3744 | time:3259 | time:134 | time:308 | time:2294 | time:3367 | time:8463 | res=1000002499940.7,time:52 | res=104960000000,time=196 | time:729 | 4757 | 热更DLL(Redmi K30 Ultra) | res=3.927128,time:614 res2=3.927128,time:287 | time:1608 | time:1657 | time:2052 | time:186 | No Data Printed | time:715 | time:1167 | time:2823 | res=1999254659255,time:516 | res=10475520000,time:4063 | time:1361 | time:3227 | 热更DLL(寄存器)(Redmi K30 Ultra) | res=3.927128,time:210 res2=3.927128,time:226 | time:1964 | time:2017 | time:1155 | time:155 | No Data Printed | time:712 | time:1382 | time:3588 | res=1999254659255,time:305 | res=10475520000,time:1582 | time:1419 | time:2502 | xLua(Redmi K30 Ultra) | res=3.9271313476562,time:1562 | time:11919 | time:14849 | time:15560 | time:287 | No Data Printed | time:10784 | time:11562 | time:29784 | res=1000002499941,time:416 | res=10496000000,time=2149 | time:3033 | time: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次三维向量创建 -> 求和
|