foreword
At present, hot updates are still relatively popular in China. Company leaders require that all kinds of trivial projects must be hot updated. . . At present, the main mainstream method is lua (slua, tolua, xlua). After querying for a period of time, I plan to learn some open source XLua from TX manufacturers.
Environment configuration
The environment of Unity is not mentioned here, and Unity3d 2020 is used by default. Version 3.12f1c1.
download
XLua plugin download address: https://github.com/Tencent/xLua/releases
Click on any version to download.
Lua Engineering
After the download is complete, unzip it, and you will get a demo project as shown in the figure.
Use directly
We can add this directory directly on Unity Hub and open the project:
New Construction
You can also create a new project on Unity Hub:
After the new project is completed, copy all the files in the Assets directory to the Assets directory of the new project.
HelloWord
Open the scene Helloworld.unity in the \Assets\XLua\Examples\01_Helloworld directory
Helloworld.cs:
public class Helloworld : MonoBehaviour
{
// Use this for initialization
void Start()
{
LuaEnv luaenv = new LuaEnv();
luaenv.DoString("CS.UnityEngine.Debug.Log('hello world')");
luaenv.Dispose();
}
// Update is called once per frame
void Update()
{
}
}
After running, you can see the output effect of lua calling the Debug.Log function:
this way, with the help of XLua, you can easily call C#.
Summarize
I feel that it is relatively simple and convenient to get started quickly. After building the project, you can use xlua, but it is still a long way to build a complete set of hot update architecture.
It is recommended to check the documentation first (Assets\XLua\Doc):