[UE4]用Slate框架写UE4插件

来源:互联网 发布:mac如何删除系统软件 编辑:程序博客网 时间:2024/05/18 00:06

可能是个深坑,根据需求慢慢填吧。首先,官方文档还是要看的,对新手来说,看了之后还是一头雾水,但是最关键的收获是,有个超级强大的工具,可以帮助我们找到自己想学习的布局和使用。

Slate Widget Inspector(Slate控件检查器)

UE官方文档 - Slate概述

有了这个之后,就可以学习Editor里面各种各样的布局是怎么写的了。

简单的自定义布局

1. 新建插件

新建一个插件,选择StandaloneWindow,引擎会默认为我们写好一些窗口代码。

自定义编辑器窗口插件

2. 查看默认Slate布局

在自动生成的代码中,可以在一个名为OnSpawnPluginTab的方法中,找到以下内容。

return SNew(SDockTab)    .TabRole(ETabRole::NomadTab)    [        //Put your tab content here!        SNew(SBox)        .HAlign(HAlign_Center)        .VAlign(VAlign_Center)        [            SNew(STextBlock)            .Text(WidgetText)        ]    ];

默认Slate布局

3. 自定义Slate布局

接下来,替换上面的代码,换成自己的Slate布局。编译通过后,要重启才能生效。

return SNew(SDockTab)        .TabRole(ETabRole::NomadTab)        [            SNew(SVerticalBox)            + SVerticalBox::Slot()            .HAlign(HAlign_Fill)            .VAlign(VAlign_Center)            .AutoHeight()            [                SNew(SHorizontalBox)                +SHorizontalBox::Slot()                .HAlign(HAlign_Fill)                .VAlign(VAlign_Center)                .Padding(0,2,0,2)                .FillWidth(0.2f)                [                    SNew(STextBlock)                    .Text(FText::FromString(FString("KeyValue")))                 ]                + SHorizontalBox::Slot()                .Padding(0, 2, 0, 2)                .HAlign(HAlign_Fill)                .VAlign(VAlign_Center)                .FillWidth(0.8f)                [                    SNew(SEditableTextBox)                    .HintText(FText::FromString(FString(TEXT("Please input key value"))))                    .SelectAllTextWhenFocused(true)                    .ClearKeyboardFocusOnCommit(true)                ]            ]            + SVerticalBox::Slot()            .HAlign(HAlign_Fill)            .VAlign(VAlign_Center)            .AutoHeight()            [                SNew(SHorizontalBox)                + SHorizontalBox::Slot()                .Padding(0, 2, 0, 2)                .HAlign(HAlign_Fill)                .VAlign(VAlign_Center)                .FillWidth(0.2f)                [                    SNew(STextBlock)                    .Text(FText::FromString(FString("AppID")))                ]                + SHorizontalBox::Slot()                .Padding(0, 2, 0, 2)                .HAlign(HAlign_Fill)                .VAlign(VAlign_Center)                .FillWidth(0.8f)                [                    SNew(SEditableTextBox)                    .HintText(FText::FromString(FString(TEXT("Please input app ID"))))                    .SelectAllTextWhenFocused(true)                    .ClearKeyboardFocusOnCommit(true)                ]            ]        ];

自定义Slate布局

2 0