ILRuntime热更方案坑点

ILRuntime热更方案坑点

在热更工程中:

1.AddComponent需要限定好类型,不能用Type类型,会报错

2.GetComponent无法获取基类组件类型,无法找到时,需要在MonoBehaviorAdapter中添加遍历获取基类逻辑
3.Hotfix调用Unity中带参数的委托,需要注册委托参 RegisterMethodDelegate
4.强转Action委托类型as报错,使用(Action)XXX的方式去转换
5.尽可能不过多使用特性,反射,容易出问题。
6.继承自MonoBehavior的脚本声明处初始化不起作用,需要在Awake中去初始化
7.ref out关键字谨慎使用,比如传递ref/out 静态变量时,会报错。
8.Json解析必须要使用集成的LitJson库
9.重写父类方法时,不能使用virtual关键字,否则会执行两次,要使用override

10.Awake方法在AddComponent组件时调用一次,不论节点是否显示。此时需要在MonoBehaviorAdapter中加一层判断来规避此情况。

11.协程无法使用字符串启动,只支持参数为IEnumerator类型的方式启动或停止协程
12.ILRuntime不支持proto2,需要换成proto3,同时由于ILRuntime不认为ILRT里面跑的数据类型是枚举,导致无法把默认值转换为枚举,不能使用枚举(比如消息类型)

13.打包时,主工程未用到但是热更工程用到的dll未被打包,添加link.xml文件,内容为

例如:

<linker>
<!-- The following assemblies contain namespaces that should be fully preserved
even when assembly stripping is used. Not excluding the assemblies below from
stripping can result in crashes or various exceptions.

<assembly fullname="Vuforia.UnityExtensions">
<namespace fullname="Vuforia" preserve="all"/>
</assembly>
-->

<assembly fullname="System">
<namespace fullname="System.Runtime.InteropServices" preserve="all"/>
<namespace fullname="System.Collections;" preserve="all"/>
<namespace fullname="System.Collections.Generic;" preserve="all"/>
<namespace fullname="System.Collections.IEnumerator;" preserve="all"/>
</assembly>

<assembly fullname="UnityEngine">
<type fullname="UnityEngine.Collider" preserve="all"/>
<type fullname="UnityEngine.SphereCollider" preserve="all"/>
<type fullname="UnityEngine.AudioSources" preserve="all"/>
</assembly>

<!-- XMLSerilizer-->
<assembly fullname="System.Xml">
<namespace fullname="System.Xml" preserve="all"/>
</assembly>

<!--JSONSerilizer-->

<assembly fullname="Newtonsoft.Json">
<namespace fullname="Newtonsoft.Json" preserve="all"/>
</assembly>
<assembly fullname="UnityEngine" preserve="all"/>
<assembly fullname="Assembly-CSharp" preserve="all"/>
</linker>

14.在若因使用指针,必须标记为unsafe的,默认情况下unity中使用unsafe标记会报错,可以在项目中添加smcs.rsp文件并加入-unsafe预编译命令

posted @ 2019-10-16 17:24  那一轮弯月~  阅读(7365)  评论(1编辑  收藏  举报