Using the hot update feature of xlua to repair the c# code, the git address corresponding to xlua is https://github.com/Tencent/xLua
development preparation
Project settings
1. Open the HOTFIX feature
Add the HOTFIX_ENABLE macro, (add it under File->Build Setting->Scripting Define Symbols in Unity3D). This macro should be set separately for the editor and each mobile platform! If it is automated packaging, it should be noted that the macros set with the API in the code will not take effect and need to be set in the editor.
(It is recommended that HOTFIX_ENABLE is not turned on for business code development, and HOTFIX_ENABLE is only turned on when building the mobile version or when developing patches under the compiler)
2. Execute the XLua/Generate Code menu.
3. Inject, build the mobile phone package. This step will be automatically performed during the build. To develop patches under the editor, you need to manually execute the "XLua/Hotfix Inject In Editor" menu. Printing "hotfix inject finish!" or "had injected!" is successful, otherwise an error message will be printed.
If "hotfix inject finish!" or "had injected!" has been printed, execute xlua.hotfix and still report an error like "xlua.access, no field __Hitfix0_Update", either the class is not configured in the Hotfix list, or the injection is successful After that, the compilation is triggered again, overwriting the injection result.
Identifies the type to hot update
Create a HotfixCfg file in the Editor directory to configure hotfixable classes. The method of identifying the Namespace is adopted, so that the classes under the Namespace can be hot updated
#if !XLUA_GENERAL
using UnityEngine;
using UnityEditor;
#endif
using System.Collections.Generic;
using XLua;
using System;
using System.Reflection;
using System.Linq;
public static class HotfixCfg
{
[Hotfix]
public static List<Type> by_property
{
get
{
return (from type in Assembly.Load("Assembly-CSharp").GetTypes()
where type.Namespace == "YourNamespace"
select type).ToList();
}
}
}
Repair process
Generate hot update resource pack
Assuming that the online version is 1.0.0, a corresponding repair version 1.0.0.001 needs to be released at this time
1. Create the 1.0.0.001 folder in the Assets/Hotfix folder and add the lua patch luaScript.lua. Fix bugs with lua scripts
2. In the Inspector interface, set the AssetBundle tag of the patch code to 1.0.0.001
3. Call Assets/Build AssetBundle to generate the corresponding AssetBundle resources
4. Upload the AssetBundle resources to the cdn server. Fill in the corresponding information and address into the hot update configuration table below
5. The server sends the corresponding hot update information according to the configuration table
Hot update configuration table
version |
channel |
fixVersion |
abUrl |
1.0.0 |
all |
1.0.0.001 |
https://xxx.oss/app/hotfix/all/1.0.0.001 |
1.0.0 |
huawei |
1.0.0.001 |
https://xxx.oss/app/hotfix/huawei/1.0.0.001 |
1.0.0 |
appstore |
1.0.0.001 |
https://xxx.oss/app/hotfix/appstore/1.0.0.001 |
version: The version number that needs to be fixed
channel: The channel number that needs to be repaired. If it is all, it is the repair package for all platforms. If it is other, it is the repair package for the specific channel. Priority is given to judging the channel package of the specific channel number, if not, select the full-platform repair package.
fixVersion: The version number of the fix version
abUrl: The address of the corresponding assetBundle repair package
Precautions
Hot-updated lua code doesn't fit into the development trunk. The next version makes modifications directly on the c# code.
Client update flow chart