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

97 lines
4.9 KiB
Markdown
Raw Normal View History

2023-06-29 11:55:02 +08:00
---
title: UE5 Lyra学习笔记(2)—LyraPlugins
date: 2022-08-09 13:55:20
tags: Lyra Editor
rating: ⭐️⭐️
---
# Plugins
- AsyncMixin
- CommonGame
- CommonLoadingScreen
- CommonUser
- GameFeatures
- GameplayMessageRouter
- GameSettings
- GameSubtitles
- LyraExampleContent
- LyraExtTool
- ModularGameplayActors
- PocketWorlds
- UIExtension
## AsyncMixin
## ModularGameplayActors
引擎插件ModularGameplay的Actor版本增加了UGameFrameworkComponentManager控制的各种基础胶水类Lyra里的相关类都继承自他们。
- AModularGameModeBase指定了插件里实现的类
- AModularAIController
- AModularCharacter
- AModularGameStateBase
- AModularPawn
- AModularPlayerController
- AModularPlayerState
## UIExtension
主要实现了`UUIExtensionPointWidget`这个控件以及用于数据控制的`UUIExtensionSubsystem``UUIExtensionPointWidget`是一个布局控件实现一种以数据驱动方式通过GameplayTag 匹配方式来插入Widget的方式。一般通过在UMG控件中设置参插槽参数
![](https://cdn.jsdelivr.net/gh/blueroseslol/ImageBag@latest/ImageBag/Lyra/Lyra_W_ShootHUDLayout.png)
![](https://cdn.jsdelivr.net/gh/blueroseslol/ImageBag@latest/ImageBag/Lyra/Lyra_W_ShootHUDLayout_WidgetSetting.png)
在LyraExperienceActionSet中设置AddWidgetsLayoutClass、LayoutIDWidgetClass、SlotID最后会通过`UCommonUIExtensions::PushContentToLayer_ForPlayer`往屏幕上增加Widget。
![](https://cdn.jsdelivr.net/gh/blueroseslol/ImageBag@latest/ImageBag/Lyra/Lyra_LyraExperienceActionSet.png)
这样设计的其中一个优点在于实现解耦例如在相关Ability的Add/Remove进行UI注册与卸载做到一个Ability做到所有的逻辑。
- UUIExtensionSubsystem
- UUIExtensionHandleFunctions通过FUIExtensionPointHandle判断有效性与卸载函数。
- UUIExtensionPointHandleFunctions通过FUIExtensionPointHandle判断有效性与卸载函数。
- RegisterExtensionPointForContext使用传入数据构建`FUIExtensionPoint`并其填充`ExtensionPointMap`,并且调用`ExtensionPoint`绑定的委托。
- RegisterExtensionAsData使用传入数据构建`FUIExtension`并其填充`ExtensionMap`,并且调用`Extension`绑定的委托。
- UnregisterExtensionPoint通过Handle移除对应`FUIExtensionPoint`
- UnregisterExtension通过Handle移除对应`FUIExtension`
- 若干蓝图函数。
- UMG控件
- UUIExtensionPointWidget
AddWidgets代码位于`UGameFeatureAction_AddWidgets`类中。
## CommonUI
- CommonUI官方文档https://docs.unrealengine.com/5.0/zh-CN/overview-of-advanced-multiplatform-user-interfaces-with-common-ui-for-unreal-engine/
- Introduction to Common UIhttps://www.youtube.com/watch?v=TTB5y-03SnE
- Lyra跨平台UI开发https://www.bilibili.com/video/BV1mT4y167Fm?spm_id_from=333.999.0.0&vd_source=d47c0bb42f9c72fd7d74562185cee290
### CommonUIActionRouterBase
这是一个本地玩家用的子系统。可以用于注册InputAction。
## GameplayMessageRouter
Runtime模块实现了`UGameplayMessageSubsystem``UAsyncAction_ListenForGameplayMessage`Editor模块实现了`UK2Node_AsyncAction_ListenForGameplayMessages`节点。
### FGameplayMessageListenerHandle
存储了UGameplayMessageSubsystem的弱指针、Handle IDint32 ID、MessageChannelFGameplayTag Channel与FDelegateHandle。并且实现了Unregister()与IsValid()。
### UGameplayMessageSubsystem
是一个UGameInstanceSubsystem。成员变量只有`ListenerMap`记录MessageChannel=>FChannelListenerList的Map
```c++
// List of all entries for a given channel
struct FChannelListenerList
{
TArray<FGameplayMessageListenerData> Listeners;
int32 HandleID = 0;
};
private:
TMap<FGameplayTag, FChannelListenerList> ListenerMap;
```
- 泛型函数:获取到类型的`UScriptStruct`传入内部函数,最后返回`FGameplayMessageListenerHandle`
- RegisterListener
- BroadcastMessage
- UnregisterListener
- 泛型函数调用的内部函数
- RegisterListenerInternal从使用MessageChannel(GameplayTag)从`ListenerMap`找到对应(如果没有则添加)的`FChannelListenerList`,并填充`FGameplayMessageListenerData`数据:仿函数以及其他相关信息。
- BroadcastMessageInternal调用对应MessageChannel(GameplayTag)与UScriptStruct类型的所有仿函数该过程还会移除无效的仿函数所在项
- UnregisterListenerInternal`ListenerMap`中找到对应MessageChannel(GameplayTag)的`FChannelListenerList`并从其中移除指定HandleID的`FGameplayMessageListenerData`。如果之后`FChannelListenerList`为空,则从`ListenerMap`移除这个键值。
### UAsyncAction_ListenForGameplayMessage
在Activate()中向`UGameplayMessageSubsystem`注册Channel、Lambda、`TWeakObjectPtr<UScriptStruct> MessageStructType``EGameplayMessageMatch`。lambda主要作用就是触发OnMessageReceived委托的多播。
UK2Node_AsyncAction_ListenForGameplayMessages为其封装的蓝图节点。