Loading directories and custom files

Hi,

I have an issue when building my game for Windows/Android (and all other platforms i would assume) but it works fine in the editor.

All i want is to read all directories (world1, world2, etc) that are in a specific folder (levels), and then, read all my custom files (lvl1.lvl, lvl2.lvl, etc, they are text files) that are in these directories.

Here is a code sample i wrote to find my “worlds” :

string LEVEL_PATH = Application.dataPath + Path.AltDirectorySeparatorChar + "Resources" + Path.AltDirectorySeparatorChar + "Levels";

foreach (string worldDir in Directory.GetDirectories(LEVEL_PATH)) {
            World world = new World(worldDir);
            world.LoadLevels();            
            worlds.Add(world);
        }

It does work fine in the Editor. But when i build and run the game, it doesn’t because my “levels” folder is not present in the projectname_Data/Resources of my build. Therefore, i get an exception on run telling me it can’t find the Directory.

So my question is, how can i tell Unity to export those files in the build package ?

If your files are inside the Resources folder, then they will be added into Resources on build. You can then load them using the Resources.Load() API, see: