1. 上面初始化函数必须加Super::否则Tick函数不执行:或者其他莫名错误!!!

2. UI中获取鼠标键盘输入键,必须加以下代码 然后重写NativeOnPreviewKeyDown函数,否则重写不生效!!!

3. Actor类添加tick函数必须在构造方法里面添加以下代码才生效

4. 剪切掉超出父类尺寸部分,可以用于放大功能提升显示精度而不影响整个控件的尺寸,默认不剪切Inherit

5. 当某个类似按钮类型的在游戏中出现无法点击情况,先查看是不是有其他控件遮挡住了或者将按钮的Zorder设大

6. UI部件保证其他地方可以获取调用

7. UI保证屏幕尺寸不影响部件的相对位置

8. UI不改变边缘部分进行放大缩小等

9. UI要使某个图片靠边 且改变游戏窗口尺寸不影响UI部件的位置,可以调节锚点。


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字体描边


字体选择如果没有 可以先查看打开,然后就有了


13. 可自由设置样式的字体
- 在ui中添加rich text block

- 创建data table

- 选择richtextstylerow

- 点击add 添加

- 双击重新命名

- 这儿设置了7种不同的颜色,设置字体相关属性

- 回到UI界面 设置Text Style Set

- 字体内容格式<></>

- 效果:

14. UI添加动画方式

网友评论