XNA: get array / list of resources?

I am currently developing a game using XNA (school project), and I was wondering if there is a way to list all the resources at runtime because my resource files are called ### - Name ## and I want to index them on the first 3 digit number.

+6
c # xna
source share
1 answer

Would something like this help?

public static Dictionary<String, T> LoadContent<T>(this ContentManager contentManager, string contentFolder) { //Load directory info, abort if none DirectoryInfo dir = new DirectoryInfo(contentManager.RootDirectory + "\\" + contentFolder); if (!dir.Exists) throw new DirectoryNotFoundException(); //Init the resulting list Dictionary<String, T> result = new Dictionary<String, T>(); //Load all files that matches the file filter FileInfo[] files = dir.GetFiles("*.*"); foreach (FileInfo file in files) { string key = Path.GetFileNameWithoutExtension(file.Name); result[key] = contentManager.Load<T>(contentManager.RootDirectory + "/" + contentFolder + "/" + key); } //Return the result return result; } 
+12
source share

All Articles