1. 上面初始化函数必须加Super::否则Tick函数不执行:或者其他莫名错误!!!
![](https://img.haomeiwen.com/i13034088/b2cfa9bb7614d63b.png)
2. UI中获取鼠标键盘输入键,必须加以下代码 然后重写NativeOnPreviewKeyDown函数,否则重写不生效!!!
![](https://img.haomeiwen.com/i13034088/e8123016ebe3f6a9.png)
3. Actor类添加tick函数必须在构造方法里面添加以下代码才生效
![](https://img.haomeiwen.com/i13034088/a695645e7a357c30.png)
4. 剪切掉超出父类尺寸部分,可以用于放大功能提升显示精度而不影响整个控件的尺寸,默认不剪切Inherit
![](https://img.haomeiwen.com/i13034088/f85e90a122250fb5.png)
5. 当某个类似按钮类型的在游戏中出现无法点击情况,先查看是不是有其他控件遮挡住了或者将按钮的Zorder设大
![](https://img.haomeiwen.com/i13034088/1a465891cd8b9614.png)
6. UI部件保证其他地方可以获取调用
![](https://img.haomeiwen.com/i13034088/9635ae0b499e549a.png)
7. UI保证屏幕尺寸不影响部件的相对位置
![](https://img.haomeiwen.com/i13034088/fb50ffc626d221d7.png)
8. UI不改变边缘部分进行放大缩小等
![](https://img.haomeiwen.com/i13034088/a5f49ce7dfec9eda.png)
9. UI要使某个图片靠边 且改变游戏窗口尺寸不影响UI部件的位置,可以调节锚点。
![](https://img.haomeiwen.com/i13034088/0b00a16fee5dc93a.png)
![](https://img.haomeiwen.com/i13034088/d958277a3b8b444f.png)
10. 关于Button
a. 假设该button在UE4 UI中已编辑
.h文件定义:
UButton* PuGongButton;
UFUNCTION()
void OnPuGongButtonPress();
UFUNCTION()
void OnPuGongButtonRelease();
NativeConstruct函数中:
//查找Btn_pugong
PuGongButton = FindWidget<UButton>("Btn_pugong");
//button按下-弹起事件
FindButtonAndBindPressed("Btn_pugong", "OnPuGongButtonPress");
FindButtonAndBindReleased("Btn_pugong", "OnPuGongButtonRelease");
b. 动态创建button
if (CvsRootPanel)
{
if (WidgetTree)
{
//创建建筑标识按钮
UButton * SceneryBtn = WidgetTree->ConstructWidget<UButton>(UButton::StaticClass());
if (SceneryBtn)
{
UPanelSlot* Slot = CvsRootPanel->AddChild(SceneryBtn);
if (UCanvasPanelSlot* cpSlot = Cast<UCanvasPanelSlot>(Slot))
{
//建筑默认尺寸
//cpSlot->SetSize(FVector2D(20, 20));
cpSlot->SetPosition(FVector2D(PanwInMiniMapLocX + MiniMapPosOffsetX, PanwInMiniMapLocY + MiniMapPosOffsetY));
}
//创建按钮显示的图片
UImage* ImgScenery = WidgetTree->ConstructWidget<UImage>(UImage::StaticClass());
if (ImgScenery)
{
UPanelSlot* Slot = SceneryBtn->AddChild(ImgScenery);
ImgScenery->SetBrushFromTexture(BuildingIcon, false);
}
}
}
}
11. 资源相关的变量需要加uproperty()
UPROPERTY()
UTexture2D* TaskIcon = nullptr;
12. UI字体描边
![](https://img.haomeiwen.com/i13034088/848459f2aea6cf1e.png)
![](https://img.haomeiwen.com/i13034088/c45b24269583eae8.png)
字体选择如果没有 可以先查看打开,然后就有了
![](https://img.haomeiwen.com/i13034088/b63db6e87d7fec51.png)
![](https://img.haomeiwen.com/i13034088/8755f6336e477a89.png)
13. 可自由设置样式的字体
- 在ui中添加rich text block
![](https://img.haomeiwen.com/i13034088/784d100af586f028.png)
- 创建data table
![](https://img.haomeiwen.com/i13034088/ac6225c8a20a434e.png)
- 选择richtextstylerow
![](https://img.haomeiwen.com/i13034088/f4458112569046c7.png)
- 点击add 添加
![](https://img.haomeiwen.com/i13034088/809763e0b4b70981.png)
- 双击重新命名
![](https://img.haomeiwen.com/i13034088/592b15d132976f28.png)
- 这儿设置了7种不同的颜色,设置字体相关属性
![](https://img.haomeiwen.com/i13034088/4515350c38d92bb9.png)
- 回到UI界面 设置Text Style Set
![](https://img.haomeiwen.com/i13034088/9fc37a80ed29a8d1.png)
- 字体内容格式<></>
![](https://img.haomeiwen.com/i13034088/373e3090ef15ddf4.png)
- 效果:
![](https://img.haomeiwen.com/i13034088/3ee115e5ffb55ce1.png)
14. UI添加动画方式
![](https://img.haomeiwen.com/i13034088/1a3b72370ed0f50f.png)
网友评论