ScriptReference/EditorUtility.DisplayCancelableProgressBar #108
Replies: 2 comments
-
|
Comment by Dave Smeathers:
It returns true when cancel is pressed. |
Beta Was this translation helpful? Give feedback.
-
|
Comment by A good way to use this is using Exceptions to your advantage. public class Abort() : System.Exception {}
public void Process()
{
EditorUtility.ShowProgressBar("Title", "Doing Stuff", 0f);
try
{
ProcessAssets();
}
catch(Abort)
{
// The user hit cancel. Nothing to do here.
}
catch(Exception e)
{
// We got an an exception so lets handle it.
}
finally
{
// If we get an exception or the user cancels we always clear our progress bar
EditorUtility.ClearProgressBar();
}
}
private void ProcessAssets()
{
// Complex code
if (EditorUtility.DisplayCancelableProgressBar("Title", "Doing Stuff", 0f))
{
throw new Abort();
}
// Other complex code
}Having the finally block makes sure that we always clear the progress bar when we are done. If we were to get an exception while doing our process the loading bar would stick around forever and the user would have to restart Unity. Throwing our own Abort exception allows us to break at any point and not log errors to the console. using (var progressBar = new ScopedProgressBar("MyOp")) { }Like this EditorScopedProgressBar by SoylentGraham |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
ScriptReference/EditorUtility.DisplayCancelableProgressBar
https://docs.unity3d.com/ScriptReference/EditorUtility.DisplayCancelableProgressBar.html
Beta Was this translation helpful? Give feedback.
All reactions