Example #1
0
        public IEnumerator RunRoutine()
        {
            IsBusy             = true;
            Information.Status = UnityBackgroundWorkerStatus.Busy;
            UnityBackgroundWorkerArguments args = new UnityBackgroundWorkerArguments();

            WorkerThread = new Thread(() => WorkMethod(Data, args));
            WorkerThread.IsBackground = true;
            WorkerThread.Start();
            while (WorkerThread.IsAlive)
            {
                yield return(null);

                if (Information.Progress != args.Progress)
                {
                    Information.Progress = args.Progress;
                    ProgressMethod(Data, Information.Progress);
                }
            }
            if (args.HasError)
            {
                Information.ErrorMessage = args.ErrorMessage;
                Information.Status       = UnityBackgroundWorkerStatus.HasError;
            }
            if (Information.Status == UnityBackgroundWorkerStatus.Busy)
            {
                Information.Status = UnityBackgroundWorkerStatus.Done;
            }
            DoneMethod(Data, Information);
            args         = null;
            WorkerThread = null;
            Information  = null;
            Information  = new UnityBackgroundWorkerInformation();
            IsBusy       = false;
        }
Example #2
0
 public UnityBackgroundWorker(MonoBehaviour caller, DoWork DoWorkMethod, ProgressReport ProgressReportMethod, WorkDone WorkDoneMethod, object CustomData)
 {
     Caller         = caller;
     Data           = CustomData;
     Information    = new UnityBackgroundWorkerInformation();
     WorkMethod     = DoWorkMethod;
     ProgressMethod = ProgressReportMethod;
     DoneMethod     = WorkDoneMethod;
 }