我目前正在使用 XNA (学校项目)开发游戏,我想知道是否有一种方法可以在运行时列出所有资源,因为我的资源文件名为 ###-Name## 并且我想在第一个时对它们进行索引3 位数字。
这样的事情会有帮助吗?
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;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)