ShitEngine
基于 C++20 与 SDL3 的轻量级 2D 游戏引擎
Toggle main menu visibility
载入中...
搜索中...
未找到
Prefab.h
浏览该文件的文档.
1
#pragma once
2
#include "
GameObject.h
"
3
#include <nlohmann/json.hpp>
4
#include <string>
5
#include <vector>
6
7
namespace
Shit
{
8
9
class
Scene
;
10
22
class
SHIT_API
Prefab {
23
public
:
25
struct
ComponentData
{
26
std::string
typeName
;
27
nlohmann::json
fields
;
28
};
29
31
static
Prefab
Capture
(
GameObject
* source);
32
34
static
Prefab
FromJson
(
const
nlohmann::json& j);
35
37
nlohmann::json
toJson
()
const
;
38
40
void
apply
(
GameObject
* go)
const
;
41
43
GameObject
*
instantiate
(
Scene
* scene,
const
std::string& name =
""
)
const
;
44
46
bool
hasData
()
const
{
return
!m_components.empty(); }
47
49
const
std::vector<ComponentData>&
getComponents
()
const
{
return
m_components; }
50
51
private
:
52
Prefab
() =
default
;
53
54
std::vector<ComponentData> m_components;
55
};
56
57
}
// namespace Shit
SHIT_API
#define SHIT_API
定义
Core.h:14
GameObject.h
Shit::GameObject
游戏物体类
定义
GameObject.h:23
Shit::Prefab
预制体,可重复生成相同配置的 GameObject
定义
Prefab.h:22
Shit::Prefab::toJson
nlohmann::json toJson() const
序列化为 JSON
Shit::Prefab::Capture
static Prefab Capture(GameObject *source)
从现有 GameObject 捕获组件与字段(跳过 readOnly 字段与不可序列化类型)
Shit::Prefab::getComponents
const std::vector< ComponentData > & getComponents() const
已捕获的组件数据(只读,供编辑器序列化/预览)
定义
Prefab.h:49
Shit::Prefab::hasData
bool hasData() const
是否包含反射数据
定义
Prefab.h:46
Shit::Prefab::apply
void apply(GameObject *go) const
把此预制体应用到已有 GameObject(反射克隆)
Shit::Prefab::FromJson
static Prefab FromJson(const nlohmann::json &j)
从 JSON 反序列化
Shit::Prefab::instantiate
GameObject * instantiate(Scene *scene, const std::string &name="") const
创建新 GameObject 并应用此预制体
Shit::Scene
场景类
定义
Scene.h:34
Shit
定义
AudioPlayer.h:10
Shit::Prefab::ComponentData
单个组件的数据(类型名 + 反射字段值,JSON 可序列化)
定义
Prefab.h:25
Shit::Prefab::ComponentData::fields
nlohmann::json fields
字段名 → 值(仅反射且可序列化的字段)
定义
Prefab.h:27
Shit::Prefab::ComponentData::typeName
std::string typeName
组件类型名(TypeRegistry::Get 查询)
定义
Prefab.h:26
include
ShitEngine
GameObject
Prefab.h
制作者
1.17.0