- Home /
How can I get the data from text files located inside my assets?
Here's my situation.
I would like to have text files located inside my assets. These are basically Notepad-editable "map" files.
How can I reference them so that I can take the data from the files and copy them elsewhere onto the user's system?
The end result I'm after is that the game has the capability of reading map files from a Maps folder located on the user's system. I want in-built maps to be "copied" to that folder on start up (to keep them intact/up to date) while still allowing people to put their own custom maps inside the same folder.
So in other words, I can't figure out how to make reference to my internal .txt files and retrieve the string data from them. All the rest I know how to do. All I can seem to find about this are editor-related scripts, and I don't think those are what I need.
search for saving at runtime. There isn't really a standard way. I THIN$$anonymous$$ it has to do with the security and with there not being a standard safe directory you could always be sure you could access and save to across operating systems.
search for saving at runtime nad check out
http://www.$$anonymous$$dthecube.com/blog/2009/11/reading-text-data-into-a-unity-game
Answer by yoyo · Dec 11, 2012 at 06:35 AM
If you store your files with a .txt extension then Unity will treat each file as a TextAsset, and you can uses Resources.Load to load them and textAsset.text to access them.
Alternatively, since you are creating a standalone build (I presume?) you can use standard System.IO.File calls for file manipulation, and you can find your data relative to Application.dataPath.
Thanks, I appreciate it. Resources.Load was all that I needed to know.
Glad to help. @sparkzbarca's link above looks pretty useful too.
Your answer
Follow this Question
Related Questions
Is it possible to reference a custom file type in the inspector? 1 Answer
Is there a way to extract assets from Unity MMO files? 1 Answer
Build settings: how to export files into the build 1 Answer
Create / preserve file in asset folder. 2 Answers
Are all ScriptableObject assets included in the build? 4 Answers