Files
loneseDocument/Content/Blueprints/BP_ControllerComp.md
meishibiezb 29a3f77908 init
2026-06-04 21:44:13 +08:00

56 lines
3.4 KiB
Markdown
Raw 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
## 功能概述
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) | 引擎内置 |
## 对外接口
- **蓝图函数**
- `MoveController(A: GameplayTag, InVec: Vector)` -- 摄像机移动指令处理,接收 GameplayTag 和移动向量
- `RotateController(A: GameplayTag, InVec: Vector)` -- 摄像机旋转指令处理
- `ZoomCamera(A: GameplayTag, InVec: Vector)` -- 摄像机缩放指令处理,通过 InVec 中的值调整臂长
- `ResetControllerLocation(DiscreteMeta: DiscreteMeta)` -- 摄像机位置重置,接收离散命令元数据
- `TickFollowChar()` -- 跟随模式每帧更新,将摄像机位置锁定到 FollowedChar
- **蓝图变量**(均为 is_instance_editable
- `MoveSpeed` (double) -- 摄像机移动速度
- `MinArmLength` (double) -- 最小臂长
- `MaxArmLength` (double) -- 最大臂长
- `ZoomSpeed` (double) -- 缩放速度
- `IsFollowMode` (bool) -- 是否启用跟随模式
- `FollowedChar` (Character*) -- 跟随目标角色引用
- **继承自 (BP_EndpointComp_C / UEndpointComponent) 的接口**
- `EndpointState` -- 端点状态,含 `InterestedTags` 配置摄像机控制相关标签
- `OnCommandReceived` -- 收到指令时的处理入口
- **EventGraph**:含 6 个事件和 27 个节点,处理摄像机控制的核心逻辑
## 使用方法
- 作为 ActorComponent 添加到 BP_TestChar
- 在组件实例上配置 `MoveSpeed``MinArmLength``MaxArmLength``ZoomSpeed` 等摄像机参数
- 通过 `EndpointState.InterestedTags` 配置关注的摄像机控制 GameplayTag如 "Camera.Move"、"Camera.Zoom"、"Camera.Rotate"、"Camera.Reset"
- 开启 `IsFollowMode` 并设置 `FollowedChar` 可启用角色跟随模式
- `MoveController``RotateController``ZoomCamera` 函数由 OnCommandReceived 事件根据指令标签分发调用
- `TickFollowChar()` 在 EventGraph 的 Tick 事件中调用,实现每帧跟随
- `UCommandRouterComponent` 自动发现并注册本组件
## 用例
- BP_TestChar 的组件,处理摄像机控制指令
- 通过配置参数在运行时动态调整 ACameraPawn 的行为(臂长、速度、跟随目标)