BlueRoseNote/03-UnrealEngine/Gameplay/Lyra/UE5 Lyra学习笔记(6)—CommonUI.md

67 lines
1.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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