public void Step() { EventStepper.active = this; var count = this.passes; while (count > 0) { count -= 1; bool canceled = false; if (this.index != -1) { this.method(this.collection, this.index); float percent = ((float)this.index) / this.collection.Count; canceled = Utility.DisplayCancelableProgressBar(EventStepper.title, EventStepper.message, percent); this.index += 1; } bool loading = Application.isLoadingLevel; bool ended = (this.index > this.collection.Count - 1) || this.index == -1; if ((loading || canceled || ended) && !this.complete) { this.index = -1; this.complete = true; this.onComplete(); EventStepper.instances.Remove(this); Utility.ClearProgressBar(); break; } } EventStepper.active = null; }
public static void AddStepper(string eventName, MethodStep method, IList collection, int passes = 1) { var stepper = new EventStepper(method, null, collection, passes); stepper.onComplete = () => Event.Remove(eventName, stepper.Step); Event.Add(eventName, stepper.Step).SetPermanent(); }