Files
loneseDocument/Content/Blueprints/BP_ControllerComp.md
meishibiezb a8bdf281ff update
2026-06-05 03:01:15 +08:00

73 lines
4.5 KiB
Markdown
Raw Permalink 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_ControllerComp
## 基本信息
- **类型**: Blueprint (ActorComponent)
- **父类**: BP_EndpointComp_C (即 UEndpointComponent)
- **源文件**: /Game/Blueprints/Component/BP_ControllerComp.BP_ControllerComp
- **模块**: Content/Blueprints/Component
## 功能概述
BP_ControllerComp 是自定义控制器端点组件管理摄像机的缩放和跟随模式。持有多个摄像机相关配置参数移动速度MoveSpeed、臂长范围MinArmLength / MaxArmLength、缩放速度ZoomSpeed、跟随模式开关IsFollowMode以及跟随目标角色引用FollowedChar
## 设计用意
BP_ControllerComp 是 BP_TestChar 上最复杂的端点组件,负责处理摄像机控制指令。它持有自己的配置参数而非依赖 ACameraPawn 的默认值表明它可能在运行时动态调整摄像机行为例如切换跟随模式、调整臂长和移动速度。IsFollowMode 和 FollowedChar 的组合支持摄像机锁定特定角色的功能。
## 职责范围
BP_ControllerComp 负责摄像机控制参数的管理、跟随模式的切换以及摄像机移动指令的处理。摄像机实际的 SpringArm 变换和空间计算由 ACameraPawn 及其 SpringArm 组件负责。
## 项目内依赖
| 依赖项 | 关系 | 源文件 |
|--------|------|--------|
| BP_EndpointComp_C | 父类 | CharacterControl 插件 |
| UEndpointComponent | 祖父类 | CharacterControl 插件 |
| ACharacter | 引用 (FollowedChar) | 引擎内置 |
## 外部视角
BP_ControllerComp 是 BP_EndpointComp_C即 UEndpointComponent的蓝图子类从外部调用者视角
**公开配置属性(蓝图可读写)**
- `MoveSpeed`double— 摄像机移动速度
- `MinArmLength` / `MaxArmLength`double— 臂长最小/最大值
- `ZoomSpeed`double— 缩放速度
- `IsFollowMode`bool— 是否启用跟随模式
- `FollowedChar`Character*)— 跟随模式的目标角色
**自定义函数**
- `MoveController(GameplayTag, Vector)` — 处理摄像机移动指令
- `RotateController(GameplayTag, Vector)` — 处理摄像机旋转指令
- `ZoomCamera(GameplayTag, Vector)` — 处理摄像机缩放指令
- `ResetControllerLocation(DiscreteMeta)` — 重置摄像机位置
- `TickFollowChar()` — 每帧更新跟随目标位置
**外部交互方式**
- 作为 BP_TestChar 的组件自动创建
- 指令系统通过 UCommandRouter 将摄像机控制指令路由到该组件
- 外部系统可通过组件引用读取/修改其配置参数
**EventGraph 事件**
| 事件 | 类型 | 触发时机 | 行为 |
|------|------|----------|------|
| `事件开始运行` | 原生覆盖 (BeginPlay) | 组件创建时由引擎自动触发 | 调用父类 BeginPlay |
| `事件Tick` | 原生覆盖 | 每帧 | 调用父类 Tick然后调用 TickFollowChar 更新跟随目标位置 |
| `事件OnCommandReceived` | 委托事件 (EndpointComponent) | 收到指令路由系统派发的 CommandPacket | 解析 CommandPacket → 根据 GameplayTag 分发到 MoveController/RotateController/ZoomCamera连续指令或 ResetControllerLocation离散指令 |
| `EnterFollowMode` | 自定义事件 | 外部系统通过指令或直接调用触发 | 设置 IsFollowMode=true → 获取 Owner → Cast 到 PlayerController → Cast 到 Character → 设为 FollowedChar |
| `EnterFreeMode` | 自定义事件 | 外部系统通过指令或直接调用触发 | 设置 IsFollowMode=false解除跟随 |
| `DealWithCommand` | 自定义事件 | 收到指令时由组件内部逻辑调用 | 调用 DealWithCommand(CommandPacket) 函数进行指令处理分发 |
## 使用方法
BP_ControllerComp 在项目中的典型调用流程:
- **摄像机移动控制流程** — 外部输入 → UCommandRouter 派发 → `OnCommandReceived` 触发 → 解析 CommandPacket → 根据 GameplayTag 路由到 MoveController/RotateController/ZoomCamera → 更新摄像机位置/旋转/臂长
- **跟随模式切换流程** — 外部系统调用 `EnterFollowMode` → 设置 IsFollowMode=true → 获取 Owner → Cast 到 PlayerController → Cast 到 Character 设为 FollowedChar → Tick 中 TickFollowChar 每帧更新摄像机位置跟随角色
- **自由模式切换流程** — 外部系统调用 `EnterFreeMode` → 设置 IsFollowMode=false → TickFollowChar 不再更新摄像机位置
## 用例
| 引用方 | 路径 | 用途 |
|--------|------|------|
| BP_TestChar | `/Game/Blueprints/BP_TestChar` | 作为端点组件添加到角色,处理摄像机控制指令 |
| BP_TestCtl | `/Game/Blueprints/BP_TestCtl` | 引用 BP_ControllerComp 用于摄像机控制 |