Files
loneseDocument/Content/Blueprints/BP_DropItemInvComp.md
meishibiezb a8bdf281ff update
2026-06-05 03:01:15 +08:00

59 lines
3.0 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_DropItemInvComp
## 基本信息
- **类型**: Blueprint (ActorComponent)
- **父类**: BP_InventoryComp
- **源文件**: /Game/Blueprints/Playground/BP_DropItemInvComp.BP_DropItemInvComp
- **模块**: Content/Blueprints/Playground
## 功能概述
BP_DropItemInvComp 是掉落物品库存组件,继承 BP_InventoryComp 并增加了一个 FName 类型的 `Item` 变量,用于指定该掉落物包含什么物品类型。适用于可拾取的掉落物 Actor。
## 设计用意
BP_DropItemInvComp 将 BP_InventoryComp 的通用库存功能特化为"掉落物"用途。通过 Item 变量指定掉落物的物品类型,在 BeginPlay 时自动调用继承的 CreateItemInternal 创建物品,结合继承的 IInventory 接口实现支持玩家通过 ReceiveItem 拾取。这种设计使掉落物 Actor 只需添加一个组件并设置一个变量即可完整支持物品掉落和拾取流程。
## 职责范围
BP_DropItemInvComp 负责掉落物品的自动创建和作为可拾取物品容器运行。掉落物的物理表现由所在的 Actor 负责,复杂的物品行为由物品类型配置决定。
## 项目内依赖
| 依赖项 | 关系 | 源文件 |
|--------|------|--------|
| BP_InventoryComp | 父类 | /Game/Blueprints/Playground/BP_InventoryComp |
## 外部视角
BP_DropItemInvComp 是 BP_InventoryComp 的蓝图子类,从外部调用者视角:
**新增属性(蓝图可读写)**
- `Item`FName— 掉落物包含的物品类型名称
**继承的行为**
- 继承 BP_InventoryComp 的全部接口DefaultContainer、ViewCache、OnViewChanged、UpdateViewCache、CreateItemInternal
- 在 BeginPlay 时根据 Item 变量值自动调用 CreateItemInternal 创建对应物品
**外部交互方式**
- 作为 Actor 的组件(例如可拾取的掉落物 Actor
- 玩家通过 IInventory 接口的 ReceiveItem 拾取物品
- 外部系统通过父类 BP_InventoryComp 的接口操作
**EventGraph 事件**
| 事件 | 类型 | 触发时机 | 行为 |
|------|------|----------|------|
| `事件开始运行` | 原生覆盖 (BeginPlay) | 组件创建时由引擎自动触发 | 调用父类 BeginPlay → Switch Has Authority → 读取 Item 变量 → 调用 CreateItemInternal 创建指定类型的掉落物品 |
| `事件Tick` | 原生覆盖 | 每帧 | 调用父类 Tick无额外逻辑 |
## 使用方法
BP_DropItemInvComp 在项目中的典型调用流程:
- **掉落物初始化流程** — 掉落物 Actor 创建 → BP_DropItemInvComp.BeginPlay → 调用父类 BP_InventoryComp BeginPlay → 服务器端读取 Item 变量 → CreateItemInternal 创建指定类型的物品到容器
- **玩家拾取流程** — 玩家与掉落物碰撞 → 通过 IInventory 接口 RequestMoveItem → DropItemInvComp 的 DefaultContainer 取出物品 → ReceiveItem 转移到玩家 InventoryComp
## 用例
| 引用方 | 路径 | 用途 |
|--------|------|------|
| Playground | `/Game/地图关卡/Playground` | 关卡中掉落物 Actor 的组件,管理掉落物品 |
| BP_TestItem | `/Game/Blueprints/Playground/BP_TestItem` | 测试用物品管理组件 |