- Home /
Dynamically load json data to a game: What are the best practices?
Hi Everybody,
I'm working on an a quiz type game which currently includes lots of data from excel files, which I manually transfer to json file, and load to the game.
I found several code packages for excel to json (didn't try them yet):
https://unitylist.com/p/28t/Unity-excel-importer
https://github.com/pedicagames/Excel-To-JSon-C-Unity-
https://forum.unity.com/threads/released-unity-quicksheet.289146/
However, I'd like to implement remote data storage and local data storage, so data can be updated dynamically to the game based on player progress.
Are you familiar with best practice to loading data into database, where this will be dynamically pushed to a game?
Which database / service can suit my needs?
Thanks
Answer by sacredgeometry · Mar 06 at 12:50 PM
Use Newtonsoft.Json it is the industry standard for C#/.NET JSON deserialisation/ serialisation.
Just read the file as a string using any of the normal .NET methods and use the Newtonsoft deserialisation method to map it onto an equivalent c# models i.e. POCOs.
https://www.newtonsoft.com/json/help/html/deserializeobject.htm
I suggest doing it by hand but if you are feeling lazy there are plenty of tools for generating the C# types which might get you most of the way there if there is a lot of data/ type variation. https://quicktype.io/csharp
Regarding the "remote storage", thats what databases are for, front a database with an api that provides an interface for the basic CRUD for the data you are trying to store. If SQL: You could use an ORM like Entity Frameworks or PetaPOCO to make talking to the database a little easier
https://docs.microsoft.com/en-us/ef/
Any SQL variant will do, I favour Postgres personally if I have a choice, otherwise MSSQL or MySQL will do the job fine.
https://www.postgresql.org/ https://www.microsoft.com/en-gb/sql-server/sql-server-2019 https://www.mysql.com/
Other than that you have NoSQL options like Mongo that may be useful. It really depends on your requirements. No real need for an ORM here they are pretty simple to set up CRUD the complexities really start to emerge when you are trying to work with a lot of data and how best to structure it as its a little more open ended than SQL.
The api can be written in what ever language and framework you want but C# .net/ web apis are pretty good and it would save you a lot of effort as you could share the DTOs in a single library across your two projects meaning less maintenance burden.