xLua——动态热更

作者:追风剑情 发布于:2017-7-17 21:43 分类:Lua

参考 https://github.com/Tencent/xLua/blob/master/Assets/XLua/Doc/hotfix.md

以下代码来自xLua demo

using UnityEngine;
using System.Collections;
using XLua;

[Hotfix]
public class HotfixTest : MonoBehaviour {
    LuaEnv luaenv = new LuaEnv();

    public int tick = 0; //如果是private的,在lua设置xlua.private_accessible(CS.HotfixTest)后即可访问

    // Use this for initialization
    void Start () {
    }

    // Update is called once per frame
    void Update () {
	    if (++tick % 50 == 0)
        {
            Debug.Log(">>>>>>>>Update in C#, tick = " + tick);
        }
	}

    void OnGUI()
    {
        if (GUI.Button(new Rect(10, 100, 300, 150), "Hotfix"))
        {
            luaenv.DoString(@"
                xlua.hotfix(CS.HotfixTest, 'Update', function(self)
                    self.tick = self.tick + 1
                    if (self.tick % 50) == 0 then
                        print('<<<<<<<<Update in lua, tick = ' .. self.tick)
                    end
                end)
            ");
        }
    }
}

运行测试

11111.png

标签: xLua

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号