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_MoveInput.BP_MoveInput
- **模块**: Content
- **模块**: Content/Blueprints/Component
## 功能概述
BP_MoveInput 是移动输入端点组件,持有对 CharacterMovementComponent 的引用(通过 CharMove 变量),将指令系统中的移动指令转化为实际的角色移动。
@@ -21,25 +21,40 @@ BP_MoveInput 负责接收移动指令并将其转换为 CharacterMovementCompone
| UEndpointComponent | 父类 | CharacterControl 插件 |
| UCharacterMovementComponent | 引用 (CharMove) | 引擎内置 |
## 对外接口
- **蓝图变量**
- `CharMove` (CharacterMovementComponent*) -- 持有对所属角色的 CharacterMovementComponent 引用is_instance_editable可在组件实例上配置
- **继承自 UEndpointComponent 的接口**
- `EndpointState` (FEndpointState) -- 端点状态,含 `InterestedTags` 配置关注的移动指令标签(如 "Command.Move"
- `OnCommandReceived(const FCommandPacket& Command)` (BlueprintImplementableEvent) -- 收到移动指令时调用,在 EventGraph 中实现node_count=22
- `OnEndpointStateChanged` / `OnCommandOutput` -- 状态和输出委托
- **通过 EventGraph 的行为**
- `Command.ContinuousPayload.ContinuousValue` 提取移动向量 (FVector3f)
- 调用 `CharMove` 的移动接口将向量转化为实际角色移动
## 外部视角
BP_MoveInput 是 UEndpointComponent 的蓝图子类,从外部调用者视角:
**公开属性(蓝图可读写)**
- `CharMove`CharacterMovementComponent*)— 被控制的角色移动组件引用
**核心行为**
- 继承 UEndpointComponent 的 OnCommandReceivedBlueprintImplementableEvent接收移动指令
- 从 FCommandPacket.ContinuousPayload.ContinuousValue 中提取移动向量
- 将移动向量应用至 CharMove 引用的 CharacterMovementComponent
**EventGraph 事件**
| 事件 | 类型 | 触发时机 | 行为 |
|------|------|----------|------|
| `事件开始运行` | 原生覆盖 (BeginPlay) | 组件创建时由引擎自动触发 | 获取 Owner → 按类获取 CharacterMovementComponent → 存入 CharMove 变量 |
| `事件Tick` | 原生覆盖 | 每帧 | 预留(当前无连线逻辑) |
| `事件OnCommandReceived` | 委托事件 (EndpointComponent) | 收到指令路由系统派发的 CommandPacket | 解析 ContinuousPayload → 提取 ContinuousValue 向量 → 计算向前/向右移动分量 → 调用 CharacterMovementComponent.AddMovementInput |
**外部交互方式**
- 作为 BP_TestChar 的组件自动创建
- 指令系统通过 UCommandRouter 将匹配标签的指令路由到该组件
- 不暴露自定义事件或委托
## 使用方法
- 作为 ActorComponent 添加到 BP_TestChar
- 设置 `CharMove` 变量指向所属角色的 `CharacterMovementComponent`
- 配置 `EndpointState.InterestedTags` 添加移动相关 GameplayTag如 "Command.Move"
- 设置 `EndpointState.bIsContinuousFriendly = true`(移动是连续指令)
- `UCommandRouterComponent` 自动发现并注册本组件为端点
- 当 EnhancedInput 产生移动输入 -> UCommandInputComponent 生成 FCommandPacket -> UCommandRouterComponent 按标签匹配 -> 本组件的 OnCommandReceived 收到指令 -> 从 ContinuousPayload.ContinuousValue 提取 FVector3f -> 调用 CharacterMovementComponent 执行移动
BP_MoveInput 在项目中的典型调用流程:
- **移动输入流程** — 指令系统派发移动指令 → OnCommandReceived 触发 → 解析 CommandPacket.ContinuousPayload.ContinuousValue → 提取移动向量 → 结合角色控制旋转计算前后/左右分量 → 调用 CharMove.AddMovementInput → CharacterMovementComponent 处理实际移动
## 用例
- BP_TestChar 的组件,处理移动指令
- 通过 `CharMove` 变量连接 CharacterMovementComponent实现指令到移动的桥接
| 引用方 | 路径 | 用途 |
|--------|------|------|
| BP_TestChar | `/Game/Blueprints/BP_TestChar` | 作为端点组件添加到角色,执行移动指令 |
| BP_NewChar | `/Game/Blueprints/BP_NewChar` | 引用该组件处理角色移动输入 |