update
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
- **类型**: Blueprint (ActorComponent)
|
||||
- **父类**: BP_InventoryComp
|
||||
- **源文件**: /Game/Blueprints/Playground/BP_DropItemInvComp.BP_DropItemInvComp
|
||||
- **模块**: Content
|
||||
- **模块**: Content/Blueprints/Playground
|
||||
|
||||
## 功能概述
|
||||
BP_DropItemInvComp 是掉落物品库存组件,继承 BP_InventoryComp 并增加了一个 FName 类型的 `Item` 变量,用于指定该掉落物包含什么物品类型。适用于可拾取的掉落物 Actor。
|
||||
@@ -20,30 +20,39 @@ BP_DropItemInvComp 负责掉落物品的自动创建和作为可拾取物品容
|
||||
|--------|------|--------|
|
||||
| BP_InventoryComp | 父类 | /Game/Blueprints/Playground/BP_InventoryComp |
|
||||
|
||||
## 对外接口
|
||||
- **蓝图变量**(is_instance_editable):
|
||||
- `Item` (FName) -- 掉落物品的类型名称,对应数据表中物品行的 RowName。在组件实例上设置,指定该掉落物包含什么物品
|
||||
- **继承自 BP_InventoryComp 的全部接口**:
|
||||
- `DefaultContainer` -- 底层物品容器引用
|
||||
- `ViewCache` (TArray<FItemView>) -- 物品视图缓存
|
||||
- `OnViewChanged` -- 视图变化委托
|
||||
- `UpdateViewCache()` -- 刷新视图缓存
|
||||
- `CreateItemInternal(FName ItemType, int32 Count) -> bool` -- 创建物品
|
||||
- **继承自 BP_InventoryComp 的 IInventory 接口实现**:
|
||||
- `GetItemViews()`、`GetItemViewByID()`、`GetItemCount()` -- 查询接口
|
||||
- `RequestMoveItem(ID, TargetInventory)` -- 请求移出物品(掉落物被拾取时调用)
|
||||
- `ReceiveItem(ID, SourceContainer)` -- 从其他容器接收物品(拾取验证场景使用)
|
||||
- **EventGraph**:含 2 个事件和 7 个节点,在 BeginPlay 时根据 `Item` 变量自动调用 CreateItemInternal
|
||||
## 外部视角
|
||||
|
||||
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,无额外逻辑 |
|
||||
|
||||
## 使用方法
|
||||
- 作为 ActorComponent 添加到掉落物 Actor 上
|
||||
- 在组件实例上设置 `Item` 变量为数据表中物品的 RowName(FName 类型)
|
||||
- 在 BeginPlay 事件中自动调用 `CreateItemInternal(Item, 1)` 创建物品,实现掉落物生成
|
||||
- 可以通过设置 `DefaultContainer` 覆盖默认的 BP_DefaultContainer
|
||||
- 玩家拾取时,通过 IInventory::RequestMoveItem 将物品从掉落物容器转移至玩家库存
|
||||
- 掉落物的物理外观由所在的 Actor 负责,本组件仅处理物品数据的创建和转移
|
||||
- 继承自 BP_InventoryComp,所有库存管理功能均可用
|
||||
|
||||
BP_DropItemInvComp 在项目中的典型调用流程:
|
||||
|
||||
- **掉落物初始化流程** — 掉落物 Actor 创建 → BP_DropItemInvComp.BeginPlay → 调用父类 BP_InventoryComp BeginPlay → 服务器端读取 Item 变量 → CreateItemInternal 创建指定类型的物品到容器
|
||||
- **玩家拾取流程** — 玩家与掉落物碰撞 → 通过 IInventory 接口 RequestMoveItem → DropItemInvComp 的 DefaultContainer 取出物品 → ReceiveItem 转移到玩家 InventoryComp
|
||||
|
||||
## 用例
|
||||
- 掉落物 Actor 的库存组件,在运行时自动生成配置的物品
|
||||
- 其父类 BP_InventoryComp 同时被 WBP_InventoryView 引用以显示物品列表
|
||||
|
||||
| 引用方 | 路径 | 用途 |
|
||||
|--------|------|------|
|
||||
| Playground | `/Game/地图关卡/Playground` | 关卡中掉落物 Actor 的组件,管理掉落物品 |
|
||||
| BP_TestItem | `/Game/Blueprints/Playground/BP_TestItem` | 测试用物品管理组件 |
|
||||
|
||||
Reference in New Issue
Block a user