- Home /
Mobile Game with Login user using firebase SDK?
I want to make a mobile game(firebase implemented) where the user logins, and the game save score and some other things + adding leaderboards,acheivements.
1. I used the google play service to test the leaderboards and achievement,but do firebase do this all?or i have to implement the google play services with it?
2. concerning the login user and saved scores/some other stuff whats the best way to achieve this since the game is also on iOS? like the user should add/create an email and that is saved to the cloud with authentication this work on both iOS and android since i didn't use the google mail account .is this better?or the logins with his Facebook account?
Answer by OneCept-Games · Apr 05, 2018 at 07:04 AM
With Firebase Authentication and -Database (Realtime the only one currently supported for Unity), you can use both Email/Pasword- Facebook (an other SOME's) as well as Anonymously and your own custom authentication method, and then you can use the Database to store your highscore by UserID. I normally create shared paths in the database in the root, like: /DATABASE_URL/highscore/$uid/. And if I want to store user private data i use the path /DATABASE_URL/users/$uid/score/.
public void SyncToServer(string tableName, object items, bool sharedData=false) { if (FirebaseAuth.DefaultInstance.CurrentUser == null) { Debug.LogError("SyncWithFirebase: User is not authorized/logged in. Data will not be syncronized with server!"); return; } // Set the database root reference DatabaseReference rootRef = DataController.Instance.firebaseDatabaseRef; if (rootRef != null) { DatabaseReference usersRef; DatabaseReference uidRef; DatabaseReference tableRef; if (sharedData) tableRef = rootRef.Child(tableName); else { usersRef = rootRef.Child("users"); uidRef = usersRef.Child(FirebaseAuth.DefaultInstance.CurrentUser.UserId); tableRef = uidRef.Child(tableName); } tableRef.SetRawJsonValueAsync(JsonUtility.ToJson(items, true)).ContinueWith(task => { if (task.IsFaulted) Debug.LogError("SyncWithFirebase: " + tableName + " write failed: " + task.Exception); if (task.IsCompleted) Debug.Log("SyncWithFirebase: " + tableName + " write succeeded..."); }); } else Debug.LogError("SyncWithFirebase: Database Reference not set!"); }
tableName in this case would be "highscore" and items object in this case could be a List of a HighScore class you want to save (ie. int LevelName, int Score).