Unity3d C# Hot Update XLua Plugin Environment Configuration and Getting Started (Hello Word)

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
insert image description here

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.
insert image description here

Use directly

We can add this directory directly on Unity Hub and open the project:
insert image description here

New Construction

You can also create a new project on Unity Hub:
insert image description here

After the new project is completed, copy all the files in the Assets directory to the Assets directory of the new project.
insert image description here

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:
insert image description here
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):

insert image description here

Guess you like

Origin blog.csdn.net/qq_33789001/article/details/123045123