Files
meishibiezb a8bdf281ff update
2026-06-05 03:01:15 +08:00

66 lines
4.0 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.
# BP_Bomb
## 基本信息
- **类型**: Blueprint (Actor)
- **父类**: Actor
- **源文件**: /Game/Blueprints/Playground/BP_Bomb.BP_Bomb
- **模块**: Content/Blueprints/Playground
## 功能概述
BP_Bomb 是物品系统和追踪器系统的交互核心示例 Actor。它结合了 IItemContainer物品容器接口、UItemTracer物品追踪器和 Owner 检测,演示了物品在 Actor 之间的完整生命周期:创建、追踪、转移和响应。
## 设计用意
BP_Bomb 是最复杂的蓝图示例,演示了物品系统的全部核心功能。它通过 ItemContainer 持有炸弹物品的容器,通过 ItemLocationUItemTracer追踪炸弹物品的位置变化通过 Item IDGUID实现跨容器追踪。追踪器绑定 OnItemMoved 委托当检测到炸弹转移到其他容器时触发相应的业务逻辑如爆炸。GetContainer() 和 FindActorInOuterChain 函数则演示了 C++/蓝图桥接模式——在蓝图层面实现等同于 C++ UItemTracer 的查找逻辑。
## 职责范围
BP_Bomb 负责演示物品+追踪器的完整交互流程,包括物品创建、容器查找、追踪器委托绑定、以及物品转移响应。底层容器存储实现由 UDefaultContainer 处理BP_Bomb 专注于物品生命周期管理的示例代码。
## 项目内依赖
| 依赖项 | 关系 | 源文件 |
|--------|------|--------|
| IItemContainer | 持有 (ItemContainer) | Item 插件 |
| UItemTracer | 持有 (ItemLocation) | Item 插件 |
## 外部视角
BP_Bomb 是 Actor 的子类,从外部调用者视角:
**公开属性(蓝图可读写)**
- `ItemContainer`IItemContainer 接口引用)— 持有的物品容器
- `Current Owner`Object*)— 当前拥有者
- `ItemLocation`UItemTracer*)— 物品位置追踪器
- `Item ID`Guid— 追踪的物品 GUID
**自定义函数**
- `GetContainer()``IItemContainer` — 获取当前持有的容器接口
- `FindActorInOuterChain(Object*)``Actor*` — 沿 Outer 链向上查找 Actor
**外部交互方式**
- 放置在 Playground 关卡中作为可交互对象
- 演示物品系统核心流程:创建 → 追踪 → 转移 → 响应
- 通过 ItemLocationUItemTracer绑定 OnItemMoved 委托,检测物品跨容器转移
**EventGraph 事件**
| 事件 | 类型 | 触发时机 | 行为 |
|------|------|----------|------|
| `事件开始运行` | 原生覆盖 (BeginPlay) | Actor 生成时由引擎自动触发 | 通过 GetContainer 获取容器 → CreateItem 创建炸弹物品 → GetItemProperty 获取 ItemTracer → 存入 ItemLocation → 存入 ItemID |
| `事件Actor开始重叠` | 原生覆盖 (OnActorBeginOverlap) | 其他 Actor 进入重叠区域 | 预留(当前无连线逻辑) |
| `事件Tick` | 原生覆盖 | 每帧 | Switch Has Authority → 服务器端逻辑处理 |
| `On Component Hit (Sphere)` | 组件绑定事件 | 球形碰撞体被击中时 | Switch Has Authority → 验证 ItemLocation 有效 → 按类获取 BP_InventoryComp → RequestMoveItem 请求物品移动 |
| `事件RequestMoveItem` | 接口事件 (来自 Inventory 系统) | Inventory 系统请求移动物品时 | 通过 GetContainer 获取容器 → ReceiveItem 接收物品 |
## 使用方法
BP_Bomb 在项目中的典型调用流程:
- **炸弹初始化流程** — BeginPlay → GetContainer → CreateItemTestBomb→ GetItemProperty获取 ItemTracer→ 存入 ItemLocation 和 ItemID → 追踪器绑定委托
- **物品移动触发流程** — 玩家拾取炸弹 → 炸弹被移出容器 → On Component Hit → 验证 ItemLocation → 获取目标 BP_InventoryComp → RequestMoveItem → 接口事件触发 → ReceiveItem 接收物品到新容器
- **追踪器响应流程** — ItemLocationUItemTracer检测到物品移动 → 触发 OnItemMoved 委托 → 执行爆炸/响应逻辑
## 用例
| 引用方 | 路径 | 用途 |
|--------|------|------|
| Playground | `/Game/地图关卡/Playground` | 关卡中放置的交互示例,演示物品系统全流程 |