13using System.Collections.Generic;
14using System.Diagnostics;
46 public static readonly EditorProgressView Single =
new EditorProgressView();
49 EditorUtility.ClearProgressBar();
52 public void DisplayProgress(
string title,
string info,
float progress) {
53 EditorUtility.DisplayProgressBar(title, info, progress);
67 private List<int> chunks =
new List<int>();
68 private List<int> progress =
new List<int>();
69 private List<string> titleStrings =
new List<string>();
70 private List<string> infoStrings =
new List<string>();
71 private Stopwatch stopwatch =
new Stopwatch();
73 private bool _forceUpdate;
84 public ProgressBar() :
this(EditorProgressView.Single) { }
109 public void Begin(
int sections,
string title,
string info, Action action) {
110 if (!stopwatch.IsRunning) {
115 chunks.Add(sections);
117 titleStrings.Add(title);
118 infoStrings.Add(info);
124 int lastIndex = chunks.Count - 1;
125 chunks.RemoveAt(lastIndex);
126 progress.RemoveAt(lastIndex);
127 titleStrings.RemoveAt(lastIndex);
128 infoStrings.RemoveAt(lastIndex);
131 if (lastIndex >= 0) {
132 progress[lastIndex]++;
135 if (chunks.Count == 0) {
147 public void Step(
string infoString =
"") {
148 progress[progress.Count - 1]++;
149 if (stopwatch.ElapsedMilliseconds > 17 || _forceUpdate) {
150 displayBar(infoString);
156 private void displayBar(
string info =
"") {
157 _forceUpdate =
false;
159 float percent = 0.0f;
160 float fraction = 1.0f;
161 string titleString =
"";
162 string infoString =
"";
163 for (
int i = 0; i < chunks.Count; i++) {
164 float chunkSize = chunks[i];
165 float chunkProgress = progress[i];
167 percent += fraction * (chunkProgress / chunkSize);
168 fraction /= chunkSize;
170 titleString += titleStrings[i];
171 infoString += infoStrings[i];
This class allows you to easily give feedback of an action as it completes.
ProgressBar(IProgressView view)
Constructs a new progress bar given a progress view object that will display the progress information...
void Begin(int sections, string title, string info, Action action)
Begins a new chunk. If this call is made from within a chunk it will generate a sub-chunk that repres...
void Step(string infoString="")
Steps through one section of the current chunk. You can provide an optional info string that will be ...
This interface describes a generic way to update the progress of an action.
void Clear()
Clears the progress view. Is called if the action has been completed or canceled.
void DisplayProgress(string title, string info, float progress)
Updates the progress view with some title text, information, and a progress percentage that ranges fr...