public string RegisterPersistentTimer(PersistentTimer timer, bool restore = false) { if (timer == null) { return(string.Empty); } timer.Obsolete = false; timer.SetConditions(restore); persisitentTimers.Add(timer); return(timer.Id); }
private void OnDisable() { if (persisitentTimers.Count > 0) { foreach (var timer in persisitentTimers) { PersistentTimer p = timer as PersistentTimer; if (p != null) { p.Save(); } } } }
private void TicToc(List <CountdownTimer> timers, float deltaTime) { // Iterate the list in reverse order so that callback implementations may add new timers. for (int i = timers.Count - 1; i >= 0; i--) { if (timers[i].Scope != CountdownScope.Level || !levelPaused) { timers[i].Remaining -= deltaTime; if (timers[i].PercentCallback != null) { // An arbitrary performance trick if (timers[i].Remaining <= 0 || Time.frameCount % tickPeriod == 0) { timers[i].PercentCallback(timers[i].Id, (timers[i].Duration - MathUtility.Clamp(timers[i].Remaining, 0f, timers[i].Duration)) / timers[i].Duration); } } PersistentTimer p = timers[i] as PersistentTimer; if (p != null && p.SecondCallback != null) { var sec = Mathf.FloorToInt(p.Remaining); sec = sec < 0 ? 0 : sec; if (sec != p.RemainingWholeSecs) { p.SetWholeSecs(sec); p.SecondCallback(p.Id, p.RemainingWholeSecs); } } if (timers[i].Remaining <= 0 && !timers[i].Obsolete) { timers[i].Obsolete = true; callbacks.Add(timers[i]); } } } timers.RemoveAll(item => item.Obsolete == true); for (int c = 0; c < callbacks.Count; c++) { callbacks[c].Callback(callbacks[c].Id); } callbacks.Clear(); }