0

I am trying to save the game data online as other many games do.
I would like the user to sign on through any source like facebook, google or any other, and then user's games progress should be stored online, and when user reset the game or by mistake he lost the device data he should be able to access the data stored online to retrieve the information of his progress like coins, gems and unlocked levels etc.

I have tried the google play games services for that, there I found leaderboard and achievements but I didn't found a way to save my user's game stats.

I don't have currently a solution.

I expect to store the data online and my game users should be able to sync the data online.

Jack Mariani
  • 2,270
  • 1
  • 15
  • 30
Ali Ahmad
  • 25
  • 2
  • 4
  • 2
    Not sure I understand the question here, surely you're not allowing the local client to manipulate these values anyway? Your server backend should handle these details, manipulation and storage, your client should only be able to get a copy of the current values, but all operations (like buying gems/coins, spending them, etc.) should be handled by your server. – Lasse V. Karlsen May 20 '19 at 09:21
  • Hi.. thanks for quick reply. But i am actually wondering for a solution in detail. Can you please post a link to follow the steps for server implementations in unity? – Ali Ahmad May 20 '19 at 09:23
  • Unfortunately that is going to be a very broad question. You need to look into server and backend development, databases (of any sort) for storing data there, designing APIs for this kinda thing. – Lasse V. Karlsen May 20 '19 at 09:38

1 Answers1

1

If you're working in Unity and targeting Android and iOS, you can also look into Firebase. You can store the user stats in Real-Time Database, which has pretty nice integration with Unity.

I don't have a good sample for storing consumables and progress, but there is an open-source leaderboard sample that will get you started with the basics and give you a good idea of what the shape of the code will look like without committing (most of the database related code is in this source file).

I'd suggest a structure that looks something like:

user_list:

  • {user_id0}
    • coins
    • gems
    • levels
  • {user_id1}
    • coins
    • gems
    • levels

You can keep it safe with with a rules.json file that says something like:

{
  "rules": {
    "Users": {
      "$uid": {
        ".read": "auth != null && $uid == auth.uid",
        ".write": "auth != null && $uid == auth.uid"
      }
    }
  }
}

You will have to use Firebase Authentication to really take advantage of the rules logic, but it should support most auth providers you want (including your existing work on Google Play Games as well as iOS's Game Center). You can tie into your existing work with Google Play Games sign on or use one of a bunch of different auth providers.

For my own flow, I like to tie consumable updates (coins and gems probably in your case) directly into update listeners to just let RTDB's caching system run on its own using ValueChanged listeners. Updating the database is best done with the RunTransaction call, which will help you deal with corner cases whilst offline or if the user is switching between devices.

Patrick Martin
  • 2,993
  • 1
  • 13
  • 11