Saturday, July 4, 2015

rpg - Storing Type/Game Data Within A Unity 3D Game Using An Offline Flatfile Database


I've read several documents on how to manage game type data:


Would it be better to use XML/JSON/Text or a database to store game content?


How to choose how to store data?


Im developing an offline RPG game in Unity3D. I've made online games before, but with online we had an edge for the database. For the online game we used a MySQL database each time the player loaded the game, they would download the database (JSON setup) and we would parse it on the client side and it would be good to go.


However for an offline RPG I don't have the luxury of storing my game type data online. To be clear when I say type data I mean things like: -Monster tables -Item tables -Ability tables etc


What I liked about the MySQL database was that it was tabluar and I could edit rows and columns easily and not need to create hundreds of classes/subclasses to manage the type data.


My question is how can I mimic the MySQL database in Unity3D?



I considered using an excel file but I feel that would be so easy for the user to hack. Just change the excel data and boom, you've hacked the game.


Is there a way I can create an offline (secure-ish) flatfile database that will let me avoid having to create tons of type data class files to manage all my game data?



Answer



Depending on your needs, you could just serialize a Dictionary to a binary file. I can post some code after I get home, but this link explains the serialization features of C#.


This is only secure-ish (a binary file is harder to hack than an excel spreadsheet) but that's all you requested. I can't tell from your question if this is data generated during the game or data you created ahead of time, but if the latter then you could just write an editor within Unity itself.


Alternatively, you could simply not care if the user hacks this data. If this is a single-player game, then let the player do what they want. If this is a multiplayer game, then you need more security anyway.


EDIT: Here's a Unity specific resource about saving a serialized object: http://gamedevelopment.tutsplus.com/tutorials/how-to-save-and-load-your-players-progress-in-unity--cms-20934


This most important Unity-specific thing mentioned there is Application.persistentDataPath


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...