/// <summary> /// 计时器运行 /// </summary> void Run() { if (TimerList.Count == 0) { return; } for (int i = 0; i < TimerList.Count; i++) { TimerObject o = TimerList[i]; if (o.Pause) { continue; } // 正常计时 间隔回调 if (o.StartTick <= o.EndTick) { o.CurTick += 1; if ((o.CurTick - o.OldTick) == o.TriggerTick) { o.CallBack(o); o.OldTick = o.CurTick; } if (o.CurTick >= o.EndTick) { o.IsOver = true; } } else// 倒计时 间隔回调 { o.CurTick -= 1; if ((o.OldTick - o.CurTick) == o.TriggerTick) { o.CallBack(o); o.OldTick = o.CurTick; } if (o.CurTick <= o.EndTick) { o.IsOver = true; } } // 在规定时间触发一次回调 if (-1 == o.EndTick) { o.CurTick += 1; if (o.CurTick == o.TriggerTick) { o.CallBack(o); o.IsOver = true; } } if (o.IsOver) { RemoveList.Add(o); } } for (int i = 0; i < RemoveList.Count; i++) { TimerObject o = RemoveList[i]; TimerList.Remove(o); } RemoveList.Clear(); }