[关闭]
@daaoling 2017-01-08T07:45:30.000000Z 字数 1148 阅读 1816

Xlua 热更新

Xlua Hot Fix

quick start

Define Target Class

  1. [Hotfix]
  2. public class HotfixTest : MonoBehaviour {
  3. LuaEnv luaenv = new LuaEnv();
  4. public int tick = 0; //如果是private的,在lua可以用反射来访问
  5. // Update is called once per frame
  6. void Update () {
  7. if (++tick % 50 == 0)
  8. {
  9. Debug.Log(">>>>>>>>Update in C#, tick = " + tick);
  10. }
  11. }
  12. }

How to fix

  1. void OnGUI()
  2. {
  3. if (GUI.Button(new Rect(10, 100, 300, 150), "Hotfix"))
  4. {
  5. luaenv.DoString(@"
  6. xlua.hotfix(CS.HotfixTest, 'Update', function(self)
  7. self.tick = self.tick + 1
  8. if (self.tick % 50) == 0 then
  9. print('<<<<<<<<Update in lua, tick = ' .. self.tick)
  10. end
  11. end)
  12. ");
  13. }
  14. }

Support

函数/变量(属性,事件)

now issue

请问 hotfix 子类中重载父类的方法
https://github.com/Tencent/xLua/issues/35

  1. 父类中有个
  2. public virtual void Awake()
  3. {
  4. Debug.Log("name" + gameObject.name);
  5. }
  6. 子类中重载:
  7. public override void Awake()
  8. {
  9. base.Awake();
  10. Debug.Log("testpanel awake===");
  11. }
  12. 我在hotfix 这个子类的Awake时:
  13. xlua.hotfix(CS.TestPanel, 'Awake', function()
  14. print('<<<<<<<<Awake in lua')
  15. end)
  16. 这里,有什么办法还可以执行到父类的Awake
  17. 目前没提供。。hotfix的话,你把父类逻辑也在lua实现就可以了。
  18. 就是在hotfix的时候把父类的这个方法里面的逻辑也写到Lua里面?以后会有提供么?
  19. 想了下,貌似很难用很常规的办法提供。
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注