vault backup: 2024-03-22 16:45:37

This commit is contained in:
BlueRose 2024-03-22 16:45:37 +08:00
parent 3ccf1e56c7
commit 04c08dfe9c
3 changed files with 67 additions and 0 deletions

View File

@ -0,0 +1,67 @@
---
title: UE5 Lyra学习笔记(6)—CommonUI
date: 2024-03-22 15:03:59
excerpt:
tags:
rating: ⭐
---
# 前言
- 全局管理类
- [[#UGameUIManagerSubsystem]]
- [[#UGameUIPolicy]]
- UPrimaryGameLayout
- Widgets
使用[[#GameplayAbility]]检测玩家输入并且开启UI。
# UGameUIManagerSubsystem
父类为UGameInstanceSubsystem主要的功能是管理CurrentPolicy(UGameUIPolicy)。
# UGameUIPolicy
# GameplayAbility
Lyra使用2个位于Plugins/ShooterCore/Content/Input/Abilites/
- GAB_ShowWidget_WhenInputPressed
- GAB_ShowWidget_WhileInputHeld
GAB_ShowWidget_WhenInputPressed![[GAB_ShowWidget_WhenInputPressed.png|800]]
GAB_ShowWidget_WhileInputHeld略微复杂一些会多一些![[GAB_ShowWidget_WhileInputHeld.png|1200]]
## GameplayTasks
- UCancellableAsyncAction
- [[#UAsyncAction_PushContentToLayerForPlayer]]
核心函数逻辑如下主要调用UPrimaryGameLayout::PushWidgetToLayerStackAsync()
```c++
void UAsyncAction_PushContentToLayerForPlayer::Activate()
{
if (UPrimaryGameLayout* RootLayout = UPrimaryGameLayout::GetPrimaryGameLayout(OwningPlayerPtr.Get()))
{
TWeakObjectPtr<UAsyncAction_PushContentToLayerForPlayer> WeakThis = this;
StreamingHandle = RootLayout->PushWidgetToLayerStackAsync<UCommonActivatableWidget>(LayerName, bSuspendInputUntilComplete, WidgetClass, [this, WeakThis](EAsyncWidgetLayerState State, UCommonActivatableWidget* Widget) {
if (WeakThis.IsValid())
{
switch (State)
{
case EAsyncWidgetLayerState::Initialize:
BeforePush.Broadcast(Widget);
break;
case EAsyncWidgetLayerState::AfterPush:
AfterPush.Broadcast(Widget);
SetReadyToDestroy();
break;
case EAsyncWidgetLayerState::Canceled:
SetReadyToDestroy();
break;
}
}
SetReadyToDestroy();
});
}
else
{
SetReadyToDestroy();
}
}
```

Binary file not shown.

After

Width:  |  Height:  |  Size: 106 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 349 KiB