Stepping on the pit for a month
Problem description
Hot update resources can be completed on the client side, including downloading, writing lua scripts, finding lua scripts,
but opening Development Build in buildsetting, opening Use Player Log and Stack Trace, and then finding the operation log in the packaged file. The log content is as follows
LuaException: xlua.access, no field __Hotfix0_Update
stack traceback:
[C]: in field 'access'
[string "Init"]:101: in field 'hotfix'
LuaHotFix:2: in main chunk
[C]: in function 'require'
[string "chunk"]:1: in main chun
The error reported above is due to the failure to inject, but every time I change the C# code, I manually inject it, and the console prints had injected, indicating that the injection is successful, that is, there is a problem during operation, which causes the injection to fail.
To solve the client packaging problem, the following conditions must be met
* The hot update script must be tagged
* There are three ways to tag
1. Tags
* [LuaCallCSharp]
2. Static list
* Used to solve the class that cannot be tagged directly
[LuaCallCSharp]
public static List<Type> mymodule_lua_call_cs_list = new List<Type>()
{
typeof(GameObject),
typeof(Dictionary<string, int>),
};
3. Dynamic list
[Hotfix]
public static List<Type> by_property
{
get
{
return (from type in Assembly.Load("Assembly-CSharp").GetTypes()
where type.Namespace == "XXXX"
select type).ToList();
}
}
*Create XLuaBuildProcessor in the Editor file and add code
* It is intended to solve the problem that after the xLua injection is successful, the compilation is triggered again, and the injection result is overwritten to cause the bug
class XLuaBuildProcessor : IPostBuildPlayerScriptDLLs
{
public int callbackOrder
{
get
{
return 0;
}
}
public void OnPostBuildPlayerScriptDLLs(BuildReport report)
{
string dir = string.Empty;
foreach (var item in report.files)
{
if (item.path.Contains("Assembly-CSharp.dll"))
{
dir = item.path.Replace("Assembly-CSharp.dll", "");
}
}
Hotfix.HotfixInject(dir);
}
}
* After that, it can run and package normally, and there is no error in the operation log