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

4.2 KiB
Raw Blame History

BP_TestChar

基本信息

  • 类型: Blueprint (Actor)
  • 父类: AMyCharacter
  • 源文件: /Game/Blueprints/BP_TestChar.BP_TestChar
  • 模块: Content

功能概述

BP_TestChar 是玩家主角的蓝图实现,继承 C++ 的 AMyCharacter。它通过添加 CharacterControl 插件的路由组件来扩展角色能力,在蓝图层面组合移动、指令路由和摄像机控制。

设计用意

AMyCharacter 在 C++ 层提供了移动和摄像机 Pawn 创建的基础能力。BP_TestChar 在蓝图层面通过组件化的方式组装角色功能:添加 UCommandRouterComponent 将角色变成指令路由中心,添加各种 ICommandEndpoint 组件处理不同类型的指令。作为项目的核心 Pawn它是指令系统和角色能力的"组装层"——新功能通过添加新的端点组件来扩展,而非修改 C++ 代码。

职责范围

BP_TestChar 是角色的蓝图配置层,负责添加并配置 CharacterControl 路由组件和端点组件实现角色重叠、Tick 等蓝图级逻辑。移动逻辑由 AMyCharacter C++ 层处理,摄像机逻辑由 ACameraPawn 负责。

项目内依赖

依赖项 关系 源文件
AMyCharacter 父类 /Game/Blueprints/BP_TestChar (C++ 继承)
ACameraPawn 间接CameraActorClass /Game/Blueprints/BP_CameraPawn
UCommandRouterComponent 组件 CharacterControl 插件
BP_UniversalEndpointComp 组件 /Game/Blueprints/Component/BP_UniversalEndpointComp
BP_MoveInput 组件 /Game/Blueprints/Component/BP_MoveInput
BP_ControllerComp 组件 /Game/Blueprints/Component/BP_ControllerComp
BP_SayHello 组件 /Game/Blueprints/Component/BP_SayHello

对外接口

  • 继承自 AMyCharacter 的 BlueprintCallable 函数
    • Move(const FInputActionValue& Value) -- 移动输入处理,供 EnhancedInput 绑定调用
    • BeginRun(const FInputActionValue& Value) / StopRun(const FInputActionValue& Value) -- 奔跑切换
    • BeginCrouch(const FInputActionValue& Value) / StopCrouch(const FInputActionValue& Value) -- 蹲伏切换
    • IsRunning() const / IsCrouching() const -- 状态查询
  • 继承自 AMyCharacter 的 BlueprintReadOnly 属性
    • DefaultMapping (UInputMappingContext*) -- 默认输入映射上下文
    • MoveAction, RunAction, CrouchAction, CameraMoveAction, CameraZoomAction, CameraResetAction, CameraRotateAction -- 各输入动作引用
    • CameraActorClass (TSubclassOf) -- 摄像机 Pawn 类,设置为 BP_CameraPawn
  • 身上的组件作为对外能力
    • UCommandRouterComponent -- 指令路由中心,通过 RegisterEndpoint / InputCommand 接收和分发指令
    • BP_UniversalEndpointComp -- 通用端点,对外暴露 CommandReceivedDispatcher 动态多播委托
    • BP_MoveInput -- 移动端点,对外暴露 CharMove (CharacterMovementComponent*) 变量
    • BP_ControllerComp -- 摄像机控制端点,对外暴露 MoveControllerRotateControllerZoomCameraResetControllerLocationTickFollowChar 函数及摄像机配置参数
    • BP_SayHello -- 测试端点,验证指令路由系统

使用方法

  • 在 BP_TestMode 中设置为 DefaultPawnClass,作为项目的默认 Pawn
  • 在蓝图编辑器中添加 CharacterControl 路由和端点组件:UCommandRouterComponent 作为指令路由器,BP_UniversalEndpointCompBP_MoveInputBP_ControllerCompBP_SayHello 作为各类指令端点
  • 通过父类 AMyCharacter 的 CameraActorClass 属性指定 BP_CameraPawn 作为分离式摄像机
  • 配置父类的 InputAction 属性MoveAction、RunAction 等)连接 EnhancedInput 系统
  • 各端点组件通过 EndpointState.InterestedTags 配置关注的 GameplayTagUCommandRouterComponent 的 AutoRegisterEndpoints 在 BeginPlay 时自动注册所有组件上的端点
  • 指令链路EnhancedInput -> UCommandInputComponent -> UCommandRouterComponent -> 匹配的端点组件

用例

  • BP_TestMode 的 DefaultPawnClass,作为玩家进入关卡时的默认角色
  • 身上挂载的 BP_UniversalEndpointCompBP_MoveInputBP_ControllerCompBP_SayHello 作为该角色的指令处理端点
  • CameraActorClass 属性引用 BP_CameraPawn角色被 Possess 时自动生成摄像机