Exemple #1
0
 public static void RunOnMainThread(Action a)
 {
     lock (RunOnMainThreadJobs)
     {
         GJob j = new GJob();
         j.Action = a;
         RunOnMainThreadJobs.Add(j);
     }
 }
Exemple #2
0
 public static void ScheduleOnMainThread(Action a, int order = 10)
 {
     lock (ScheduleOnMainThreadJobs)
     {
         GJob j = new GJob();
         j.Action = a;
         j.Order  = order;
         ScheduleOnMainThreadJobs.Add(j);
     }
 }
Exemple #3
0
        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());
            }
        }