Files
loneseDocument/Content/Blueprints/BP_UniversalEndpointComp.md
meishibiezb 29a3f77908 init
2026-06-04 21:44:13 +08:00

45 lines
3.0 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.
# 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``bIsAsynchronous`
- `OnCommandReceived(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` 订阅指令事件