# BP_UniversalEndpointComp ## 基本信息 - **类型**: Blueprint (ActorComponent) - **父类**: UEndpointComponent - **源文件**: /Game/Blueprints/Component/BP_UniversalEndpointComp.BP_UniversalEndpointComp - **模块**: Content/Blueprints/Component ## 功能概述 BP_UniversalEndpointComp 是通用指令端点组件,继承 CharacterControl 的 UEndpointComponent。它添加了 `CommandReceivedDispatcher` 事件分发器委托,让其他蓝图可以动态绑定到该端点的指令接收事件,无需创建新子类。 ## 设计用意 UEndpointComponent 提供了 OnCommandReceived (BlueprintImplementableEvent) 用于蓝图处理指令,但该事件只能在子类中覆盖,外部蓝图无法直接订阅。BP_UniversalEndpointComp 通过添加一个动态多播委托 `CommandReceivedDispatcher`,在收到指令时将事件转发为委托广播,使外部蓝图也能监听该端点的指令接收事件,提升了端点组件的可组合性。 ## 职责范围 BP_UniversalEndpointComp 负责提供外部的指令接收委托,将内部事件转发为可外部订阅的委托。它不处理具体的指令逻辑(由外部订阅者负责),也不涉及路由器逻辑(由 UCommandRouter 负责)。 ## 项目内依赖 | 依赖项 | 关系 | 源文件 | |--------|------|--------| | UEndpointComponent | 父类 | CharacterControl 插件 | ## 外部视角 BP_UniversalEndpointComp 是 UEndpointComponent 的蓝图子类,从外部调用者视角: **公开属性(蓝图可读写)** - `CommandReceivedDispatcher`(多播委托)— 指令接收事件分发器 **核心行为** - 继承 UEndpointComponent 的 OnCommandReceived(BlueprintImplementableEvent),在收到指令时触发 - 在 OnCommandReceived 实现中将指令转发为 CommandReceivedDispatcher 广播 - 外部蓝图可通过 Bind Event 节点绑定到 CommandReceivedDispatcher,无需新建 Endpoint 子类 **EventGraph 事件** | 事件 | 类型 | 触发时机 | 行为 | |------|------|----------|------| | `事件开始运行` | 原生覆盖 (BeginPlay) | 组件创建时 | 预留(当前无连线逻辑) | | `事件Tick` | 原生覆盖 | 每帧 | 预留(当前无连线逻辑) | | `事件OnCommandReceived` | 委托事件 (EndpointComponent) | 收到指令路由系统派发的 CommandPacket | 调用 CommandReceivedDispatcher 广播给所有绑定的外部蓝图 | **外部交互方式** - 作为 BP_TestChar 的组件自动创建 - 外部蓝图通过组件引用的方式获取实例,绑定 CommandReceivedDispatcher ## 使用方法 BP_UniversalEndpointComp 在项目中的典型调用流程: - **指令转发流程** — UCommandRouter 派发指令 → OnCommandReceived 触发 → 调用 CommandReceivedDispatcher 广播 → 所有绑定了该委托的外部蓝图(如 BP_Hud 的 DealWithCommand)同时收到指令 - **事件绑定流程** — 外部蓝图(如 BP_Hud 的 BeginPlay)→ 获取 BP_UniversalEndpointComp 引用 → Bind Event to CommandReceivedDispatcher → 创建自定义事件处理指令 ## 用例 | 引用方 | 路径 | 用途 | |--------|------|------| | BP_TestChar | `/Game/Blueprints/BP_TestChar` | 作为端点组件添加到角色,接收并转发指令 | | BP_Hud | `/Game/Blueprints/BP_Hud` | 在 EventGraph 中引用,用于端点通信 |