UE4 Editor Plugin UI - Progress bar
制作UE4 编辑器插件时,可能会遇到非常耗时的任务。如果不想在没有任何提示信息的情况下冻结编辑器窗口,需要添加一个进度条,以便于用户可以跟踪任务的进度,否则用户会认为当前任务可能处于崩溃。
FScopedSlowTask
一个耗时的任务:
for (FString SubFolder : SubFolders)
{
TArray AssetDatasFromPath = FTools::GetAssetsFromPath(SubFolder);
if (AssetDatasFromPath.Num() == 0)
{
AssetRegistryModule.Get().RemovePath(SubFolder);
}
}
进度条的基本用法:
FScopedSlowTask ExplorePathsTask(SelectedPaths.Num(), LOCTEXT("LookingForUnusedAssetsText", "Looking for assets to remove"));
ExplorePathsTask.MakeDialog();
ExploreFoldersTask.EnterProgressFrame();
完整示例:
FScopedSlowTask ExploreFoldersTask(SubFolders.Num(), LOCTEXT("LookingForUnusedAssetsText", "Looking for assets to remove"));
ExploreFoldersTask.MakeDialog();
for (FString SubFolder : SubFolders)
{
ExploreFoldersTask.EnterProgressFrame();
TArray AssetDatasFromPath = FTools::GetAssetsFromPath(SubFolder);
if (AssetDatasFromPath.Num() == 0)
{
AssetRegistryModule.Get().RemovePath(SubFolder);
}
}
More
对于FScopeSlowTask 对象,还可以用于一下情况:
- 可以嵌套耗时的子任务
- 可以设置取消当前任务
- 可以设置任务的进度量
取消当前任务
FScopedSlowTask ExploreFoldersTask(SubFolders.Num(), LOCTEXT("LookingForUnusedAssetsText", "Looking for assets to remove"));
ExploreFoldersTask.MakeDialog(true);
for (FString SubFolder : SubFolders)
{
if(ExploreFoldersTask.ShouldCancel())
break;
ExploreFoldersTask.EnterProgressFrame();
}
指定任务的进度
FScopedSlowTask SlowTask(100.0f, LOCTEXT("SlowTaskText", "Slow Task"));
SlowTask.MakeDialog();
SlowTask.EnterProgressFrame(10.0f);
SlowTask.EnterProgressFrame(35.0f);
SlowTask.EnterProgressFrame(55.0f);
参考
- UE4 – Making a progress bar in the editor
- UE4 Editor Plugin UI
- UE4 Editor Plugin UI - Dialog
|