编辑器图表添加通用命令
在之前创建的编辑器中,复制、粘贴、删除节点的操作无法完成,其原因是需要给编辑器添加FUICommandList类用于管理节点操作的通用命令。
为了方便,参考行为树状态机的实现,直接令我们的状态机编辑器继承一个FAIGraphEditor,该类封装了对节点操作的常用命令。
修改StateMachineEditor,继承自FAIGraphEditor,关键是在创建Graph前调用CreateCommandList(),并将UpdateGraphEdPtr的值设为当前的图表。
- StateMachineEditor.h
class STATEMACHINEEDITOR_API FStateMachineEditor : public FWorkflowCentricApplication, public FAIGraphEditor, public FNotifyHook
加入一个函数给FStateMachineGraphTabFactory获取GraphEditorCommands。
TSharedPtr<FUICommandList> GetGraphEditorCommands() {
return GraphEditorCommands; }
然后在cpp中创建命令,并将UpdateGraphEdPtr设为我们的节点编辑图表。
- StateMachineEditor.cpp
void FStateMachineEditor::InitStateMachineEditor(const EToolkitMode::Type Mode, const TSharedPtr<class IToolkitHost>& InitToolkitHost, UStateMachine* InStateMachine)
{
StateMachine = InStateMachine;
StateMachineGraph = StateMachine->StateMachineGraph;
// Initialize the asset editor and spawn nothing (dummy layout)
const TSharedRef<FTabManager::FLayout> DummyLayout = FTabManager::NewLayout("NullLayout")->AddArea(FTabManager::NewPrimaryArea());
InitAssetEditor(Mode, InitToolkitHost, FName("StateMachineEditorApp"), DummyLayout, true, true, InStateMachine);
DocumentManager = MakeShareable(new FDocumentTracker);
DocumentManager->Initialize(SharedThis(this));
DocumentManager->SetTabManager(TabManager.