private static void Tick() { try { if (RunOnMainThreadJobs.Count > 0) { RunOnMainThreadJobs.RemoveAll(j => j == null || j.Action == null); for (int i = 0; i < RunOnMainThreadJobs.Count; ++i) { GJob j = RunOnMainThreadJobs[i]; j.Run(); } RunOnMainThreadJobs.Clear(); } } catch (System.Exception e) { Debug.Log("Error on job scheduling: " + e.ToString()); RunOnMainThreadJobs = new List <GJob>(); } try { if (ScheduleOnMainThreadJobs.Count > 0) { ScheduleOnMainThreadJobs.RemoveAll(j => j == null || j.Action == null); if (ScheduleOnMainThreadJobs.Count > 0) { ScheduleOnMainThreadJobs.Sort((j0, j1) => - j0.Order.CompareTo(j1.Order)); int lastJobIndex = ScheduleOnMainThreadJobs.Count - 1; ScheduleOnMainThreadJobs[lastJobIndex].Run(); ScheduleOnMainThreadJobs[lastJobIndex] = null; } } } catch (System.Exception e) { ScheduleOnMainThreadJobs = new List <GJob>(); Debug.Log("Error on job scheduling: " + e.ToString()); } }