c# – XNA:获取一个数组/资源列表?
发布时间:2020-12-15 08:30:01 所属栏目:百科 来源:网络整理
导读:我目前正在开发一个使用XNA(学校项目)的游戏,我想知道是否有办法在运行时列出所有资源,因为我的资源文件名为### – Name ##并且我想在第一个上对它们编制索引3位数字. 解决方法 这样的事情有帮助吗? public static DictionaryString,T LoadContentT(this Co
我目前正在开发一个使用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; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |