Exemplo n.º 1
0
    /// <summary>
    /// 添加一个定时器
    /// </summary>
    /// <param name="trigger"></param>
    /// <param name="callback"></param>
    /// <returns></returns>
    public int AddTimerEvent(int trigger, TimerTriggerCallback callback)
    {
        int         guid     = GetGuid();
        TimerObject timerObj = new TimerObject(guid, 0, -1, trigger, callback);

        TimerList.Add(timerObj);
        return(guid);
    }
Exemplo n.º 2
0
 public TimerObject(int guid, int st, int et, int tt, TimerTriggerCallback callback)
 {
     Guid        = guid;
     startTick   = st;
     endTick     = et;
     curTick     = st;
     triggerTick = tt;
     Callback    = callback;
     delta       = 0;
     isOver      = false;
     running     = true;
 }
Exemplo n.º 3
0
 public TimerObject(int guid, int st, int et, int tt, TimerTriggerCallback callback)
 {
     this.Guid        = guid;
     this.startTick   = st;
     this.endTick     = et;
     this.curTick     = st;
     this.triggerTick = tt;
     this.callback    = callback;
     this.pause       = false;
     this.isOver      = false;
     this.oldTick     = st;
 }
Exemplo n.º 4
0
    public static Delegate TimerTriggerCallback(LuaFunction func)
    {
        TimerTriggerCallback d = (param0) =>
        {
            int    top = func.BeginPCall();
            IntPtr L   = func.GetLuaState();
            LuaScriptMgr.PushObject(L, param0);
            func.PCall(top, 1);
            func.EndPCall(top);
        };

        return(d);
    }
Exemplo n.º 5
0
        /// <summary>
        /// 注册一个定时器;
        /// </summary>
        public int RegisterTimerEx(int start, int end, int trigger, TimerTriggerCallback callback, bool startTrigger = true)
        {
            int         guid     = GetGuid();
            TimerObject timerObj = new TimerObject(guid, start * 1000, end * 1000, trigger * 1000, callback);

            TimerList.Add(timerObj);
            if (startTrigger)
            {
                //第一次触发一下;
                callback(timerObj);
            }
            return(guid);
        }
Exemplo n.º 6
0
    /// <summary>
    /// 添加一个定时器;
    /// </summary>
    /// <param name="name"></param>
    /// <param name="o"></param>
    public int AddTimerEvent(int start, int end, int trigger, TimerTriggerCallback callback, bool startTrigger = false)
    {
        int         guid     = GetGuid();
        TimerObject timerObj = new TimerObject(guid, start, end, trigger, callback);

        TimerList.Add(timerObj);
        if (startTrigger)
        {
            //第一次触发一下;
            callback(timerObj);
        }
        return(guid);
    }
Exemplo n.º 7
0
    static int AddTimerEvent(IntPtr L)
    {
        int count = LuaDLL.lua_gettop(L);

        if (count == 2)
        {
            TimerManager obj  = (TimerManager)LuaScriptMgr.GetUnityObjectSelf(L, 1, "TimerManager");
            TimerObject  arg0 = (TimerObject)LuaScriptMgr.GetNetObject(L, 2, typeof(TimerObject));
            obj.AddTimerEvent(arg0);
            return(0);
        }
        else if (count == 3)
        {
            TimerManager         obj       = (TimerManager)LuaScriptMgr.GetUnityObjectSelf(L, 1, "TimerManager");
            int                  arg0      = (int)LuaScriptMgr.GetNumber(L, 2);
            TimerTriggerCallback arg1      = null;
            LuaTypes             funcType3 = LuaDLL.lua_type(L, 3);

            if (funcType3 != LuaTypes.LUA_TFUNCTION)
            {
                arg1 = (TimerTriggerCallback)LuaScriptMgr.GetNetObject(L, 3, typeof(TimerTriggerCallback));
            }
            else
            {
                LuaFunction func = LuaScriptMgr.GetLuaFunction(L, 3);
                arg1 = (param0) =>
                {
                    int top = func.BeginPCall();
                    LuaScriptMgr.PushObject(L, param0);
                    func.PCall(top, 1);
                    func.EndPCall(top);
                };
            }

            int o = obj.AddTimerEvent(arg0, arg1);
            LuaScriptMgr.Push(L, o);
            return(1);
        }
        else if (count == 6)
        {
            TimerManager         obj       = (TimerManager)LuaScriptMgr.GetUnityObjectSelf(L, 1, "TimerManager");
            int                  arg0      = (int)LuaScriptMgr.GetNumber(L, 2);
            int                  arg1      = (int)LuaScriptMgr.GetNumber(L, 3);
            int                  arg2      = (int)LuaScriptMgr.GetNumber(L, 4);
            TimerTriggerCallback arg3      = null;
            LuaTypes             funcType5 = LuaDLL.lua_type(L, 5);

            if (funcType5 != LuaTypes.LUA_TFUNCTION)
            {
                arg3 = (TimerTriggerCallback)LuaScriptMgr.GetNetObject(L, 5, typeof(TimerTriggerCallback));
            }
            else
            {
                LuaFunction func = LuaScriptMgr.GetLuaFunction(L, 5);
                arg3 = (param0) =>
                {
                    int top = func.BeginPCall();
                    LuaScriptMgr.PushObject(L, param0);
                    func.PCall(top, 1);
                    func.EndPCall(top);
                };
            }

            bool arg4 = LuaScriptMgr.GetBoolean(L, 6);
            int  o    = obj.AddTimerEvent(arg0, arg1, arg2, arg3, arg4);
            LuaScriptMgr.Push(L, o);
            return(1);
        }
        else
        {
            LuaDLL.luaL_error(L, "invalid arguments to method: TimerManager.AddTimerEvent");
        }

        return(0);
    }
Exemplo n.º 8
0
 public int RegisterTimer(float start, float end, float trigger, TimerTriggerCallback callback, bool startTrigger = true)
 {
     return(RegisterTimerEx((int)start, (int)end, (int)trigger, callback, startTrigger));
 }