Exemplo n.º 1
0
        public static void ClearProgressBar()
        {
            if (UnityThread.allowsAPI)
            {
                EditorUtility.ClearProgressBar();
            }

            BackgroundProgress.Clear();
        }
Exemplo n.º 2
0
 public static void DisplayProgressBar(string title, string info, float progress)
 {
     if (UnityThread.allowsAPI)
     {
         EditorUtility.DisplayProgressBar(title, info, progress);
     }
     else
     {
         BackgroundProgress.Report(title, progress);
     }
 }
Exemplo n.º 3
0
        private static void Work()
        {
            while (true)
            {
                Action task      = null;
                var    remaining = 0;

                lock (queue)
                {
                    if (queue.Count > 0)
                    {
                        remaining = queue.Count;
                        task      = queue.Dequeue();
                    }
                }

                if (task != null)
                {
                    BackgroundProgress.Report($"{remaining} task{(queue.Count > 1 ? "s" : "")} remaining...", 0);

                    try
                    {
                        task();
                    }
                    catch (Exception ex)
                    {
                        EditorApplication.delayCall += () => Debug.LogException(ex);
                    }
                    finally
                    {
                        BackgroundProgress.Clear();
                    }
                }
                else
                {
                    Thread.Sleep(100);
                }
            }
        }
Exemplo n.º 4
0
        private void RunSynchronous(Task task)
        {
            threadTracker.Enter();

#if USE_PROGRESS_API
            // TODO: Improve TaskThreadTracker to track the actual task objects per thread,
            // which would allow us to use the progressItemId of the latest task on the current
            // thread as a parentId in Progress.Start.

            task.progressItemId = Progress.Start(task.title, task.currentStepLabel);

            EditorApplication.CallbackFunction reportDelegate = () => ReportTaskOnEditorUpdate(task);

            EditorApplication.update += reportDelegate;
#else
            BackgroundProgress.Report(task.title, 0);
#endif

            task.Begin();

#if USE_PROGRESS_API
            var status = Progress.Status.Running;
#endif

            try
            {
                task.Run();

#if USE_PROGRESS_API
                status = Progress.Status.Succeeded;
#endif
            }
            catch (ThreadAbortException)
            {
#if USE_PROGRESS_API
                status = Progress.Status.Canceled;
#endif
            }
            catch (OperationCanceledException)
            {
#if USE_PROGRESS_API
                status = Progress.Status.Canceled;
#endif
            }
            catch (TargetInvocationException tiex) when(tiex.InnerException is OperationCanceledException ||
                                                        tiex.InnerException is ThreadAbortException)
            {
#if USE_PROGRESS_API
                status = Progress.Status.Canceled;
#endif
            }
            catch
            {
#if USE_PROGRESS_API
                status = Progress.Status.Failed;
#endif

                throw;
            }
            finally
            {
                task.End();

#if USE_PROGRESS_API
                Progress.Finish(task.progressItemId, status);
                task.progressItemId       = -1;
                EditorApplication.update -= reportDelegate;
#else
                BackgroundProgress.Clear();
#endif

                threadTracker.Exit();
            }
        }
Exemplo n.º 5
0
        public void Report(Task task)
        {
#if !USE_PROGRESS_API
            BackgroundProgress.Report(task.currentStepLabel ?? task.title, task.ratio);
#endif
        }