update
This commit is contained in:
@@ -4,44 +4,64 @@
|
||||
- **类型**: Blueprint (HUD)
|
||||
- **父类**: HUD
|
||||
- **源文件**: /Game/Blueprints/BP_Hud.BP_Hud
|
||||
- **模块**: Content
|
||||
- **模块**: Content/Blueprints
|
||||
|
||||
## 功能概述
|
||||
BP_Hud 是项目的 HUD 蓝图,管理三个 UI 窗口的引用:物品栏窗口(InvView,类型 WBP_InventoryView)、库存窗口(InventoryWindow)和提示窗口(HintWindow)。作为 UI 系统的"根"容器,持有并显示各种 Widget。
|
||||
游戏主 HUD,管理三个 UI 窗口的引用:物品栏视图(InvView → WBP_InventoryView)、库存窗口(InventoryWindow → WBP_Window)、提示窗口(HintWindow → WBP_Window),并在 EventGraph 中引用 BP_UniversalEndpointComp 处理端点通信。作为 UI 系统的根容器,负责 Widget 的创建和生命周期管理。
|
||||
|
||||
## 设计用意
|
||||
BP_Hud 将 UI 管理集中在 HUD 中,而不是分散在各个 Widget 或 Controller 中。它将物品视图、库存窗口和提示窗口都集中持有在一个地方,作为 UI 系统的入口点,方便其他系统通过 HUD 访问和操作 UI。
|
||||
选择继承 Engine.HUD 而非在 PlayerController 或 Pawn 中管理 UI,是因为 HUD 是 UE 原生提供的 UI 渲染层入口,拥有独立的绘制生命周期(DrawHUD),且不干扰游戏逻辑层的更新频率。将三个核心窗口的引用集中到 HUD 后,其他系统只需要通过 PlayerController→GetHUD() 即可访问所有 UI 组件,避免了全局单例或漫长的引用传递链。
|
||||
|
||||
## 职责范围
|
||||
BP_Hud 负责持有主要 UI 窗口引用并作为 UI 系统的入口点。具体的 UI 逻辑(物品列表渲染、窗口交互、提示显示)由各 Widget 自身负责,BP_Hud 仅提供引用的集中管理。
|
||||
- 在游戏初始化时创建 InvView、InventoryWindow、HintWindow 三个 Widget
|
||||
- 持有这三个 Widget 的引用,作为其他系统获取 UI 实例的入口
|
||||
- 不介入各 Widget 内部的具体交互逻辑(物品渲染、窗口拖拽、提示内容由各自 Widget 负责)
|
||||
- 不处理输入事件分发。
|
||||
|
||||
## 项目内依赖
|
||||
| 依赖项 | 关系 | 源文件 |
|
||||
|--------|------|--------|
|
||||
| WBP_InventoryView | 引用 (InvView) | /Game/Blueprints/UI/Item/WBP_InventoryView |
|
||||
| WBP_Window | 引用 (InventoryWindow, HintWindow) | /Game/Blueprints/UI/WBP_Window |
|
||||
| WBP_InventoryView | 包含(变量InvView) | /Game/Blueprints/UI/Item/WBP_InventoryView |
|
||||
| WBP_Window | 包含(变量InventoryWindow, HintWindow) | /Game/Blueprints/UI/WBP_Window |
|
||||
| WBP_Hint | 引用(EventGraph) | /Game/Blueprints/UI/WBP_Hint |
|
||||
| BP_UniversalEndpointComp | 引用(EventGraph) | /Game/Blueprints/Component/BP_UniversalEndpointComp |
|
||||
|
||||
## 对外接口
|
||||
- **蓝图可编辑变量**(均为 Instance Editable):
|
||||
- `InvView` (WBP_InventoryView_C*) -- 物品栏视图 Widget 引用,类型为 WBP_InventoryView
|
||||
- `InventoryWindow` (WBP_Window_C*) -- 库存窗口 Widget 引用,类型为 WBP_Window
|
||||
- `HintWindow` (WBP_Window_C*) -- 提示窗口 Widget 引用,类型为 WBP_Window
|
||||
- **继承自 AHUD 的标准接口**:
|
||||
- `DrawHUD()` -- HUD 绘制入口
|
||||
- `ReceiveDrawHUD(SizeX, SizeY)` -- 蓝图可覆盖的 UI 绘制事件
|
||||
- `GetOwningPlayerController()` -- 获取所属的 PlayerController
|
||||
- HUD 生命周期事件(BeginPlay、EndPlay 等)
|
||||
- **EventGraph**:含 4 个事件和 39 个节点,负责 Widget 的创建和初始化逻辑
|
||||
## 外部视角
|
||||
|
||||
BP_Hud 是纯蓝图 HUD(无 C++ 子类),从外部调用者视角:
|
||||
|
||||
**公开 Widget 变量(蓝图可读写)**
|
||||
- `InvView`(WBP_InventoryView_C*)— 物品栏视图 Widget 引用
|
||||
- `InventoryWindow`(WBP_Window_C*)— 库存窗口 Widget 引用
|
||||
- `HintWindow`(WBP_Window_C*)— 提示窗口 Widget 引用
|
||||
|
||||
上述三个变量均标记为 InstanceEditable,其他蓝图可通过 `GetPlayerController→GetHUD→Cast To BP_Hud_C` 访问。HUD 本身无自定义 BlueprintCallable 函数,所有交互通过操作这三个 Widget 引用间接完成。
|
||||
|
||||
**EventGraph 事件**
|
||||
|
||||
| 事件 | 类型 | 触发时机 | 行为 |
|
||||
|------|------|----------|------|
|
||||
| `事件开始运行` | 原生覆盖 (BeginPlay) | HUD 创建时由引擎自动触发 | 创建 InventoryWindow、InvView、HintWindow 三个 Widget,添加到视口;绑定 BP_UniversalEndpointComp 的 Command Received 委托到 DealWithCommand |
|
||||
| `DealWithCommand` | 自定义事件 | 收到 BP_UniversalEndpointComp 的指令数据包时 | 解析 CommandPacket → 提取 DiscreteMeta 中的 GameplayTag → 若匹配 "Gameplay.Action.UI.Hint" 则切换 HintWindow 显示/隐藏,否则切换 InventoryWindow 显示/隐藏 |
|
||||
|
||||
**外部交互方式**
|
||||
- 游戏模式在启动时自动创建 BP_Hud,并初始化三个子 Widget
|
||||
- 外部系统获取 BP_Hud 实例后,通过读取其 Widget 变量访问 UI 组件
|
||||
- 指令路由系统通过 BP_UniversalEndpointComp 间接向 BP_Hud 发送 UI 控制指令
|
||||
|
||||
## 使用方法
|
||||
- 在 BP_TestMode 中设置为 `HUDClass`,每次 PlayerController 初始化时自动创建
|
||||
- 在蓝图 EventGraph 中创建和初始化三个 Widget:`InvView`(物品栏)、`InventoryWindow`(库存窗口)、`HintWindow`(提示窗口)
|
||||
- 三个 Widget 变量为 Instance Editable,可在编辑器中替换为不同的 Widget 子类
|
||||
- 其他系统通过 `PlayerController->GetHUD()` 获取 BP_Hud 实例,再通过变量访问各 Widget
|
||||
- 作为 UI 系统的"根"容器,所有主要 UI 窗口的引用集中在此处管理
|
||||
|
||||
BP_Hud 是纯蓝图 HUD,在项目中通过以下调用链工作:
|
||||
|
||||
- **游戏初始化流程** — 引擎启动游戏 → BP_TestMode 将 BP_Hud 设为 HUDClass → 生成 BP_Hud 实例 → 触发`事件开始运行` → 创建 InvView/InventoryWindow/HintWindow 三个 Widget 并添加到视口
|
||||
- **指令驱动的 UI 切换流程** — 外部系统(如 BP_ControllerComp)发送 CommandPacket → BP_UniversalEndpointComp 接收并派发 → BP_Hud 的 `DealWithCommand` 处理 → 解析 GameplayTag → 切换 HintWindow 或 InventoryWindow 的可见性
|
||||
- **外部访问 UI 组件流程** — 任何蓝图(如 BP_Barrel、BP_InventoryComp)→ GetPlayerController → GetHUD → Cast To BP_Hud_C → 直接读写 InvView/InventoryWindow/HintWindow 变量
|
||||
|
||||
## 用例
|
||||
- BP_TestMode 的 `HUDClass`,玩家进入关卡时生成
|
||||
- `InvView` 变量引用 WBP_InventoryView,物品系统通过此引用更新物品列表 UI
|
||||
- `InventoryWindow` 变量引用 WBP_Window,库存窗口的显示和隐藏通过此引用控制
|
||||
- `HintWindow` 变量引用 WBP_Window,提示信息的显示通过此引用控制
|
||||
|
||||
| 引用方 | 路径 | 用途 |
|
||||
|--------|------|------|
|
||||
| BP_TestMode | `/Game/Blueprints/BP_TestMode` | 将 BP_Hud 设为 HUDClass,作为游戏全局 UI 根容器 |
|
||||
| BP_TestCtl | `/Game/Blueprints/BP_TestCtl` | 通过 GetHUD 获取 BP_Hud,访问子 Widget |
|
||||
| BP_Barrel | `/Game/Blueprints/Playground/BP_Barrel` | 通过 BP_Hud 获取 InventoryWindow 和 InvView,实现木桶 UI |
|
||||
| BP_InventoryComp | `/Game/Blueprints/Playground/BP_InventoryComp` | 引用 BP_Hud 用于库存 UI 联动 |
|
||||
|
||||
Reference in New Issue
Block a user