版权声明:辛辛苦苦写的,转载请注明出处噢 https://blog.csdn.net/wangjiangrong/article/details/83826972
额,好久没写了,感觉有点不务正业。改邪归正改邪归正。
今天正好要热更修复一个问题。需要新建一个IEnumerator 方法来解决,所以我们就要用Lua来实现C#的IEnumerator方法。查阅了下官方的文档,有如下一段描述
一切就都变的简单,假设要热更的类如下
namespace Examples {
public class Hotfix : MonoBehaviour {
void Show() {
Debug.Log("Show!!!");
}
}
}
我们进行热更,在show方法中启动一个协程方法,等待3秒打印一个Log,对应的Lua代码如下:
local util = require "util";
local testLog = function(str)
return util.cs_generator(function()
coroutine.yield(CS.UnityEngine.WaitForSeconds(3))
print("testLog"..str);
end)
end;
util.hotfix_ex(CS.Examples.Hotfix, "Show", function(self)
self:Show();
self:StartCoroutine(testLog("qwer"));
end);
这样就可以用lua实现c#的IEnumerator 方法了。