示例
using UnityEngine;
using System.Collections;
using XLua;
namespace Hotfix {
[Hotfix]
public class LuaManager : MonoBehaviour {
private LuaEnv luaenv;
private int tick = 0;
void Awake()
{
luaenv = new LuaEnv();
}
void OnDestroy()
{
luaenv = null;
}
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"))
{
//Lua代码中需要加入这句才能访问私有变量
//xlua.private_accessible(CS.Hotfix.LuaManager)
//注意: 不能对没有的C#方法进行热更
luaenv.DoString(@"
xlua.private_accessible(CS.Hotfix.LuaManager)
xlua.hotfix(CS.Hotfix.LuaManager, 'Update', function(self)
self.tick = self.tick + 1
if (self.tick % 50) == 0 then
print('<<<<<<<<Update in lua, tick = ' .. self.tick)
end
end)
");
}
}
}
}
运行测试