public static SceneData SceneDataFromSource(Scene source, Hammurabi serializer) { SceneData data = new SceneData(); GameObject[] sourceGameObjects = source.GetRootGameObjects(); data.gameObjects = new GameObjectData[sourceGameObjects.Length]; for (int i = 0; i < sourceGameObjects.Length; i++) { GameObject sourceGameObject = sourceGameObjects[i]; data.gameObjects[i] = GameObjectData.GameObjectDataFromSource(sourceGameObject, serializer); } return(data); }
public void SaveCurrentScene() { Scene scene = SceneManager.GetActiveScene(); SceneData data = SceneData.SceneDataFromSource(scene, this); string jsonData = data.ToJson(); string path = Application.dataPath; path += "/../output/"; Directory.CreateDirectory(path); path += "test.scene.json"; if (File.Exists(path)) { File.Delete(path); } StreamWriter writer = new StreamWriter(path); writer.Write(jsonData); writer.Close(); }