Game Level data. Resource Text file, or other

Hi all.

New, very very new to Unity. Just starting my first game. I’m porting from a tutorial i worked through on Swift development, before I saw the light and launched into Unity. In the Swift tutorial they were using JSON files to hold the info for each level.

I’ve been searching here about JSON and XML and it just seems like there’s a lot of effort to support either one in a multi-platform mobile game.

So, my question, if I’m using files to hold my game data, and that data will eventually just be serialized into the game object model, why not just bake the data directly into the game? It would save the memory space for another add on, and would be much more performant than loading levels from any kind of files. Right?

You can put them in StreamingAssets and access them directly ingame (readonly)

Thanks Aaro. The documentation seems to indicate that you can’t do that on android. A couple of forums posts say the same thing.

The amount of data isn’t really all that big. it’s level name, description, target score, allowed number of moves, and 3 2 dimensional arrays of [8,8], or potentially one [8,8,3].

The json files in the tutorial had the data laid out in a “grid” making it easy to visualize. Wouldn’t be difficult to do the same with string constants and some well places line breaks. Then parse and load the appropriate string into my object model.

Why not just have a class GameData. It loads the data (hard-coded) into the data structure(s). Then add a method GetLevelData that fetches the data for the specified level. This way it is just code right inside your app. Unless you want to provide future updates to that data or let the user modify it.

Ben,

My thoughts exactly.

@SKMoss , it is possible on Android however only using the WWW class.

Hi Aaro,

I don’t doubt the documentation is misleading. The second paragraph indicates:

“Note that on some platforms it is not possible to directly access the StreamingAssets folder because there is no file system access in the web platforms, and because it is compressed into the .apk file on Android. On those platforms, a url will be returned, which can be used using the WWW class.”

This would lead me to believe that while I could service Android with a Web Service (JSON Call???) the use of StreamingAssets in Android would not be a workable option. Due to the nature of the target audience, the game needs to be available for play, when no internet is available. Unfortunately I don’t have an Android device to test with yet.

WWW doesn’t imply that the assets must be online, you can still read locally. The StreamingAssets will be put inside a jar file in the apk for android, the www class is needed because need first to access the jar file, but you can do it locally without internet connection.