Пример #1
0
 /// <summary>
 /// 注册一个定时器;
 /// </summary>
 public void RegisterTimer(TimerObject timerObj)
 {
     if (!TimerList.Contains(timerObj))
     {
         TimerList.Add(timerObj);
     }
 }
Пример #2
0
 /// <summary>
 /// 删除一个定时器;
 /// </summary>
 public void RemoverTimer(TimerObject timerObj)
 {
     if (TimerList.Contains(timerObj))
     {
         TimerList.Remove(timerObj);
     }
 }
Пример #3
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);
        }
Пример #4
0
        /// <summary>
        /// 获取一个定时器;
        /// </summary>
        public TimerObject GetTimerObject(int guid)
        {
            TimerObject tobeRemObj = null;

            for (int i = 0; i < TimerList.Count; ++i)
            {
                TimerObject to = TimerList[i];
                if (to.TimerGuid == guid)
                {
                    tobeRemObj = to;
                    break;
                }
            }

            return(tobeRemObj);
        }
Пример #5
0
        /// <summary>
        /// 删除一个定时器;
        /// </summary>
        public TimerObject RemoverTimer(int guid)
        {
            TimerObject tobeRemObj = null;

            for (int i = 0; i < TimerList.Count; ++i)
            {
                TimerObject to = TimerList[i];
                if (to.TimerGuid == guid)
                {
                    tobeRemObj = to;
                    break;
                }
            }

            if (tobeRemObj != null)
            {
                TimerList.Remove(tobeRemObj);
            }

            return(tobeRemObj);
        }
Пример #6
0
        /// <summary>
        /// 定时器更新;
        /// </summary>
        public void UpdateAllTimers(float tick)
        {
            int iTick = (int)(tick * 1000);

            for (int i = 0; i < TimerList.Count; ++i)
            {
                TimerObject to = TimerList[i];
                if (to.UpdateTick(iTick))
                {
                    removeList.Add(to);
                }
            }

            for (int i = 0; i < removeList.Count; ++i)
            {
                TimerObject toRem = removeList[i];
                TimerList.Remove(toRem);
            }

            removeList.Clear();
        }