示例#1
0
 public Bridge(string id, TimerArgs args, TimerCallBack callBack, TimerCallBack endCallBack)
 {
     Id          = id;
     Args        = args;
     CallBack    = callBack;
     EndCallBack = endCallBack;
 }
示例#2
0
    public static void ResetTimer(TimerCallBack callback, float delay, bool repeat)
    {
        if (callback == null)
        {
            return;
        }

        if (delay <= 0)
        {
            delay = 0.001f;
        }

        foreach (Timer timer in timerList)
        {
            if (callback == timer.CallBack && timer.Enable)
            {
                                #if UNITY_EDITOR
                //Debug.Log("StartTimer callback repeat");
                                #endif
                timer.Repeat = repeat;
                timer.ResetDelay(delay);
                break;
            }
        }
    }
示例#3
0
        /// <summary>
        /// 添加定时器,该定时器不受时间缩放影响
        /// </summary>
        /// <param name="interval">定时器时间间隔</param>
        /// <param name="count">定时器执行次数,0不限次数</param>
        /// <param name="start">定时器开始等待时间</param>
        /// <param name="func">定时器回调方法</param>
        /// <returns></returns>
        public int AddTimer(float interval, int count, float start, TimerCallBack func)
        {
            if (interval < 0 || count < 0 || start < 0)
            {
                Debug.LogError("error add timer args:" + interval + count + start);
                return(0);
            }
            Tick tick = new Tick();

            if (tick == null)
            {
                return(0);
            }
            timerid++;
            tick.tid      = timerid;
            tick.interval = interval;
            tick.start    = unscaledTime + start;
            tick.count    = count;
            tick.cbfunc   = func;
            lock (locker)//锁
            {
                tickDict.Add(tick.tid, tick);
            }
            return(tick.tid);
        }
示例#4
0
 public Timer(TimerType timeType, TimerCallBack callBack)
 {
     this.TimerType = timeType;
     this.CallBack  = callBack;
     this.IsPause   = false;
     this.IsOver    = true;
 }
示例#5
0
 //添加计时器
 public static void AddTimer(string id, int second, TimerCallBack callBack, TimerCallBack endCallBack, float removeDelayMs, bool useDateTime = true)
 {
     if (list.Where(s => s.Id == id).ToList().Count == 0)
     {
         list.Add(new Bridge(id, new TimerArgs(id, second, removeDelayMs, useDateTime), callBack, endCallBack));
     }
 }
示例#6
0
        /// <summary>
        /// 有限次数的重复调用
        /// </summary>
        /// <param name="spaceTime">间隔时间</param>
        /// <param name="isIgnoreTimeScale">是否忽略时间缩放</param>
        /// <param name="callBackCount">重复调用的次数</param>
        /// <param name="callBack">回调函数</param>
        /// <param name="objs">回调函数的参数</param>
        /// <returns></returns>
        public static TimerEvent CallBackOfIntervalTimer(float spaceTime, bool isIgnoreTimeScale, int callBackCount,
                                                         TimerCallBack callBack, params object[] objs)
        {
            return(AddTimer(spaceTime, isIgnoreTimeScale, -1, null, callBack, objs));

            ;
        }
示例#7
0
    /// <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);
    }
    public string AddTimer(int delay, int interval, int executeCount, TimerCallBack timerCallback, bool autoDestroyOnComplete = true, TimerCompleteCallBack timerCompleteCallBack = null)
    {
        // 根据时间获取timerStr
        long   nowTicks    = System.DateTime.Now.Ticks;
        string timerString = nowTicks + "-" + _tmpIndex;

        _tmpIndex++;
        // 初始化timer
        Timer timer = ObjectsPool.GetInstance().GetPoolClassAtPool <Timer>();

        // 基础属性赋值
        timer.timerStr                = timerString;
        timer.delay                   = delay;
        timer.interval                = interval;
        timer.executeTotalCount       = executeCount;
        timer.timerCallBack           = timerCallback;
        timer.isAutoDestroyOnComplete = autoDestroyOnComplete;
        timer.completeCallBack        = timerCompleteCallBack;
        // 初始化
        timer.intervalCount = 0;
        timer.isComplete    = false;
        // 添加到执行列表中
        _timerList.Add(timer);
        _timerCount++;
        _timerDic.Add(timerString, timer);
        return(timerString);
    }
示例#9
0
        /// <summary>
        /// Instantiates a gameobject to have the timedpanel prefab.
        /// </summary>
        /// <param name="countdownFrom">value in seconds to countdown from, after which an optional callback can be invoked.</param>
        /// <param name="callBack">The callback method to execute prior to destrucntion</param>
        /// <param name="heading">Text value for panel heading to dispkay</param>
        /// <param name="description">Text value for the panel's description to display</param>
        /// <returns></returns>
        public static TimedPanel create(float countdownFrom, TimerCallBack callBack, string heading, string description)
        {
            Transform  panelTransform = Instantiate(GameAssets.INSTANCE.timedPanelPrefab, Vector2.zero, Quaternion.identity);
            TimedPanel panel          = panelTransform.GetComponent <TimedPanel>();

            panel.setData(countdownFrom, callBack, heading, description);
            return(panel);
        }
示例#10
0
    /// <summary>
    /// 게임 시작전 준비 시간을 나타내주는 UI 호출
    /// </summary>
    /// <param name="canvas">유니티 부모 Canvas 오브젝트</param>
    /// <param name="time">준비 시간</param>
    /// <param name="callBack">타이머가 끝났을때 호출되는 콜백 함수</param>
    public void CreateStartGameTimer(GameObject canvas, float time, TimerCallBack callBack)
    {
        _startGameTimerLabel = Instantiate(prefStartGameTimerLabel, canvas.transform);
        _startGameTimerText  = _startGameTimerLabel.GetComponentInChildren <Text>();
        _startGameTime       = time;
        _startGameCallBack   = callBack;

        _startGameTimerText.text = time.ToString();
    }
示例#11
0
 public TimerEvent(float next, TimerCallBack callBack, bool isLoop, int id)
 {
     _nextTime   = next;
     _callBack   = callBack;
     _isLoop     = isLoop;
     _id         = id;
     _offsetTime = 0;
     _isDelete   = false;
 }
示例#12
0
        ///
        private void setData(float countdownFrom, TimerCallBack callBack, string heading, string description = "")
        {
            this.countdownFrom = countdownFrom;
            this.callBack      = callBack;

            countdownText.text    = countdownFrom.ToString();
            panelHeading.text     = heading;
            paneldescription.text = description;
        }
示例#13
0
        public Timer(TaskProcesser taskProcesser, int durationMS, TimerCallBack timerCB, object param, bool isRepeat = true)
        {
            this.param   = param;
            this.timerCB = timerCB;

            this.taskProcesser = taskProcesser;
            this.durationMS    = durationMS;
            this.isRepeat      = isRepeat;
        }
示例#14
0
 public void MoveTime(long millis)
 {
     currentMillis += millis;
     if (delegateToExecute != null && executeRunnableMillis <= currentMillis)
     {
         delegateToExecute();
         delegateToExecute= null;
         executeRunnableMillis = 0;
     }
 }
示例#15
0
	/// <summary>
	/// New Timer with the specified host, time and callback.
	/// </summary>
	/// <param name="host">The object to atatch the timer to</param>
	/// <param name="time">Time that the timer runs for in seconds</param>
	/// <param name="callback">Function to call on complete</param>
	public static Timer New(GameObject host, float time, TimerCallBack callback)
	{
		var child = new GameObject ("Timer");
		child.transform.parent = host.transform;

		Timer timer = child.AddComponent<Timer> ();
		timer.callback = callback;
		timer.runTime = time;

		return timer;
	}
示例#16
0
 public void removeAllOfOne(TimerCallBack callBack, bool isReal)
 {
     if (isReal)
     {
         removeAllOfOne(callBack, _timeListReal);
     }
     else
     {
         removeAllOfOne(callBack, _timeList);
     }
 }
示例#17
0
 public float removeEvent(TimerCallBack callBack, int id, bool isReal)
 {
     if (isReal)
     {
         return(removeEvent(callBack, id, _timeListReal, _totalSecondsReal));
     }
     else
     {
         return(removeEvent(callBack, id, _timeList, _totalSeconds));
     }
 }
示例#18
0
 public Timer(TimerCallBack callback, float interval, bool repeat)
 {
     m_elapsed        = 0;
     m_callback       = callback;
     m_callback1      = null;
     m_interval       = interval;
     m_repeat         = repeat;
     m_enable         = true;
     m_callBackArgNum = 0;
     arg1             = null;
 }
示例#19
0
 public Timer(TimerCallBack1 callback, float interval, bool repeat, System.Object arg)
 {
     m_elapsed        = 0;
     m_callback       = null;
     m_callback1      = callback;
     m_interval       = interval;
     m_repeat         = repeat;
     m_enable         = true;
     m_callBackArgNum = 1;
     arg1             = arg;
 }
示例#20
0
        public Timer(TaskProcesser taskProcesser, int durationMS, TimerCallBack timerCB, TaskDataBase param, bool isRepeat = true)
        {
            taskDataType = TaskDataType.TDATA_TIMER;

            this.param   = param;
            this.timerCB = timerCB;

            this.taskProcesser = taskProcesser;
            this.durationMS    = durationMS;
            this.isRepeat      = isRepeat;
        }
    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;
    }
示例#22
0
 public override void OnRelease()
 {
     m_timerName         = "";
     m_repeatCount       = 0;
     m_currentRepeat     = 0;
     m_isIgnoreTimeScale = false;
     m_callBack          = null;
     m_objs         = null;
     m_timerSpace   = 0;;
     m_currentTimer = 0;
     m_isDone       = false;
 }
示例#23
0
    /// <summary>
    /// New Timer with the specified host, time and callback.
    /// </summary>
    /// <param name="host">The object to atatch the timer to</param>
    /// <param name="time">Time that the timer runs for in seconds</param>
    /// <param name="callback">Function to call on complete</param>
    public static Timer New(GameObject host, float time, TimerCallBack callback)
    {
        var child = new GameObject("Timer");

        child.transform.parent = host.transform;

        Timer timer = child.AddComponent <Timer> ();

        timer.callback = callback;
        timer.runTime  = time;

        return(timer);
    }
示例#24
0
    public void register(float next, TimerCallBack cb, int id, bool isLoop, bool isReal)
    {
        TimerEvent ne = new TimerEvent(next, cb, isLoop, id);

        if (isReal)
        {
            register(ne, _timeListReal, _totalSecondsReal);
        }
        else
        {
            register(ne, _timeList, _totalSeconds);
        }
    }
示例#25
0
 public void OnPop()
 {
     m_timerName         = "";
     m_repeatCount       = 0;
     m_currentRepeat     = 0;
     m_isIgnoreTimeScale = false;
     m_callBack          = null;
     m_objs         = null;
     m_timerSpace   = 0;;
     m_currentTimer = 0;
     m_isDone       = false;
     m_isStop       = false;
 }
示例#26
0
    public int AddTimer(float duration, TimerCallBack callBack, bool repeat = false)
    {
        Timer timer = new Timer();

        //   timer.startTime = curTime;
        timer.duration = duration;
        //  timer.endTime = curTime + duration;
        timer.callBack = callBack;
        timer.id       = timerId++;
        timer.enable   = true;
        timer.repeat   = repeat;
        //   timers[timer.id] = timer;
        waitForAdd.Add(timer);
        return(timer.id);
    }
示例#27
0
    private void removeAllOfOne(TimerCallBack callBack, LinkedList <TimerEvent> list)
    {
        LinkedListNode <TimerEvent> node = list.First;

        while (node != null)
        {
            TimerEvent e = node.Value;
            if (e._callBack == callBack)
            {
                e._callBack = null;
                e.delete();
            }
            node = node.Next;
        }
    }
示例#28
0
    public void CreateTimeoutGameTimer(GameObject canvas, float time, TimerCallBack timeoutCallBack)
    {
        if (_elapseGameTimerLabel != null)
        {
            Destroy(_elapseGameTimerLabel);
        }

        _timeoutCallBack      = timeoutCallBack;
        _elapseGameTimerLabel = Instantiate(prefElapseGameTimerLabel, canvas.transform);
        _elapseGameTimerText  = _elapseGameTimerLabel.GetComponentInChildren <Text>();

        _timeoutGameTime          = time;
        _elapseGameTimerText.text = ((int)_timeoutGameTime).ToString();
        _elapseGameTimerLabel.GetComponent <RectTransform>().anchoredPosition = ElapseGameTimerInitPosition;
    }
示例#29
0
    //return the remained time
    private float removeEvent(TimerCallBack callBack, int id, LinkedList <TimerEvent> list, float totalTime)
    {
        LinkedListNode <TimerEvent> node = list.First;

        while (node != null)
        {
            TimerEvent e = node.Value;
            if (e._callBack == callBack && e._id == id)
            {
                e._callBack = null;
                e.delete();
                return(e._targetTime - totalTime);
            }
            node = node.Next;
        }
        return(0);
    }
示例#30
0
    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));
        }
    }
示例#31
0
    public static void StartPauseTimer(TimerCallBack callback, bool state)
    {
        foreach (Timer timer in timerList)
        {
            if ((callback == timer.CallBack && timer.Enable))
            {
                timer.Pause = state;
                test        = callback;
            }
        }

        foreach (Timer timer in addList)
        {
            if (callback == timer.CallBack && timer.Enable)
            {
                timer.Pause = state;
            }
        }
    }
示例#32
0
    /// <summary>
    /// 添加一个Timer
    /// </summary>
    /// <param name="l_spaceTime">间隔时间</param>
    /// <param name="l_isIgnoreTimeScale">是否忽略时间缩放</param>
    /// <param name="l_callBackCount">重复调用的次数</param>
    /// <param name="l_timerName">Timer的名字</param>
    /// <param name="l_callBack">回调函数</param>
    /// <param name="l_objs">回调函数的参数</param>
    /// <returns></returns>
    public static TimerEvent AddTimer(float l_spaceTime, bool l_isIgnoreTimeScale, int l_callBackCount, string l_timerName,TimerCallBack l_callBack, params object[] l_objs)
    {
        TimerEvent l_te = new TimerEvent();

        l_te.m_timerName = l_timerName;

        l_te.m_currentTimer = 0;
        l_te.m_timerSpace = l_spaceTime;

        l_te.m_callBack = l_callBack;
        l_te.m_objs = l_objs;

        l_te.m_isIgnoreTimeScale = l_isIgnoreTimeScale;
        l_te.m_repeatCount = l_callBackCount;

        s_Instance.m_timers.Add(l_te);

        return l_te;
    }
示例#33
0
        /// <summary>
        /// 添加一个Timer
        /// </summary>
        /// <param name="spaceTime">间隔时间</param>
        /// <param name="isIgnoreTimeScale">是否忽略时间缩放</param>
        /// <param name="callBackCount">重复调用的次数</param>
        /// <param name="timerName">Timer的名字</param>
        /// <param name="callBack">回调函数</param>
        /// <param name="objs">回调函数的参数</param>
        /// <returns></returns>
        public static TimerEvent AddTimer(float spaceTime, bool isIgnoreTimeScale, int callBackCount, string timerName,
                                          TimerCallBack callBack, params object[] objs)
        {
            TimerEvent te = new TimerEvent();

            te.m_timerName    = timerName ?? te.GetHashCode().ToString();
            te.m_currentTimer = 0;
            te.m_timerSpace   = spaceTime;

            te.m_callBack = callBack;
            te.m_objs     = objs;

            te.m_isIgnoreTimeScale = isIgnoreTimeScale;
            te.m_repeatCount       = callBackCount;

            m_timers.Add(te);

            return(te);
        }
示例#34
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="currentTime"></param>
 /// <param name="interval"></param>
 /// <param name="callBack"></param>
 public TimerRepeat(float currentTime, float interval, TimerCallBack callBack)
 {
     this.currentTime = currentTime;
     this.interval = interval;
     this.callBack = callBack;
 }
示例#35
0
 public Bridge(string id, TimerArgs args, TimerCallBack callBack, TimerCallBack endCallBack)
 {
     Id = id;
     Args = args;
     CallBack = callBack;
     EndCallBack = endCallBack;
 }
示例#36
0
 //添加计时器
 public static void AddTimer(string id, int second, TimerCallBack callBack, TimerCallBack endCallBack)
 {
     AddTimer(id, second, callBack, endCallBack, 0);
 }
示例#37
0
 //添加计时器
 public static void AddTimer(string id, int second, TimerCallBack callBack, TimerCallBack endCallBack, float removeDelayMs)
 {
     if (list.Where(s => s.Id == id).ToList().Count == 0) {
         list.Add(new Bridge(id, new TimerArgs(id, second, removeDelayMs), callBack, endCallBack));
     }
 }
示例#38
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="currentTime">当前时间</param>
 /// <param name="delayTime">延迟时间</param>
 /// <param name="callBack">回调函数</param>
 public TimerBefore(float currentTime,float delayTime, TimerCallBack callBack)
 {
     this.currentTime = currentTime;
     this.delayTime = delayTime;
     this.callBack = callBack;
 }
示例#39
0
 /// <summary>
 /// 延迟调用
 /// </summary>
 /// <param name="l_delayTime">间隔时间</param>
 /// <param name="l_callBack">回调函数</param>
 /// <param name="l_objs">回调函数的参数</param>
 /// <returns></returns>
 public static TimerEvent DelayCallBack(float l_delayTime,TimerCallBack l_callBack,params object[] l_objs)
 {
     return AddTimer(l_delayTime, false, 0, "", l_callBack, l_objs);
 }
示例#40
0
 /// <summary>
 /// 间隔一定时间重复调用
 /// </summary>
 /// <param name="l_spaceTime">间隔时间</param>
 /// <param name="l_isIgnoreTimeScale">是否忽略时间缩放</param>
 /// <param name="l_timerName">Timer的名字</param>
 /// <param name="l_callBack">回调函数</param>
 /// <param name="l_objs">回调函数的参数</param>
 /// <returns></returns>
 public static TimerEvent CallBackOfIntervalTimer(float l_spaceTime, bool l_isIgnoreTimeScale, string l_timerName,TimerCallBack l_callBack, params object[] l_objs)
 {
     return AddTimer(l_spaceTime, l_isIgnoreTimeScale, -1, l_timerName, l_callBack, l_objs);
 }
示例#41
0
 /// <summary>
 /// 间隔一定时间重复调用
 /// </summary>
 /// <param name="l_spaceTime">间隔时间</param>
 /// <param name="l_callBack">回调函数</param>
 /// <param name="l_objs">回调函数的参数</param>
 /// <returns></returns>
 public static TimerEvent CallBackOfIntervalTimer(float l_spaceTime,TimerCallBack l_callBack, params object[] l_objs)
 {
     return AddTimer(l_spaceTime, false, -1, "", l_callBack, l_objs);
 }
示例#42
0
 /// <summary>
 /// 延迟调用
 /// </summary>
 /// <param name="l_delayTime">间隔时间</param>
 /// <param name="l_isIgnoreTimeScale">是否忽略时间缩放</param>
 /// <param name="l_callBack">回调函数</param>
 /// <param name="l_objs">回调函数的参数</param>
 /// <returns></returns>
 public static TimerEvent DelayCallBack(float l_delayTime, bool l_isIgnoreTimeScale, TimerCallBack l_callBack, params object[] l_objs)
 {
     return AddTimer(l_delayTime, l_isIgnoreTimeScale, 0, "", l_callBack, l_objs);
 }
示例#43
0
 public void CallBack(long howMuchLaterInMillis, TimerCallBack what)
 {
     executeRunnableMillis = howMuchLaterInMillis + currentMillis;
     delegateToExecute = what;
 }
示例#44
0
 /// <summary>
 /// 有限次数的重复调用
 /// </summary>
 /// <param name="l_spaceTime">间隔时间</param>
 /// <param name="l_isIgnoreTimeScale">是否忽略时间缩放</param>
 /// <param name="l_callBackCount">重复调用的次数</param>
 /// <param name="l_callBack">回调函数</param>
 /// <param name="l_objs">回调函数的参数</param>
 /// <returns></returns>
 public static TimerEvent CallBackOfIntervalTimer(float l_spaceTime, bool l_isIgnoreTimeScale, int l_callBackCount, TimerCallBack l_callBack, params object[] l_objs)
 {
     return AddTimer(l_spaceTime, l_isIgnoreTimeScale, -1, "",l_callBack, l_objs); ;
 }