public TimerOverCall m_timeOverCall; //倒计时结束回调 public TimerInfo(int itemID, int Repeats, int TimeInterval, TimerCallBack callBack, TimerOverCall overCall = null) { this.timerID = itemID; this.m_Repeats = Repeats; this.m_TimeInterval = TimeInterval; this.m_Callback = callBack; this.m_timeOverCall = overCall; m_TempTimeVal = 0; stop = false; delete = false; }
static int CreateTimer(IntPtr L) { try { ToLua.CheckArgsCount(L, 6); MTimerManager obj = (MTimerManager)ToLua.CheckObject(L, 1, typeof(MTimerManager)); int arg0 = (int)LuaDLL.luaL_checknumber(L, 2); int arg1 = (int)LuaDLL.luaL_checknumber(L, 3); int arg2 = (int)LuaDLL.luaL_checknumber(L, 4); TimerCallBack arg3 = null; LuaTypes funcType5 = LuaDLL.lua_type(L, 5); if (funcType5 != LuaTypes.LUA_TFUNCTION) { arg3 = (TimerCallBack)ToLua.CheckObject(L, 5, typeof(TimerCallBack)); } else { LuaFunction func = ToLua.ToLuaFunction(L, 5); arg3 = DelegateFactory.CreateDelegate(typeof(TimerCallBack), func) as TimerCallBack; } TimerOverCall arg4 = null; LuaTypes funcType6 = LuaDLL.lua_type(L, 6); if (funcType6 != LuaTypes.LUA_TFUNCTION) { arg4 = (TimerOverCall)ToLua.CheckObject(L, 6, typeof(TimerOverCall)); } else { LuaFunction func = ToLua.ToLuaFunction(L, 6); arg4 = DelegateFactory.CreateDelegate(typeof(TimerOverCall), func) as TimerOverCall; } bool o = obj.CreateTimer(arg0, arg1, arg2, arg3, arg4); LuaDLL.lua_pushboolean(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
/// <summary> /// 创建定时器 /// </summary> /// <param name="timerID">定时器ID</param> /// <param name="Repeats">重复次数</param> /// <param name="TiemInterval">时间间隔</param> /// <param name="call">回调</param> /// <returns></returns> public bool CreateTimer(int timerID, int Repeats, float TiemInterval, TimerCallBack call, TimerOverCall overCall = null) { TimerInfo timeInfo = null; lock (m_TimerManager) { if (m_TimerManager.TryGetValue(timerID, out timeInfo) && timeInfo != null) { timeInfo.m_Repeats = Repeats; timeInfo.m_TimeInterval = TiemInterval; timeInfo.m_Callback = call; timeInfo.m_timeOverCall = overCall; timeInfo.m_TempTimeVal = 0; return(true); } } timeInfo = new TimerInfo(timerID, Repeats, TiemInterval, call, overCall); lock (m_TimerManager) { m_TimerManager.Add(timerID, timeInfo); } StartTimer(timeInfo.m_TimeInterval); return(true); }