vault backup: 2024-03-22 19:08:41
This commit is contained in:
parent
04c08dfe9c
commit
df6809d8f8
@ -7,19 +7,87 @@ rating: ⭐
|
|||||||
---
|
---
|
||||||
# 前言
|
# 前言
|
||||||
- 全局管理类
|
- 全局管理类
|
||||||
- [[#UGameUIManagerSubsystem]]
|
- UGameUIManagerSubsystem:父类为UGameInstanceSubsystem,主要的功能是管理CurrentPolicy(UGameUIPolicy)。
|
||||||
- [[#UGameUIPolicy]]
|
- UGameUIPolicy:将UPrimaryGameLayout添加到Viewport中。
|
||||||
- UPrimaryGameLayout
|
- UPrimaryGameLayout
|
||||||
- Widgets
|
- Widgets
|
||||||
使用[[#GameplayAbility]]检测玩家输入并且开启UI。
|
使用[[#GameplayAbility]]检测玩家输入并且开启UI。
|
||||||
|
|
||||||
# UGameUIManagerSubsystem
|
# UPrimaryGameLayout
|
||||||
父类为:UGameInstanceSubsystem,主要的功能是管理CurrentPolicy(UGameUIPolicy)。
|
父类为UCommonUserWidget。主要功能为UILayer以及Dormant状态管理。
|
||||||
|
## UILayer
|
||||||
|
使用`TMap<FGameplayTag, TObjectPtr<UCommonActivatableWidgetContainerBase>> Layers;`进行多UI层的管理,不同Layer使用GameplayTag进行区分。Lyra的UILayer分为以下4个层:
|
||||||
|
- UI.Layer.Game
|
||||||
|
- UI.Layer.GameMenu
|
||||||
|
- UI.Layer.Menu
|
||||||
|
- UI.Layer.Modal
|
||||||
|
|
||||||
# UGameUIPolicy
|
```c++
|
||||||
|
template <typename ActivatableWidgetT = UCommonActivatableWidget>
|
||||||
|
TSharedPtr<FStreamableHandle> PushWidgetToLayerStackAsync(FGameplayTag LayerName, bool bSuspendInputUntilComplete, TSoftClassPtr<UCommonActivatableWidget> ActivatableWidgetClass, TFunction<void(EAsyncWidgetLayerState, ActivatableWidgetT*)> StateFunc)
|
||||||
|
{
|
||||||
|
static_assert(TIsDerivedFrom<ActivatableWidgetT, UCommonActivatableWidget>::IsDerived, "Only CommonActivatableWidgets can be used here");
|
||||||
|
|
||||||
|
static FName NAME_PushingWidgetToLayer("PushingWidgetToLayer");
|
||||||
|
const FName SuspendInputToken = bSuspendInputUntilComplete ? UCommonUIExtensions::SuspendInputForPlayer(GetOwningPlayer(), NAME_PushingWidgetToLayer) : NAME_None;
|
||||||
|
|
||||||
|
FStreamableManager& StreamableManager = UAssetManager::Get().GetStreamableManager();
|
||||||
|
TSharedPtr<FStreamableHandle> StreamingHandle = StreamableManager.RequestAsyncLoad(ActivatableWidgetClass.ToSoftObjectPath(), FStreamableDelegate::CreateWeakLambda(this,
|
||||||
|
[this, LayerName, ActivatableWidgetClass, StateFunc, SuspendInputToken]()
|
||||||
|
{
|
||||||
|
UCommonUIExtensions::ResumeInputForPlayer(GetOwningPlayer(), SuspendInputToken);
|
||||||
|
|
||||||
|
ActivatableWidgetT* Widget = PushWidgetToLayerStack<ActivatableWidgetT>(LayerName, ActivatableWidgetClass.Get(), [StateFunc](ActivatableWidgetT& WidgetToInit) {
|
||||||
|
StateFunc(EAsyncWidgetLayerState::Initialize, &WidgetToInit);
|
||||||
|
});
|
||||||
|
|
||||||
|
StateFunc(EAsyncWidgetLayerState::AfterPush, Widget);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
// Setup a cancel delegate so that we can resume input if this handler is canceled.
|
||||||
|
StreamingHandle->BindCancelDelegate(FStreamableDelegate::CreateWeakLambda(this,
|
||||||
|
[this, StateFunc, SuspendInputToken]()
|
||||||
|
{
|
||||||
|
UCommonUIExtensions::ResumeInputForPlayer(GetOwningPlayer(), SuspendInputToken);
|
||||||
|
StateFunc(EAsyncWidgetLayerState::Canceled, nullptr);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
return StreamingHandle;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename ActivatableWidgetT = UCommonActivatableWidget>
|
||||||
|
ActivatableWidgetT* PushWidgetToLayerStack(FGameplayTag LayerName, UClass* ActivatableWidgetClass)
|
||||||
|
{
|
||||||
|
return PushWidgetToLayerStack<ActivatableWidgetT>(LayerName, ActivatableWidgetClass, [](ActivatableWidgetT&) {});
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename ActivatableWidgetT = UCommonActivatableWidget>
|
||||||
|
ActivatableWidgetT* PushWidgetToLayerStack(FGameplayTag LayerName, UClass* ActivatableWidgetClass, TFunctionRef<void(ActivatableWidgetT&)> InitInstanceFunc)
|
||||||
|
{
|
||||||
|
static_assert(TIsDerivedFrom<ActivatableWidgetT, UCommonActivatableWidget>::IsDerived, "Only CommonActivatableWidgets can be used here");
|
||||||
|
|
||||||
|
if (UCommonActivatableWidgetContainerBase* Layer = GetLayerWidget(LayerName))
|
||||||
|
{
|
||||||
|
return Layer->AddWidget<ActivatableWidgetT>(ActivatableWidgetClass, InitInstanceFunc);
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### RegisterLayer
|
||||||
|
用于向PrimaryGameLayout注册UILayer。(为了方便管理里面的CommonActivatabbleWidgetStack)
|
||||||
|
```c++
|
||||||
|
void RegisterLayer(UPARAM(meta = (Categories = "UI.Layer")) FGameplayTag LayerTag, UCommonActivatableWidgetContainerBase* LayerWidget);
|
||||||
|
```
|
||||||
|
|
||||||
|
Content/UI的W_OverallUILayout调用,它是一个根组件为Overlay,下面有4个子组件(CommonActivatabbleWidgetStack):
|
||||||
|
- GameLayer_Stack:游戏内UI,类似HUD。
|
||||||
|
- GameMenu_Stack:游戏相关的 "菜单",例如游戏中的库存用户界面。
|
||||||
|
- Menu_Stack:设置界面等。
|
||||||
|
- Model_Stack:游戏内的模态确认对话框、错误对话框。
|
||||||
# GameplayAbility
|
# GameplayAbility
|
||||||
Lyra使用2个位于Plugins/ShooterCore/Content/Input/Abilites/
|
Lyra使用2个位于Plugins/ShooterCore/Content/Input/Abilites/
|
||||||
- GAB_ShowWidget_WhenInputPressed
|
- GAB_ShowWidget_WhenInputPressed
|
||||||
|
@ -19,6 +19,10 @@ CommonUI主要解决了**层叠式UI**输入事件处理以及**多平台**多
|
|||||||
- [Lyra Cross-platform UI Development | Tech Talk](https://www.bilibili.com/video/BV1mT4y167Fm/?spm_id_from=333.999.0.0&vd_source=d47c0bb42f9c72fd7d74562185cee290)
|
- [Lyra Cross-platform UI Development | Tech Talk](https://www.bilibili.com/video/BV1mT4y167Fm/?spm_id_from=333.999.0.0&vd_source=d47c0bb42f9c72fd7d74562185cee290)
|
||||||
|
|
||||||
# CommonUI
|
# CommonUI
|
||||||
|
|
||||||
|
- 数据表
|
||||||
|
- CommonInputActionDataBase:各平台输入绑定。
|
||||||
|
|
||||||
## CommonUI特有功能
|
## CommonUI特有功能
|
||||||
1. ⭐⭐**自带过渡效果**:在Stack控件的`Detail-Transition`中可以设置控件激活/注销时过渡效果,同时还可以设置效果曲线类型与曲线数值。默认是**渐隐(Fade Only)**。
|
1. ⭐⭐**自带过渡效果**:在Stack控件的`Detail-Transition`中可以设置控件激活/注销时过渡效果,同时还可以设置效果曲线类型与曲线数值。默认是**渐隐(Fade Only)**。
|
||||||
2. ⭐⭐⭐**CommonActivatableWidgetStack**:会自动激活Stack顶部Widget。
|
2. ⭐⭐⭐**CommonActivatableWidgetStack**:会自动激活Stack顶部Widget。
|
||||||
|
Loading…
x
Reference in New Issue
Block a user