iOS and Android reading/writing files

Hi!

I’m attending to create a level editor that’ll work both on iOS/Android devices as on desktops. The goal is to save objects types and rotations on one dimensional level, so it should like:

1 object2 60
2 object4 30
3 object6 30
4 object2 90
5 object6 30
6 object3 330
7 object7 270
8 object2 120
9 object21 30
10 object3 0

…where the first variable will be position in meters from the beggining, second one, the object type, and the last one - Y rotation of an object. I need some other variables in those .ini(? or other?) like level lenght in meters, best scores etc.

So, my question is - how to do it? How to save a file like that on android, iOS and desktop - to create levels?

And, the next question is - how to read them to get the right variables?

Thanks!

.NET handles file i/o with the System.IO namespace. You can probably find some forum/web posts that relate specifically to Unity, like this one. You’ll have to deal with a number of issues, depending on which platforms you want to target.

If you need help figuring out which folder you should be accessing, Unity will generally provide a safe location via Application.persistentDataPath.

There are many ways to accomplish these tasks. If you’re just getting started, you’ll probably have a somewhat easier time using helper functions like File.ReadAllLines() and File.WriteAllLines(), so that you can read or write file contents line-by-line with a StringReader or StringWriter.