|
ShitEngine
基于 C++20 与 SDL3 的轻量级 2D 游戏引擎
|
预制体,可重复生成相同配置的 GameObject 更多...
#include <Prefab.h>
类 | |
| struct | ComponentData |
| 单个组件的数据(类型名 + 反射字段值,JSON 可序列化) 更多... | |
Public 成员函数 | |
| nlohmann::json | toJson () const |
| 序列化为 JSON | |
| void | apply (GameObject *go) const |
| 把此预制体应用到已有 GameObject(反射克隆) | |
| GameObject * | instantiate (Scene *scene, const std::string &name="") const |
| 创建新 GameObject 并应用此预制体 | |
| bool | hasData () const |
| 是否包含反射数据 | |
| const std::vector< ComponentData > & | getComponents () const |
| 已捕获的组件数据(只读,供编辑器序列化/预览) | |
静态 Public 成员函数 | |
| static Prefab | Capture (GameObject *source) |
| 从现有 GameObject 捕获组件与字段(跳过 readOnly 字段与不可序列化类型) | |
| static Prefab | FromJson (const nlohmann::json &j) |
| 从 JSON 反序列化 | |
预制体,可重复生成相同配置的 GameObject
数据驱动:从现有 GameObject 捕获全部反射组件及字段值,实例化时通过 反射工厂 + 字段拷贝重建。支持 JSON 序列化(编辑器保存/加载预制体)。
auto prefab = Shit::Prefab::Capture(enemyGO); // 捕获 auto prefab = Shit::Prefab::FromJson(jsonData); // 或从 JSON 反序列化 auto* enemy = prefab.instantiate(scene, "enemy"); // 实例化 auto json = prefab.toJson(); // 序列化
| void apply | ( | GameObject * | go | ) | const |
把此预制体应用到已有 GameObject(反射克隆)
|
static |
从现有 GameObject 捕获组件与字段(跳过 readOnly 字段与不可序列化类型)
|
static |
从 JSON 反序列化
|
inline |
已捕获的组件数据(只读,供编辑器序列化/预览)
|
inline |
是否包含反射数据
| GameObject * instantiate | ( | Scene * | scene, |
| const std::string & | name = "" ) const |
创建新 GameObject 并应用此预制体
| nlohmann::json toJson | ( | ) | const |
序列化为 JSON