本文将以UE系统的C++层面来阐述工作流程和开发,并非编辑器蓝图制作指南。

UE编辑器蓝图主要提供两种:

  • UEditorUtilityBlueprint
  • UEditorUtilityWidgetBlueprint

一种是UEditorUtilityBlueprint,继承自UBlueprint,主要储存着UEditorUtilityObject和派生类型的实例,绝大部分的编辑器蓝图都是该类型,如常用的可以显示在资产右键菜单的AssetActionUtility,可以显示在场景Actor右键菜单的ActorActionUtility等,这些类型都继承着UEditorUtilityObject类型,并作为UEditorUtilityBlueprint实例存在着。使用该类型需要依赖Blutility模块。

 

另一种是有界面的编辑器蓝图UEditorUtilityWidgetBlueprint,同样继承自UBlueprint,在该类型实例中储存了个UEditorUtilityWidget成员实例,使用该类型不光需要依赖Blutility模块,同时也要引入UMGEditor模块。

 

在UE编辑器API中提供了对编辑器蓝图的一些操作,它们存在于UEditorUtilitySubsystem中,使用GEditor->GetEditorSubsystem<UEditorUtilitySubsystem>() 即可获取到该子系统实例。

对于C++执行以上两种编辑器蓝图有着不同的方法,在执行UEditorUtilityBlueprint时:

FSoftObjectPath ToolSoftPath(TEXT("/Game/Blueprints/Test.Test'"));  
if(UObject* Obj = ToolSoftPath.TryLoad())
{
    auto Subsystem = GEditor->GetEditorSubsystem<UEditorUtilitySubsystem>();
    check(Subsystem);
    Subsystem.TryRun(Obj);
}

当然为了确保正确执行,可以进一步校验该资产的类型,本处假定该路径的资产存在并类型正确。

接下来则是打开UEditorUtilityWidgetBlueprint实例:

FSoftObjectPath ToolSoftPath(TEXT("/Game/Blueprints/TestUI.TestUI'"));  
if(UObject* Obj = ToolSoftPath.TryLoad())
{
    auto Subsystem = GEditor->GetEditorSubsystem<UEditorUtilitySubsystem>();
    check(Subsystem);
    Subsystem.SpawnAndRegisterTab(Obj);
}