How do I make a text file read 'in' Unity

This is what I currently am doing, what I want to do is have the file be part of the package and read it from the package instead. Later I want to read it from an external source that is streamed to it, but for now, I need it read statically in the package.

 using (StreamReader sr = new StreamReader("assets/dungeons/static/basic1/map0.txt")) 
	            {
	                string line;
	                while ((line = sr.ReadLine()) != null) 
	                {
						buildList.Add(line);
	                }
	            }

Hi
Here’s what I’m using.

string pname = System.IO.Path.Combine(Application.dataPath,fileName);

StreamReader sr = new StreamReader(pname, Encoding.UTF8);
string text = sr.ReadToEnd();
sr.Close();

If you need a string array you can use:

text= text.Replace("\r\n", "\n");
string[] a = text.Split(new char[] { '\n' });

Thanks for this, will help with physical files.

Edit:
Well same problem as I have, this works in edit mode but after a build is done, it never finds the files.
shrugs

Are you copying those files into your built game?

You can do this manually, or use this method:

http://unity3d.com/Documentation/Manual/Build%20Player%20Pipeline.html

d.

You can log the file path to see where it try to open it.
Debug.Log(pname);

… and… to see the path in a build you could assign it to a guitext.

Other than having the text files in a sub folder under the assets folder, I assumed everything from there would be built into my package.
Looking over that linked script area now.

It all works in the editor, its just after the build that it doesn’t find the file.

It should be added to the wish-list.
I copy manually data files after each build.

That’s really not what one wants: people keep all kinds of files and backups and whatnot in the assets folder. If all those went into the game builds, those could get enormous. Instead, Unity tracks which files are used in your scenes, and ignores everything else.

The page I linked in the earlier post explains how you can customize your build process, which includes being able to copy files into the built game.

d.

The page just suggested using the script file, but doesn’t give any example of how to include a folder or a list of files in the package also.

So what would the script look like if I had a folder under my assets folder that I wanted to include with all of its contents?

This way when the player loads and I look for the file based on the System.IO that I posted, will it find it in the package? Unfortunately its not to clear to me how that thing works or is supposed to work.

It would be better to select files to be included like you select levels in the “build list” form.

HI,
me too facing the same issue (working in editor not in build), please send me the solution for this.

Thanks in advance
BEN

Ben, you just resurrected a topic that was 5 years old. I seriously doubt they’re going to even have the files to send you any more.