Version: Unity 6 Beta (6000.0)
LanguageEnglish
  • C#

Progress

class in UnityEditor

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

The Progress utility class reports the progress of asynchronous tasks to Unity.

The Progress utility class can be used to report progress of asynchronous tasks in multiple ways. Here is an example of a task that runs on the EditorApplication.update loop and reports progress:

using System.Collections;
using UnityEditor;

class ProgressReport_EditorUpdate { static IEnumerator s_CurrentEnumerator;

[MenuItem("Examples/ProgressReport/EditorUpdate")] static void RunEditorUpdate() { if (s_CurrentEnumerator == null) { s_CurrentEnumerator = RunTaskWithReport(); } EditorApplication.update -= RunTaskOnUpdate; EditorApplication.update += RunTaskOnUpdate; }

static void RunTaskOnUpdate() { if (s_CurrentEnumerator == null) { return; }

// Execute one step of the task var atEnd = !s_CurrentEnumerator.MoveNext();

// If there is nothing more to do, remove the update callback if (atEnd) { s_CurrentEnumerator = null; EditorApplication.update -= RunTaskOnUpdate; } }

static IEnumerator RunTaskWithReport() { // Create a new progress indicator int progressId = Progress.Start("Running one task");

// Report the progress status at anytime for (int frame = 0; frame <= 1000; ++frame) { string description; if (frame < 250) description = "First part of the task"; else if (frame < 750) description = "Second part of the task"; else description = "Last part of the task"; Progress.Report(progressId, frame / 1000.0f, description);

// Do your computation that you want to report progress on // ... yield return null; }

// The task is finished. Remove the associated progress indicator. Progress.Remove(progressId); } }

Here is another example of a task that runs on a separate thread and reports progress:

using System.Threading;
using System.Threading.Tasks;
using UnityEditor;

class ProgressReport_Threaded { [MenuItem("Examples/ProgressReport/Threaded")] static void RunThreaded() { Task.Run(RunTaskWithReport); }

static void RunTaskWithReport() { // Create a new progress indicator int progressId = Progress.Start("Running one task");

// Report the progress status at anytime for (int frame = 0; frame <= 1000; ++frame) { string description; if (frame < 250) description = "First part of the task"; else if (frame < 750) description = "Second part of the task"; else description = "Last part of the task"; Progress.Report(progressId, frame / 1000.0f, description);

// Do your computation that you want to report progress on ComputeSlowStep(); }

// The task is finished. Remove the associated progress indicator. Progress.Remove(progressId); }

static void ComputeSlowStep() { // Simulate a slow computation with a 1 millisecond sleep Thread.Sleep(1); } }

Static Properties

globalProgressReturns the global average progression of all running tasks.
globalRemainingTimeReturns the maximum time remaining for all running progress indicators.
runningReturns true if there is at least one running progress indicator, false otherwise.

Static Methods

CancelCancels a runnning progress indicator, and invokes the cancel callback for the associated task.
ClearRemainingTimeResets the computation of a progress indicator's remaining time.
EnumerateItemsReturns an enumerator to loop over all progress indicators.
ExistsChecks whether a progress indicator with the specified ID exists.
FinishMarks the progress indicator as finished.
GetCountGets the number of available progress indicators.
GetCountPerStatusFor each available status, gets the number of progress indicators with that status.
GetCurrentStepGets the current step for a progress indicator.
GetDescriptionGets a progress indicator's description.
GetEndDateTimeGets the timestamp of when the progress indicator ended.
GetIdFinds a progress indicator's unique ID using its index in the set of all available progress indicators.
GetNameGets a progress indicator's name.
GetOptionsGets the options that you specified when you started the progress indicator.
GetParentIdGets the unique ID of the progress indicator's parent, if any.
GetPriorityGets a progress indicator's priority.
GetProgressGets a progress indicator's progress.
GetProgressByIdGets information about a progress indicator.
GetRemainingTimeGets a progress indicator's remaining time, in seconds.
GetRunningProgressCountGets the number of active or running progress indicators.
GetStartDateTimeGets the timestamp of when the progress indicator started.
GetStatusGets the progress indicator's status.
GetStepLabelGets the label that displays a progress indicator's steps.
GetTimeDisplayModeGet a progress indicator's time display mode.
GetTotalStepsGets the total number of steps, from start to finish, for a progress indicator.
GetUpdateDateTimeGets the time that the progress indicator last changed, or finished.
IsCancellableIndicates whether you can cancel the progress indicator's associated task.
IsPausableIndicates whether you can pause the progress indicator's task.
PausePauses a runnning progress indicator, and invokes the pause callback for its task.
RegisterCancelCallbackRegisters a callback that is called when the user requests to cancel a running progress indicator's associated task.
RegisterPauseCallbackRegisters a callback that is called when the user requests to pause or resume a running progress indicator's task.
RemoveFinishes and removes an active progress indicator.
ReportReports a running progress indicator's current status.
ResumeResumes a paused progress indicator, and invokes the pause callback for the associated task.
SetDescriptionSets the progress indicator's description. To clear the description pass null.
SetPrioritySets a progress indicator's priority.
SetRemainingTimeSets the progress indicator's remaining time, in seconds.
SetStepLabelSets the label that displays a progress indicator's steps.
SetTimeDisplayModeSet a progress indicator's time display mode.
ShowDetailsOpens the progress window for background tasks.
StartThis method starts a new progress indicator.
UnregisterCancelCallbackUnregisters a previously registered progress cancellation callback.
UnregisterPauseCallbackUnregisters a previously registered progress pause callback.

Events

addedAn event raised when a new progress indicator starts.
removedAn event raised when a progress indicator is removed.
updatedAn event raised when a progress indicator's state updates.
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961