ShitEngine
1.4.2
基于 C++20 与 SDL3 的轻量级 2D 游戏引擎
Toggle main menu visibility
载入中...
搜索中...
未找到
SceneSerializer.h
浏览该文件的文档.
1
#pragma once
2
#include "
../Core/Core.h
"
3
#include <nlohmann/json.hpp>
4
5
#include <string>
6
#include <vector>
7
8
namespace
Shit
{
9
class
Scene
;
10
class
GameObject
;
11
33
class
SHIT_API
SceneSerializer
final {
34
public
:
37
static
nlohmann::json
toJson
(
Scene
* scene,
const
std::vector<std::string>& excludeNames = {});
38
41
static
nlohmann::json
toJson
(
Shit::GameObject
* root);
42
46
static
void
fromJson
(
const
nlohmann::json& doc,
Scene
* scene);
47
};
48
}
Core.h
SHIT_API
#define SHIT_API
定义
Core.h:14
Shit::GameObject
游戏物体类
定义
GameObject.h:23
Shit::Scene
场景类
定义
Scene.h:36
Shit::SceneSerializer
全场景序列化器 —— .scene 文件的事实标准(v2)
定义
SceneSerializer.h:33
Shit::SceneSerializer::toJson
static nlohmann::json toJson(Scene *scene, const std::vector< std::string > &excludeNames={})
序列化整个场景(含层级)为 v2 JSON。被排除的对象(如编辑器相机)不落盘, 其子对象提升为根(parent=-1)。
Shit::SceneSerializer::toJson
static nlohmann::json toJson(Shit::GameObject *root)
序列化单个对象及其子树(父先于子,parent 为数组内下标;根对象 parent=-1)—— 编辑器「存为预置」的 .prefab 资产格式(与 .scene 同构,可直接 fromJson 实例化)...
Shit::SceneSerializer::fromJson
static void fromJson(const nlohmann::json &doc, Scene *scene)
把 JSON 追加实例化进目标场景(对象 + 组件 + 层级 + 相机兜底)。 调用方负责前置清场(如编辑器"打开"先删旧对象); 实例化失败仅跳过对应对象,不抛异常、不影响已加载部分。
Shit
定义
AnimationClip.h:12
include
ShitEngine
Scene
SceneSerializer.h
制作者
1.17.0