BlueRoseNote/03-UnrealEngine/Gameplay/Lyra/UE5 Lyra学习笔记(2)—LyraPlugins.md
2023-06-29 11:55:02 +08:00

4.9 KiB
Raw Permalink Blame History

title, date, tags, rating
title date tags rating
UE5 Lyra学习笔记(2)—LyraPlugins 2022-08-09 13:55:20 Lyra Editor

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这个控件以及用于数据控制的UUIExtensionSubsystemUUIExtensionPointWidget是一个布局控件实现一种以数据驱动方式通过GameplayTag 匹配方式来插入Widget的方式。一般通过在UMG控件中设置参插槽参数

在LyraExperienceActionSet中设置AddWidgetsLayoutClass、LayoutIDWidgetClass、SlotID最后会通过UCommonUIExtensions::PushContentToLayer_ForPlayer往屏幕上增加Widget。

这样设计的其中一个优点在于实现解耦例如在相关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

CommonUIActionRouterBase

这是一个本地玩家用的子系统。可以用于注册InputAction。

GameplayMessageRouter

Runtime模块实现了UGameplayMessageSubsystemUAsyncAction_ListenForGameplayMessageEditor模块实现了UK2Node_AsyncAction_ListenForGameplayMessages节点。

FGameplayMessageListenerHandle

存储了UGameplayMessageSubsystem的弱指针、Handle IDint32 ID、MessageChannelFGameplayTag Channel与FDelegateHandle。并且实现了Unregister()与IsValid()。

UGameplayMessageSubsystem

是一个UGameInstanceSubsystem。成员变量只有ListenerMap记录MessageChannel=>FChannelListenerList的Map

// 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类型的所有仿函数该过程还会移除无效的仿函数所在项
    • UnregisterListenerInternalListenerMap中找到对应MessageChannel(GameplayTag)的FChannelListenerList并从其中移除指定HandleID的FGameplayMessageListenerData。如果之后FChannelListenerList为空,则从ListenerMap移除这个键值。

UAsyncAction_ListenForGameplayMessage

在Activate()中向UGameplayMessageSubsystem注册Channel、Lambda、TWeakObjectPtr<UScriptStruct> MessageStructTypeEGameplayMessageMatch。lambda主要作用就是触发OnMessageReceived委托的多播。

UK2Node_AsyncAction_ListenForGameplayMessages为其封装的蓝图节点。