- Home /
Level builder for iphone
Hi, Im working on a 2D game for iphone and i want to build a LevelBuilder, which will let level designer to work either from PC or MAC and generate Levels.
Is there a way in unity to save/read custom data structure to/from a file? All my objects have a Name, Transform and some have also Speed which controled by level designer.
I want to let the level designer to control this parameters and when he/she done with the level design, all data will be save. from this point,i want the iphone application to be able to read the data ( in data structure format ),and make the level.
Please Help.
Just export the scene in a unity package when he's done.
Answer by pyro · Jul 18, 2010 at 09:42 PM
I had just finished creating a 2D level editor for a game I'm working on and here's how I handled saving out the level so I thought I'd share: Prefabs.
Basically the idea was that in my main game engine, when it loads a level it is passed a prefab object that contains all the necessary info for that level to load (tile positions, enemy positions, item positions) and the level is built from there.
So in the level editor scene, when the level is done being built, you would then "Export" the level by creating a script that builds a new game object and saving all the level information exactly how your game engine would interpret it, then taking that object and saving it as a prefab, all within Unity, while the editor is running. (I just manually dragged the new level object into an empty prefab, but I imagine you could automate that with an editor script)
Then I go back to the main game engine scene, and then set it up to reference this newly created prefab to whatever level it is supposed to be, and that would be it. No File I/O code and all done within Unity pretty painlessly.
Answer by qJake · Jul 18, 2010 at 06:14 PM
Utilizing Unity packages in this instance would be dangerous, because (theoretically) anyone could slip some code in that would get run, and that's a security risk. Not to mention everyone would need to use Unity to create the levels, and there's no way to really regulate that.
The only way to do this would be to custom-design the level editor yourself (you don't even have to use Unity), and then create a custom file-format that you can somehow "send" to the iPhone (I'm not familiar with the iPhone API, so I don't know how you'd accomplish that). Then, in Unity, you would have to read the custom file format off the phone after it had been downloaded (I'm not even sure you can read files off the phone), and create the level manually based on what the file provided, basically "constructing" the level by hand, based on the data in the file.
It's a long and complex process, but there really isn't an easier way. You just need to custom-code everything yourself. And don't write this off as being easy, on the contrary, this requires quite a bit of programming knowledge.
Answer by Eric5h5 · Jul 18, 2010 at 06:28 PM
Use something from System.IO, for example ReadAllText. Then you can parse the data as necessary.
I wasn't sure if you could read off the iPhone filesystem with that... there are a lot of grey areas regarding various .NET classes and whether or not they work on the iPhone... not to mention Unity can't release the iPhone documentation because Apple are a bunch of jackasses, which doesn't help people like me that want to help, but can't, because there's no docs. :P
@SpikeX: in the current version of Unity iPhone (1.7), you can select between .NET 1.1 and 2.0 compatibility. (ReadAllText would need 2.0 I think.) You can only access a specific area per app; for example you can't read/write another app's files.
Your answer
Follow this Question
Related Questions
Defining parameters for a level 1 Answer
How to save data on iOS? 1 Answer
Image-based Level Generator having problems 0 Answers
3D level generator on a grid C# 1 Answer