예제 #1
0
        private static string AddTimeModel(long delayTime, int intervalTime, int loopTime, Action callBack)
        {
            string     key   = callBack.Target.ToString() + callBack.Method.Name;
            TimerModel model = GetTimerModel(key);

            if (model != null)
            {
                Debug.LogError("重复的计时器》》》》》" + key);
                return(key);
            }

            model = new TimerModel(key, GetCurrMillisecond() + delayTime, intervalTime, loopTime, callBack);
            timeList.Add(model);

            if (timer.Enabled == false)
            {
                timer.Start();
            }
            return(key);
        }
예제 #2
0
        private static void TimerCallBack(object obj, ElapsedEventArgs e)
        {
            for (int i = 0; i < timeList.Count; i++)
            {
                TimerModel tim = timeList[i];
                //到时间了
                if (tim.Time <= GetCurrMillisecond())
                {
                    tim.Run();
                    //一直循环
                    if (tim.LoopTimes == -1)
                    {
                        //更新时间
                        tim.Time = GetCurrMillisecond() + tim.IntervalTime;
                    }
                    else
                    {
                        tim.LoopTimes--;
                        if (tim.LoopTimes <= 0)
                        {
                            timeList.RemoveAt(i);
                        }
                        else
                        {
                            //更新时间
                            tim.Time = GetCurrMillisecond() + tim.IntervalTime;
                        }
                    }
                }
            }

            if (timeList.Count <= 0)
            {
                timer.Stop();
            }
        }