static void ExportJson(string filename) { SpawnInfo blueSpawn = null, redSpawn = null; foreach (var obj in GameObject.FindGameObjectsWithTag("Spawn")) { SpawnBuilder builder = obj.GetComponent <SpawnBuilder>(); if (builder.blueTeam) { blueSpawn = builder.GetInfo(); } else { redSpawn = builder.GetInfo(); } } CoreInfo blueCore = null, redCore = null; foreach (var obj in GameObject.FindGameObjectsWithTag("Core")) { CoreBuilder builder = obj.GetComponent <CoreBuilder>(); if (builder.blueTeam) { blueCore = builder.GetInfo(); } else { redCore = builder.GetInfo(); } } List <TowerInfo> towers = new List <TowerInfo>(); foreach (var obj in GameObject.FindGameObjectsWithTag("Tower")) { towers.Add(obj.GetComponent <TowerBuilder>().GetInfo()); } List <MonsterInfo> monsters = new List <MonsterInfo>(); foreach (var obj in GameObject.FindGameObjectsWithTag("Monster")) { monsters.Add(obj.GetComponent <MonsterBuilder>().GetInfo()); } List <MinionRelayPointInfo> minionRelayPoints = new List <MinionRelayPointInfo>(); foreach (var obj in GameObject.FindGameObjectsWithTag("MinionRelayPoint")) { minionRelayPoints.Add(obj.GetComponent <MinionRelayPointBuilder>().GetInfo()); } List <EdgeInfo> edges = new List <EdgeInfo>(); foreach (var obj in GameObject.FindGameObjectsWithTag("Edge")) { edges.Add(obj.GetComponent <EdgeBuilder>().GetInfo()); } List <CircleInfo> circles = new List <CircleInfo>(); foreach (var obj in GameObject.FindGameObjectsWithTag("Circle")) { circles.Add(obj.GetComponent <CircleBuilder>().GetInfo()); } List <BushInfo> bushes = new List <BushInfo>(); foreach (var obj in GameObject.FindGameObjectsWithTag("Bush")) { bushes.Add(obj.GetComponent <BushBuilder>().GetInfo()); } MapInfo mapInfo = new MapInfo() { blueSpawn = blueSpawn, redSpawn = redSpawn, blueCore = blueCore, redCore = redCore, towers = towers.ToArray(), monsters = monsters.ToArray(), minionRelayPoints = minionRelayPoints.ToArray(), edges = edges.ToArray(), circles = circles.ToArray(), bushes = bushes.ToArray() }; string json = JsonConvert.SerializeObject(mapInfo); StreamWriter sw = new StreamWriter(filename + ".json", false); sw.WriteLine(json); sw.Flush(); sw.Close(); }