Files
ChildHood/docs/technical/笔记/P-013-收集系统Widget蓝图创建指南.md
2026-06-15 05:13:28 +08:00

91 lines
3.6 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.
# 收集系统 Widget 蓝图创建指南(P-013)
> 配套 C++ 代码:`Source/ChildHood/Collection/` 下的 3 个 Widget 基类
> 对应技术方案:`docs/technical/收集系统-技术方案.md` 第7节(美术资源)
> 状态:C++ 基类已就位,需在 UE 编辑器创建 3 个 UMG 蓝图并配置角色
---
## 创建步骤
3 个 Widget 蓝图都需**继承对应 C++ 基类**,并确保组件名/动画名与 `BindWidget`/`BindWidgetAnim` 精确匹配(否则运行时绑定失败、C++ 判空跳过对应逻辑)。
### 1. WBP_CollectionNotification(收集通知)
| 项 | 值 |
|----|----|
| 父类 | `UCollectionNotifWidget` |
| 路径 | `Content/UI/WBP_CollectionNotification` |
| ZOrder | 10(C++ `AddToViewport(10)`) |
**必需绑定组件**(名字必须完全一致):
- `TextBlock` 名 **`NotifTextBlock`** — 通知文字
- `WidgetAnimation` 名 **`FadeInAnim`** — 淡入(整体 Opacity 0→1,0.2s)
- `WidgetAnimation` 名 **`FadeOutAnim`** — 淡出(整体 Opacity 1→0,0.3s)
**布局**:右上角锚点(与拾取通知错位,执行案第二节「在拾取通知下方」)。
**文字颜色**:由 C++ 通过 `NotifTextColor`(浅金色 #F0D060)运行时设置,蓝图 TextBlock 默认颜色无所谓。
---
### 2. WBP_CollectionProgress(进度 HUD)
| 项 | 值 |
|----|----|
| 父类 | `UCollectionProgressWidget` |
| 路径 | `Content/UI/WBP_CollectionProgress` |
| ZOrder | 5 |
**必需绑定组件**:
- `TextBlock` 名 **`ProgressTextBlock`** — 进度文本(C++ 设为 `📦 杂物 X/Y`)
- `WidgetAnimation` 名 **`BounceAnim`** — 数字弹性(`ProgressTextBlock` 的 RenderScale 1.0→1.2→1.0,0.2s)
- `WidgetAnimation` 名 **`CompleteAnim`** — 完成弹性(RenderScale→1.4x,0.5s)
**布局**:左上角锚点(Anchors Top Left),距左 3% 屏宽、距上 3% 屏高(执行案第三节)。
**颜色**:C++ `NormalColor`(白)/`CompleteColor`(金 #F0D060)运行时切换,蓝图默认白色即可。
---
### 3. WBP_CollectionComplete(完成提示)
| 项 | 值 |
|----|----|
| 父类 | `UCollectionCompleteWidget` |
| 路径 | `Content/UI/WBP_CollectionComplete` |
| ZOrder | 20 |
**必需绑定组件**:
- `TextBlock` 名 **`CompleteTextBlock`** — 完成文字(C++ 设为「杂物全部收集完成!」)
- `WidgetAnimation` 名 **`FadeInAnim`** — 淡入
- `WidgetAnimation` 名 **`FadeOutAnim`** — 淡出
**布局**:中心锚点(Anchors Center),白色大字,屏幕正中。
**显示时序**:C++ 控制(淡入→停留 2.0s→淡出→自移除),蓝图只做视觉。
---
## 配置角色蓝图
在角色蓝图(`BP_ChildHoodCharacter` 或当前使用的角色蓝图)中,选中 `CollectionHUDComponent`,在 Details 面板设置三个 WidgetClass:
```
NotifWidgetClass = WBP_CollectionNotification
ProgressWidgetClass = WBP_CollectionProgress
CompleteWidgetClass = WBP_CollectionComplete
```
> 未设置时 C++ 判空跳过 UI 创建,收集逻辑仍正常运行(仅无 UI 显示)。补全蓝图后即完整可玩。
---
## 配置拾取物交互物(与交互系统 P-016 配合)
收集系统通过 `AddToBackpack` Action 接收物品事件。每个拾取/翻找物的 `InteractableComponent.Data` 需配置:
- `Category` = **`杂物`**(关键!收集系统据此判定追踪品类)
- `ItemId` = 唯一 ID(如 `marble_blue`、`card_wusong`)
- `DisplayName` = 显示名(如 `彩色弹珠(蓝色)`)
- `InteractEffect` 含 `AddToBackpack` Action(拾取物在动画物品消失时间点触发)
详见执行案「v0.1 杂物品类清单」10 个物品的 ItemId/名称映射。