Android Game - with offline database (insert, update, delete)

I’ve been working with android offline game and I’ve been searching to find out how to save multiple player names with high score, level, achievements etc… I’ve been always ended-up with SQLite but there is no complete guide to do it and how to implement it on my project? I have experienced with mySQL but I need to work it as an offline mobile game only.
Please your help… and thank you.

use a text file

json, xml, yaml, ini, custom file, whatever

Why the overkill of MySQL for what is effectively a teeny tiny piece of data. Databases are intended for large amounts of sortable data, how many high scores do you plan on storing on a local device?

2 Likes

about 4-5 users with player names, high score, level, achievements… for adroid

Yeah, why use MySQL for that?

Just stick it in a random json file. Unity has built in json support:

Just create a simple class for each entry, and a token class for the array:

[System.Serializable]
public class HighScores
{
    public HighScoreEntry[] Entries;
}

[System.Serializable]
public class HighScoreEntry
{
    public string Name;
    public int HighScore;
    public int Level;
    public string Achievements; //no idea your format for this
}

Populate as needed and store:

var scores = new HighScores();
//fill scores.Entries;
using (var writer = new System.IO.StreamWriter(System.IO.Path.Combine(Application.persistentDataPath, "savefile.json"))
{
    writer.Write(JsonUtility.ToJson(scores));
}

Read from data as needed:

HighScores scores;
using(var reader = new System.IO.StreamReader(System.IO.Path.Combine(Application.persistentDataPath, "savefile.json"))
{
    scores = JsonUtility.FromJson(reader.ReadToEnd());
}
3 Likes

Thank you very much!.. will try working for this one :smile:

Do you still need to have mamp or xampp to work on mysql even it’s offline?

I will shortly be releasing a free asset called PlayerPrefsPlus (an extension of the Unity PlayerPrefs class) which will do exactly what you want. If you want to PM me I will send you a beta version when it is ready.

If you decide you want to go the local database route check out SQL4Unity [ SQL for Unity Database | Utilities Tools | Unity Asset Store](http:// SQL for Unity Database | Utilities Tools | Unity Asset Store)