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);
}

//可以进行一些自定义操作,我们想实现的功能

posted on 2021-05-06 01:20  Animer  阅读(686)  评论(0编辑  收藏  举报