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預編譯命令


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM