gpt4 book ai didi

c# - XNA:获取资源数组/列表?

转载 作者:太空狗 更新时间:2023-10-29 20:03:47 25 4
gpt4 key购买 nike

我目前正在使用 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;
}

关于c# - XNA:获取资源数组/列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4052532/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com