3.0 KiB
3.0 KiB
BP_UniversalEndpointComp
基本信息
- 类型: Blueprint (ActorComponent)
- 父类: UEndpointComponent
- 源文件: /Game/Blueprints/Component/BP_UniversalEndpointComp.BP_UniversalEndpointComp
- 模块: Content
功能概述
BP_UniversalEndpointComp 是通用指令端点组件,继承 CharacterControl 的 UEndpointComponent。它添加了 CommandReceivedDispatcher 事件分发器委托,让其他蓝图可以动态绑定到该端点的指令接收事件,无需创建新子类。
设计用意
UEndpointComponent 提供了 OnCommandReceived (BlueprintImplementableEvent) 用于蓝图处理指令,但该事件只能在子类中覆盖,外部蓝图无法直接订阅。BP_UniversalEndpointComp 通过添加一个动态多播委托 CommandReceivedDispatcher,在收到指令时将事件转发为委托广播,使外部蓝图也能监听该端点的指令接收事件,提升了端点组件的可组合性。
职责范围
BP_UniversalEndpointComp 负责提供外部的指令接收委托,将内部事件转发为可外部订阅的委托。它不处理具体的指令逻辑(由外部订阅者负责),也不涉及路由器逻辑(由 UCommandRouter 负责)。
项目内依赖
| 依赖项 | 关系 | 源文件 |
|---|---|---|
| UEndpointComponent | 父类 | CharacterControl 插件 |
对外接口
- 蓝图变量:
CommandReceivedDispatcher(动态多播委托) -- 指令接收事件分发器,is_instance_editable,其他蓝图可绑定此委托接收指令通知
- 继承自 UEndpointComponent 的接口:
EndpointState(FEndpointState) -- 端点状态,含EndpointGuid、InterestedTags(FGameplayTagContainer)、bIsActive、bIsContinuousFriendly、bIsAsynchronousOnCommandReceived(const FCommandPacket& Command)(BlueprintImplementableEvent) -- 收到匹配指令时调用,可在蓝图子类或本蓝图 EventGraph 中实现OnEndpointStateChanged(FOnEndpointStateChanged) -- 状态变化委托OnCommandOutput(FOnCommandOutput) -- 命令输出委托
- 继承自 ICommandEndpoint 接口:
ReceiveCommand_BP(const FCommandPacket& Command)(BlueprintNativeEvent) -- 蓝图版本的指令接收入口GetEndpointDispatcher_BP()(BlueprintNativeEvent) -- 获取端点分发器
使用方法
- 作为 ActorComponent 添加到 BP_TestChar 等需要通用指令处理的 Actor 上
- 配置
EndpointState.InterestedTags指定该端点关注的 GameplayTag 集合 - 外部蓝图通过绑定
CommandReceivedDispatcher委托来监听指令,无需创建新的端点子类 - EventGraph 中当
OnCommandReceived触发时,自动广播CommandReceivedDispatcher,将内部事件转发为外部委托 UCommandRouterComponent在 BeginPlay 时通过AutoRegisterEndpoints自动发现并注册本组件
用例
- BP_TestChar 的组件,作为通用指令端点接收路由来的指令
- 外部蓝图通过绑定
CommandReceivedDispatcher订阅指令事件