66 lines
3.3 KiB
Markdown
66 lines
3.3 KiB
Markdown
# BP_Barrel
|
||
|
||
## 基本信息
|
||
- **类型**: Blueprint (Actor)
|
||
- **父类**: Actor
|
||
- **源文件**: /Game/Blueprints/Playground/BP_Barrel.BP_Barrel
|
||
- **模块**: Content/Blueprints/Playground
|
||
|
||
## 功能概述
|
||
可交互的木桶 Actor,在 Playground 场景中作为可破坏或可互动物体。持有 BarrelWindow(WBP_Window)用于显示交互界面,与库存系统(BP_InventoryComp)和容器系统(BP_DefaultContainer)联动。
|
||
|
||
## 设计用意
|
||
Playground 场景中的测试用互动物体,用于验证 Actor 与 HUD/库存系统的交互流程。通过 BarrelWindow 窗口展示容器内容,验证库存 UI 与场景物体的数据交互。
|
||
|
||
## 职责范围
|
||
- 作为场景中的可互动物体持有 BarrelWindow 引用
|
||
- 通过 EventGraph(4 事件, 24 节点)处理交互逻辑
|
||
|
||
## 项目内依赖
|
||
| 依赖项 | 关系 | 源文件 |
|
||
|--------|------|--------|
|
||
| BP_Hud | 引用 | /Game/Blueprints/BP_Hud |
|
||
| WBP_InventoryView | 引用 | /Game/Blueprints/UI/Item/WBP_InventoryView |
|
||
| WBP_Window | 包含(变量) | /Game/Blueprints/UI/WBP_Window |
|
||
| BP_TestCtl | 引用 | /Game/Blueprints/BP_TestCtl |
|
||
| BP_InventoryComp | 引用 | /Game/Blueprints/Playground/BP_InventoryComp |
|
||
| BP_DefaultContainer | 引用 | /Game/Blueprints/Playground/BP_DefaultContainer |
|
||
|
||
## 外部视角
|
||
|
||
BP_Barrel 是 Actor 的子类,从外部调用者视角:
|
||
|
||
**公开属性(蓝图可读写)**
|
||
- `BarrelWindow`(WBP_Window_C*)— 木桶交互界面的窗口 Widget
|
||
|
||
**核心行为**
|
||
- 通过 BP_Hud 获取 InvView(WBP_InventoryView)显示木桶内物品
|
||
- 通过 BP_InventoryComp / BP_DefaultContainer 管理木桶库存
|
||
- 通过 BP_TestCtl 获取控制器引用
|
||
|
||
**EventGraph 事件**
|
||
|
||
| 事件 | 类型 | 触发时机 | 行为 |
|
||
|------|------|----------|------|
|
||
| `事件开始运行` | 原生覆盖 (BeginPlay) | Actor 生成时由引擎自动触发 | 创建 BP_DefaultContainer → 通过 IItemContainer 创建随机数量的 TestItem → 遍历新物品 ID → 通过 IInventory 接收物品 |
|
||
| `事件Actor开始重叠` | 原生覆盖 (OnActorBeginOverlap) | 其他 Actor 进入重叠区域时 | 预留(当前无连线逻辑) |
|
||
| `事件Tick` | 原生覆盖 | 每帧 | 预留(当前无连线逻辑) |
|
||
| `On Clicked (Barrel)` | 组件绑定事件 | 玩家点击木桶碰撞体时 | 获取 PlayerController → GetHUD → Cast 到 BP_Hud → 创建 WBP_Window(设 IsTemp=true)和 WBP_InventoryView → BindToComp 绑定到木桶的 BP_InventoryComp → 作为子项添加到 HUD |
|
||
|
||
**外部交互方式**
|
||
- 放置在 Playground 关卡中作为可交互场景物体
|
||
- 玩家靠近/与木桶交互时,通过 HUD 显示库存界面
|
||
|
||
## 使用方法
|
||
|
||
BP_Barrel 在项目中的典型调用流程:
|
||
|
||
- **木桶交互流程** — 玩家点击木桶碰撞体 → 触发 On Clicked (Barrel) → 获取 PlayerController → GetHUD → Cast 到 BP_Hud → 创建临时 WBP_Window 和 WBP_InventoryView → BindToComp 绑定到木桶的 BP_InventoryComp → 显示木桶库存 UI
|
||
- **木桶初始化流程** — BeginPlay → 创建 BP_DefaultContainer → 调用 CreateItem 生成随机数量 TestItem → 通过 IInventory 接口接收物品到木桶的 InventoryComp
|
||
|
||
## 用例
|
||
|
||
| 引用方 | 路径 | 用途 |
|
||
|--------|------|------|
|
||
| Playground | `/Game/地图关卡/Playground` | 关卡中的可交互木桶,演示物品查看/拾取流程 |
|