我目前正在使用XNA(学校项目)开发游戏,想知道是否有一种方法可以在运行时列出所有资源,因为我的资源文件名是###-Name##,我想按照前三位数字进行索引。
这样的东西会有帮助吗?
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;
}