ShitEngine
1.4.2
基于 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
class
TypeInfo
;
11
23
class
SHIT_API
Prefab {
24
public
:
26
struct
ComponentData
{
27
std::string
typeName
;
28
uint64_t
uuid
= 0;
29
nlohmann::json
fields
;
30
nlohmann::json
properties
;
31
};
32
34
static
Prefab
Capture
(
GameObject
* source);
35
37
static
Prefab
FromJson
(
const
nlohmann::json& j);
38
40
nlohmann::json
toJson
()
const
;
41
43
void
apply
(
GameObject
* go)
const
;
44
46
GameObject
*
instantiate
(
Scene
* scene,
const
std::string& name =
""
)
const
;
47
49
bool
hasData
()
const
{
return
!m_components.empty(); }
50
52
const
std::vector<ComponentData>&
getComponents
()
const
{
return
m_components; }
53
54
private
:
55
Prefab
() =
default
;
56
59
void
applyInternal(
GameObject
* go,
bool
restoreUuid)
const
;
60
63
void
applyProperties(
const
TypeInfo
* ti,
const
ComponentData& data,
Component
* comp)
const
;
64
65
std::vector<ComponentData> m_components;
66
};
67
68
}
// namespace Shit
SHIT_API
#define SHIT_API
定义
Core.h:14
GameObject.h
Shit::Component
组件基类
定义
Component.h:25
Shit::GameObject
游戏物体类
定义
GameObject.h:23
Shit::Prefab
预制体,可重复生成相同配置的 GameObject
定义
Prefab.h:23
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:52
Shit::Prefab::hasData
bool hasData() const
是否包含反射数据
定义
Prefab.h:49
Shit::Prefab::apply
void apply(GameObject *go) const
把此预制体应用到已有 GameObject(反射克隆;恢复记录的组件 UUID)
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:36
Shit
定义
AnimationClip.h:12
Shit::Prefab::ComponentData
单个组件的数据(类型名 + 持久 UUID + 反射字段值,JSON 可序列化)
定义
Prefab.h:26
Shit::Prefab::ComponentData::fields
nlohmann::json fields
字段名 → 值(仅反射且可序列化的字段)
定义
Prefab.h:29
Shit::Prefab::ComponentData::uuid
uint64_t uuid
组件持久 ID(0 = 未记录,加载时现场分配)
定义
Prefab.h:28
Shit::Prefab::ComponentData::typeName
std::string typeName
组件类型名(TypeRegistry::Get 查询)
定义
Prefab.h:27
Shit::Prefab::ComponentData::properties
nlohmann::json properties
属性名 → 值(SHIT_PROPERTY getter/setter 对,可读写者随档)
定义
Prefab.h:30
Shit::TypeInfo
定义
TypeInfo.h:96
include
ShitEngine
GameObject
Prefab.h
制作者
1.17.0