我目前正在开发一个使用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; }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。