This commit is contained in:
meishibiezb
2026-06-05 03:01:15 +08:00
parent 29a3f77908
commit a8bdf281ff
41 changed files with 1935 additions and 779 deletions

View File

@@ -4,7 +4,7 @@
- **类型**: Blueprint (ActorComponent)
- **父类**: UEndpointComponent
- **源文件**: /Game/Blueprints/Component/BP_UniversalEndpointComp.BP_UniversalEndpointComp
- **模块**: Content
- **模块**: Content/Blueprints/Component
## 功能概述
BP_UniversalEndpointComp 是通用指令端点组件,继承 CharacterControl 的 UEndpointComponent。它添加了 `CommandReceivedDispatcher` 事件分发器委托,让其他蓝图可以动态绑定到该端点的指令接收事件,无需创建新子类。
@@ -20,25 +20,40 @@ BP_UniversalEndpointComp 负责提供外部的指令接收委托,将内部事
|--------|------|--------|
| 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) -- 获取端点分发器
## 外部视角
BP_UniversalEndpointComp 是 UEndpointComponent 的蓝图子类,从外部调用者视角:
**公开属性(蓝图可读写)**
- `CommandReceivedDispatcher`(多播委托)— 指令接收事件分发器
**核心行为**
- 继承 UEndpointComponent 的 OnCommandReceivedBlueprintImplementableEvent在收到指令时触发
- 在 OnCommandReceived 实现中将指令转发为 CommandReceivedDispatcher 广播
- 外部蓝图可通过 Bind Event 节点绑定到 CommandReceivedDispatcher无需新建 Endpoint 子类
**EventGraph 事件**
| 事件 | 类型 | 触发时机 | 行为 |
|------|------|----------|------|
| `事件开始运行` | 原生覆盖 (BeginPlay) | 组件创建时 | 预留(当前无连线逻辑) |
| `事件Tick` | 原生覆盖 | 每帧 | 预留(当前无连线逻辑) |
| `事件OnCommandReceived` | 委托事件 (EndpointComponent) | 收到指令路由系统派发的 CommandPacket | 调用 CommandReceivedDispatcher 广播给所有绑定的外部蓝图 |
**外部交互方式**
- 作为 BP_TestChar 的组件自动创建
- 外部蓝图通过组件引用的方式获取实例,绑定 CommandReceivedDispatcher
## 使用方法
- 作为 ActorComponent 添加到 BP_TestChar 等需要通用指令处理的 Actor 上
- 配置 `EndpointState.InterestedTags` 指定该端点关注的 GameplayTag 集合
- 外部蓝图通过绑定 `CommandReceivedDispatcher` 委托来监听指令,无需创建新的端点子类
- EventGraph 中当 `OnCommandReceived` 触发时,自动广播 `CommandReceivedDispatcher`,将内部事件转发为外部委托
- `UCommandRouterComponent` 在 BeginPlay 时通过 `AutoRegisterEndpoints` 自动发现并注册本组件
BP_UniversalEndpointComp 在项目中的典型调用流程:
- **指令转发流程** — UCommandRouter 派发指令 → OnCommandReceived 触发 → 调用 CommandReceivedDispatcher 广播 → 所有绑定了该委托的外部蓝图(如 BP_Hud 的 DealWithCommand同时收到指令
- **事件绑定流程** — 外部蓝图(如 BP_Hud 的 BeginPlay→ 获取 BP_UniversalEndpointComp 引用 → Bind Event to CommandReceivedDispatcher → 创建自定义事件处理指令
## 用例
- BP_TestChar 的组件,作为通用指令端点接收路由来的指令
- 外部蓝图通过绑定 `CommandReceivedDispatcher` 订阅指令事件
| 引用方 | 路径 | 用途 |
|--------|------|------|
| BP_TestChar | `/Game/Blueprints/BP_TestChar` | 作为端点组件添加到角色,接收并转发指令 |
| BP_Hud | `/Game/Blueprints/BP_Hud` | 在 EventGraph 中引用,用于端点通信 |