UE4_Plugins模板Editor Standalone Window 初步理解
一.
1.创建插件 Editor Standalone Window
2.目录下会生成如下文件
分别为Buttom/ButtomCommands/ButtomStyle Buttom.Build.cs 文件
3. 打开ButtomCommands.cpp
通过断点,观察 以下函数顺序
void FButtomCommands::RegisterCommands()
ButtomCommands.cpp
#include "ButtomCommands.h"
#define LOCTEXT_NAMESPACE "FButtomModule"
//断点位置
void FButtomCommands::RegisterCommands()
{
UI_COMMAND(OpenPluginWindow, "Buttom", "Bring up Buttom window", EUserInterfaceActionType::Button, FInputGesture());
}
#undef LOCTEXT_NAMESPACE
如下图,会看到调用顺序为
调用位置1 void FButtomModule::StartupModule() { // This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module FButtomStyle::Initialize(); FButtomStyle::ReloadTextures(); FButtomCommands::Register();
调用位置2 commands.h void Register
template<typename CommandContextType> class TCommands : public FBindingContext { public: /** Use this method to register commands. Usually done in StartupModule(). */ FORCENOINLINE static void Register() { if ( !Instance.IsValid() ) { TSharedRef<CommandContextType> NewInstance = MakeShareable( new CommandContextType() );
Instance = NewInstance;
NewInstance->RegisterCommands();
由此我们可见,通过实例化 Commands 然后调用 NewInstance->RegisterCommands()
二.CommandList
回到StartupModule中, FUICommandList主要为绑定一些命令 ,
void FButtomModule::StartupModule() { // This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module FButtomStyle::Initialize(); FButtomStyle::ReloadTextures(); FButtomCommands::Register(); PluginCommands = MakeShareable(new FUICommandList); PluginCommands->MapAction( FButtomCommands::Get().OpenPluginWindow, FExecuteAction::CreateRaw(this, &FButtomModule::PluginButtonClicked), FCanExecuteAction());
MapAction :将命令信息映射到由multibox或鼠标/键盘输入执行的一系列委托
贴一段MapAction :
void MapAction( const TSharedPtr< const FUICommandInfo > InUICommandInfo, FExecuteAction ExecuteAction, EUIActionRepeatMode RepeatMode = EUIActionRepeatMode::RepeatDisabled ); /** * Maps a command info to a series of delegates that are executed by a multibox or mouse/keyboard input * * @param InUICommandInfo The command info to map * @param ExecuteAction The delegate to call when the command should be executed * @param CanExecuteAction The delegate to call to see if the command can be executed * @param RepeatMode Can this action can be repeated if the chord used to call it is held down? */
基本可以看到 InUICommandInfo :要映射的命令信息,ExecuteAction:什么时候应该执行命令
通过create_raw的方式:
PluginCommands->MapAction( FButtomCommands::Get().OpenPluginWindow, FExecuteAction::CreateRaw(this, &FButtomModule::PluginButtonClicked), FCanExecuteAction());
找到 void FButtomModule::PluginButtonClicked()
void FButtomModule::PluginButtonClicked() { //FGlobalTabmanager::Get()->TryInvokeTab(ButtomTabName); }
//可以进行一些自定义操作,我们想实现的功能
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· winform 绘制太阳,地球,月球 运作规律
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
· Manus的开源复刻OpenManus初探
· 写一个简单的SQL生成工具