forked from sailro/EscapeFromTarkov-Trainer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SceneDumper.cs
109 lines (90 loc) · 1.88 KB
/
SceneDumper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace EFT.Trainer
{
public class SceneDumper
{
[Serializable]
public class NamedData
{
public string Name;
public NamedData()
{
}
public override string ToString()
{
return Name;
}
}
[Serializable]
public class SceneData : NamedData
{
public List<GameObjectData> Roots;
public SceneData()
{
Roots = new List<GameObjectData>();
}
}
[Serializable]
public class GameObjectData : NamedData
{
public string Tag;
public List<GameObjectData> Childs;
public List<ComponentData> Components;
public GameObjectData()
{
Childs = new List<GameObjectData>();
Components = new List<ComponentData>();
}
}
[Serializable]
public class ComponentData
{
public string Type;
public ComponentData()
{
}
public override string ToString()
{
return Type;
}
}
public static SceneData DumpScene(Scene scene)
{
var result = new SceneData() { Name = scene.name };
foreach (var root in scene.GetRootGameObjects())
{
if (root != null)
{
result.Roots.Add(DumpGameObject(root));
}
}
return result;
}
public static GameObjectData DumpGameObject(GameObject root)
{
var result = new GameObjectData { Name = root.name, Tag = root.tag };
foreach (Transform transform in root.transform)
{
if (transform != null && transform.gameObject != null)
{
result.Childs.Add(DumpGameObject(transform.gameObject));
}
}
foreach (var component in root.GetComponents<Component>())
{
if (component != null)
{
result.Components.Add(DumpComponent(component));
}
}
return result;
}
private static ComponentData DumpComponent(Component component)
{
return new ComponentData { Type = component.GetType().FullName };
}
}
}