[Unity3D]Lua中使用协程coroutine和计时器timer
2014-08-22 23:57
363 查看
习惯了unity3d的协程用法,那么我们在Unity里面怎么使用:
StartCoroutine
StopCoroutine
WaitForSeconds
首先lua也有coroutine,其实lua中的协程真的是暂停,用法和unity并非相同的概念,我的母的实现就是为了在lua中使用上述和c#统一的协程接口类。
在C#端需要写一个接口缓存lua的function并且对其进行计时回调lua的coroutine继续执行或者让这个协程‘dead’掉。
组合成2个计时器执行某个方法:
local gm = {}
function gm.startTimer(name,delayTime,func)
local one = CreateCoroutine(function (this,name,func)
if not WaitForSeconds(this,delayTime,name) then return end
if func~=nil then func() end
end)
StartCoroutine(one,name,func)
end
function gm.stopTimer(name)
StopCoroutine(name)
end
return gm
具体使用例子:
GM.startTimer('Chiuan',1.0,function ( )
Debug.Log('hello chiuan.')
end)
--GM.stopTimer('Chiuan')
最后,具体怎么实现还是直接贴上源码 + demo吧。 http://game.ceeger.com/forum/read.php?tid=18475&fid=16
StartCoroutine
StopCoroutine
WaitForSeconds
首先lua也有coroutine,其实lua中的协程真的是暂停,用法和unity并非相同的概念,我的母的实现就是为了在lua中使用上述和c#统一的协程接口类。
在C#端需要写一个接口缓存lua的function并且对其进行计时回调lua的coroutine继续执行或者让这个协程‘dead’掉。
组合成2个计时器执行某个方法:
local gm = {}
function gm.startTimer(name,delayTime,func)
local one = CreateCoroutine(function (this,name,func)
if not WaitForSeconds(this,delayTime,name) then return end
if func~=nil then func() end
end)
StartCoroutine(one,name,func)
end
function gm.stopTimer(name)
StopCoroutine(name)
end
return gm
具体使用例子:
GM.startTimer('Chiuan',1.0,function ( )
Debug.Log('hello chiuan.')
end)
--GM.stopTimer('Chiuan')
最后,具体怎么实现还是直接贴上源码 + demo吧。 http://game.ceeger.com/forum/read.php?tid=18475&fid=16
相关文章推荐
- [Unity3D]Lua中使用协程coroutine和计时器timer
- 在 ASP.NET 中使用计时器(Timer)
- 在 ASP.NET 中使用计时器(Timer)
- [转]Java计时器Timer 使用
- Timer 计时器的初步使用(实现渐入效果)
- Java计时器Timer 使用
- 在 ASP.NET 中使用计时器(Timer)
- 在Java中怎么使用定时服务计时器Timer 处理隔断执行问题
- Java计时器Timer 使用1 (转)
- ASP.NET中使用计时器(Timer)来实现群发邮件等功能
- Java计时器Timer的使用!...
- 在 ASP.NET 中使用计时器(Timer)的整理
- 在ASP.NET中使用计时器(Timer)
- Silverlight2.0中的计时器类DispatcherTimer——不再使用Storyboard计时器
- Java计时器Timer 使用 完整案例(转)
- 在 ASP.NET 中使用计时器(Timer)的整理(2003/10/23 20:36)
- 在 ASP.NET 中使用计时器(Timer)(2003/10/23 20:06)
- 在 ASP.NET 中使用计时器(Timer)
- ASP.NET中使用计时器(Timer)(转)
- 在 ASP.NET 中使用计时器(Timer)转