Skip to content

Instantly share code, notes, and snippets.

@nicoplv
Created January 18, 2023 13:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicoplv/9e4b56d490da2959ee600e920e740e3e to your computer and use it in GitHub Desktop.
Save nicoplv/9e4b56d490da2959ee600e920e740e3e to your computer and use it in GitHub Desktop.
An helper to be able to use the Unity Progress Bar with background or async operations
[UnityEditor.InitializeOnLoad]
public class ProgressBarHelper
{
#region Methods
protected static List<Action> actions = new List<Action>();
static ProgressBarHelper()
{
UnityEditor.EditorApplication.update += Update;
}
private static void Update()
{
while(actions.Count > 0)
{
actions[0].Invoke();
actions.RemoveAt(0);
}
}
public static void DisplayProgressBar(string _title, string _description, float _progress)
{
actions.Add(() => EditorUtility.DisplayProgressBar(_title, _description, _progress));
}
public static void ClearProgressBar()
{
actions.Add(() => EditorUtility.ClearProgressBar());
}
#endregion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment