public static void Update() { for (int i = 0; i < s_timeContainer.Count; i++) { TimeContainer timeContainer = s_timeContainer[i]; if (0 == timeContainer.repeat || null == timeContainer.callback) { s_timeContainer.RemoveAt(i); continue; } if (timeContainer.currentTime <= Time.time) { timeContainer.currentTime += timeContainer.interval; timeContainer.repeat = (timeContainer.repeat <= -1) ? -1 : --timeContainer.repeat; timeContainer.callback(timeContainer.timerID, timeContainer.args); } } }
/// <summary> /// 外部调用的Update,检查哪些容器符合条件. /// 不符合条件的删除。 /// </summary> public static void Update() { //遍历所有的容器 for (int i = 0; i < s_timeContainer.Count; i++) { TimeContainer timeContainer = s_timeContainer[i]; //如果重复的次数为0,或者回调函数为空。那么清除此容器。 if (0 == timeContainer.repeat || null == timeContainer.callback) { s_timeContainer.RemoveAt(i); continue; } //叠加的时间符合条件,执行回调函数。并让repeat减1. if (timeContainer.currentTime <= Time.time) { timeContainer.currentTime += timeContainer.interval; timeContainer.repeat = (timeContainer.repeat <= -1) ? -1 : --timeContainer.repeat; timeContainer.callback(timeContainer.timerID, timeContainer.args); } } }