UE4自定义资源和编辑器(五):添加操作节点的通用命令

本文介绍了如何在UE4编辑器中为图表添加通用命令,如复制、粘贴和删除节点。通过继承FAIGraphEditor并创建FUICommandList,实现了节点操作的常用命令。同时,重写GetContextMenuActions()函数为节点添加操作菜单,增强了编辑器的功能。尽管UE4编辑器的扩展教程较少,但理解其实现逻辑后可以方便地仿照引擎功能进行自定义开发。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

编辑器图表添加通用命令

在之前创建的编辑器中,复制、粘贴、删除节点的操作无法完成,其原因是需要给编辑器添加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.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值