天天看點

xlua:hotfix大坑

開始研究xlua

Unity版本:2019.2beta

假設有一個類需要hotfix

原先的寫法:

using XLua;

public class FixTest
{
  [Hotfix]
  public void FixFunction()
  {
    Debug.Log("Fix");
  }
}      

按照文檔,配置好xlua,配置好Scripting Define Symbols: HOTFIX_ENABLE

點選XLua菜單下的Generate Code,再Hotfix Inject In Editor

在編輯狀态下運作是可以的

然後就Build項目,勾選上Development Build選項(為了有錯能看log)

運作build的項目,報錯:no field  什麼什麼的

找了半天問題

最後發現[Hotfix]标簽在這個版本的unity不能這樣用

得用另一種方式,就是在Editor下建一個靜态類,在裡面建靜态清單,清單裡是可以hotfix的類的Type,給這個清單加上[Hotfix]标簽

using XLua;

public static class LuaList
{
  [Hotfix]
  public static List<Type> typeList=new List<Type>()
  {
    typeof(FixTest)   //FixTest就是上面那段代碼建的類,并把那個的[Hotfix]去掉
  };
}