Content.Load XML with nested types with XNA

Npbluniygh

New Member
I want store some game's data into differents XML files. It's easy to set up this example : http://msdn.microsoft.com/en-us/library/ff604979(v=xnagamestudio.40).aspxit's not so hard because it use only one object's type, but I need to do the same thing with nested and custom classes, so i do that way :Tthere are the two classes : \[code\]namespace GameData{ public enum difficulty { easy, normal, medium, hard } [Serializable] class Level { public bool hardcoreMode; public difficulty difficultyMode; public List<Vague> listVague = new List<Vague>(); public Level(List<Vague> listVague, difficulty difficultyMode, bool hardcoreMode) { this.difficultyMode = difficultyMode; this.hardcoreMode = hardcoreMode; this.listVague = listVague; } public Level() { this.hardcoreMode = false; this.difficultyMode = 0; } }}using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace GameData{ class Vague { public int id; public Vague(byte id) { this.id = id; } }}\[/code\]And the XML :\[code\]<?xml version="1.0" encoding="utf-8" ?><XnaContent xmlns:Generic="GameData"> <Asset Type="GameData.Level"> <hardcoreMode>true</hardcoreMode> <difficultyMode>2</difficultyMode> <listVague> <item> <id>3</id> </item> </listVague> </Asset></XnaContent>\[/code\]
 
Back
Top