XNA: Get an array/list of resources?

后端 未结 1 1077
南笙
南笙 2021-02-09 11:42

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 #

1条回答
  •  甜味超标
    2021-02-09 12:07

    Would something like this help?

    public static Dictionary LoadContent(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 result = new Dictionary();
    
       //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(contentManager.RootDirectory + "/" + contentFolder + "/" + key);
       }   
       //Return the result
       return result;
    }
    

    0 讨论(0)
提交回复
热议问题