61 lines
3.3 KiB
Markdown
61 lines
3.3 KiB
Markdown
# BP_MoveInput
|
||
|
||
## 基本信息
|
||
- **类型**: Blueprint (ActorComponent)
|
||
- **父类**: UEndpointComponent
|
||
- **源文件**: /Game/Blueprints/Component/BP_MoveInput.BP_MoveInput
|
||
- **模块**: Content/Blueprints/Component
|
||
|
||
## 功能概述
|
||
BP_MoveInput 是移动输入端点组件,持有对 CharacterMovementComponent 的引用(通过 CharMove 变量),将指令系统中的移动指令转化为实际的角色移动。
|
||
|
||
## 设计用意
|
||
BP_MoveInput 是指令系统和 UE 移动系统之间的桥梁。它持有 `CharMove` (CharacterMovementComponent*) 引用,在 OnCommandReceived 中接收移动指令(连续指令,如 "Command.Move"),从 FCommandPacket.ContinuousPayload.ContinuousValue 提取移动向量,然后调用 CharacterMovementComponent 的移动接口。这种设计将输入系统和移动系统解耦——指令的生成、路由和执行分别由不同的组件负责。
|
||
|
||
## 职责范围
|
||
BP_MoveInput 负责接收移动指令并将其转换为 CharacterMovementComponent 的移动调用。移动向量通过连续指令的 ContinuousValue 传入,由 BP_MoveInput 提取并应用。指令的生成由 UCommandInputComponent 负责,指令的路由匹配由 UCommandRouter 负责。
|
||
|
||
## 项目内依赖
|
||
| 依赖项 | 关系 | 源文件 |
|
||
|--------|------|--------|
|
||
| UEndpointComponent | 父类 | CharacterControl 插件 |
|
||
| UCharacterMovementComponent | 引用 (CharMove) | 引擎内置 |
|
||
|
||
## 外部视角
|
||
|
||
BP_MoveInput 是 UEndpointComponent 的蓝图子类,从外部调用者视角:
|
||
|
||
**公开属性(蓝图可读写)**
|
||
- `CharMove`(CharacterMovementComponent*)— 被控制的角色移动组件引用
|
||
|
||
**核心行为**
|
||
- 继承 UEndpointComponent 的 OnCommandReceived(BlueprintImplementableEvent),接收移动指令
|
||
- 从 FCommandPacket.ContinuousPayload.ContinuousValue 中提取移动向量
|
||
- 将移动向量应用至 CharMove 引用的 CharacterMovementComponent
|
||
|
||
**EventGraph 事件**
|
||
|
||
| 事件 | 类型 | 触发时机 | 行为 |
|
||
|------|------|----------|------|
|
||
| `事件开始运行` | 原生覆盖 (BeginPlay) | 组件创建时由引擎自动触发 | 获取 Owner → 按类获取 CharacterMovementComponent → 存入 CharMove 变量 |
|
||
| `事件Tick` | 原生覆盖 | 每帧 | 预留(当前无连线逻辑) |
|
||
| `事件OnCommandReceived` | 委托事件 (EndpointComponent) | 收到指令路由系统派发的 CommandPacket | 解析 ContinuousPayload → 提取 ContinuousValue 向量 → 计算向前/向右移动分量 → 调用 CharacterMovementComponent.AddMovementInput |
|
||
|
||
**外部交互方式**
|
||
- 作为 BP_TestChar 的组件自动创建
|
||
- 指令系统通过 UCommandRouter 将匹配标签的指令路由到该组件
|
||
- 不暴露自定义事件或委托
|
||
|
||
## 使用方法
|
||
|
||
BP_MoveInput 在项目中的典型调用流程:
|
||
|
||
- **移动输入流程** — 指令系统派发移动指令 → OnCommandReceived 触发 → 解析 CommandPacket.ContinuousPayload.ContinuousValue → 提取移动向量 → 结合角色控制旋转计算前后/左右分量 → 调用 CharMove.AddMovementInput → CharacterMovementComponent 处理实际移动
|
||
|
||
## 用例
|
||
|
||
| 引用方 | 路径 | 用途 |
|
||
|--------|------|------|
|
||
| BP_TestChar | `/Game/Blueprints/BP_TestChar` | 作为端点组件添加到角色,执行移动指令 |
|
||
| BP_NewChar | `/Game/Blueprints/BP_NewChar` | 引用该组件处理角色移动输入 |
|