public static LevelData DeserializeLevel() { string path = Path.Combine(Assembly.GetExecutingAssembly().Location, "../../../../Content/LevelData.xml"); ObjectRootData root = DeserializeFromXml <ObjectRootData>(path); LevelData levelData = new LevelData(); foreach (var item in root.lvlData) { GameObject g = (GameObject)Activator.CreateInstance(Type.GetType(item.Type)); g.Initialize(new Vector2(item.X, item.Y)); levelData.GameObjects.Add(g); } return(levelData); }
public static void SerializeLevel(LevelData levelData) { string path = Path.Combine(Assembly.GetExecutingAssembly().Location, "../../../../Content/LevelData.xml"); ObjectRootData root = new ObjectRootData(); foreach (var item in levelData.GameObjects) { root.lvlData.Add(new ObjectData() { Type = item.GetType().FullName, X = (int)item.Position.X, Y = (int)item.Position.Y }); } SerializeToXml(root, path); }