XNA:获取资源数组/列表? [英] XNA: Get an array/list of resources?
本文介绍了XNA:获取资源数组/列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在使用 XNA(学校项目)开发游戏,我想知道是否有办法在运行时列出所有资源,因为我的资源文件名为 ###-Name##,我想对它们进行索引在第一个 3 位数字上.
I am currently developing a game using XNA (School project), and I was wondering if there's a way to list all the resources during runtime because my resource files are named ###-Name## and I want to index them on the first 3-digit number.
推荐答案
这样的事情会有帮助吗?
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;
}
这篇关于XNA:获取资源数组/列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文