public static void DisplayProgressBar (string title, string info, float progress);

Description

显示或更新进度条。

窗口标题将设置为 /title/,信息将设置为 /info/。 进度应设置为 0.0 和 1.0 之间的一个值,0 表示一点儿也没有完成,1.0 表示完成 100%。

如果您在编辑器脚本或向导中执行任何冗长的运算 ,并希望通知用户相应进度,这非常有用。

另请参阅:DisplayCancelableProgressBarClearProgressBar 函数。


Progress bar in the editor.

using UnityEditor;
using UnityEngine;
using System.Collections;

// Simple Editor Script that fills a bar in the given seconds. public class EditorUtilityDisplayProgressBar : EditorWindow { public float secs = 10f; public float startVal = 0f; public float progress = 0f; [MenuItem("Examples/Progress Bar Usage")] static void Init() { UnityEditor.EditorWindow window = GetWindow(typeof(EditorUtilityDisplayProgressBar)); window.Show(); }

void OnGUI() { secs = EditorGUILayout.FloatField("Time to wait:", secs); if (GUILayout.Button("Display bar")) { if (secs < 1) { Debug.LogError("Seconds should be bigger than 1"); return; } startVal = (float)EditorApplication.timeSinceStartup; } if (progress < secs) EditorUtility.DisplayProgressBar("Simple Progress Bar", "Shows a progress bar for the given seconds", progress / secs); else EditorUtility.ClearProgressBar(); progress = (float)(EditorApplication.timeSinceStartup - startVal); }

void OnInspectorUpdate() { Repaint(); } }