function CoFunc()
print('Coroutine started')
for i = 0, 10, 1 do
print(fib(i))
coroutine.wait(0.1)
end
print("current frameCount: "..Time.frameCount)
coroutine.step()
print("yield frameCount: "..Time.frameCount)
local www = UnityEngine.WWW("http://www.baidu.com")
coroutine.www(www)
local s = tolua.tolstring(www.bytes)
print(s:sub(1, 128))
print('Coroutine ended')
end
lua = new LuaState();
lua.Start();
LuaBinder.Bind(lua);//这个如果不绑定www会出问题 我也不知道为什么
DelegateFactory.Init();
LuaLooper looper = gameObject.AddComponent(); //要用协程必须要有这个LuaLooper
looper.luaState = lua;
启动协程 codelay = coroutine.start(Delay) //其中的Delay 是一个函数 codelay 用来保存协程
停止协程 coroutine.stop(coDelay) 参数是上面启动的保存
等待0.1秒 coroutine.wait(0.1)
等待一帧 coroutine.step() //执行到这后 停止一帧 后再运行
等待 www coroutine.www(www) //和unity 一样










网友评论