[Unity3D]Lua中使用协程coroutine和计时器timer

习惯了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

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值