<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Amila Senadheera on Medium]]></title>
        <description><![CDATA[Stories by Amila Senadheera on Medium]]></description>
        <link>https://medium.com/@amila.15?source=rss-73a107c58bbe------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*N7VruJwuQS8rS2hr607N4A.png</url>
            <title>Stories by Amila Senadheera on Medium</title>
            <link>https://medium.com/@amila.15?source=rss-73a107c58bbe------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 09:55:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@amila.15/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to develop a complete Leader board for a Unity game using Firebase, Facebook Sign In, Google…]]></title>
            <link>https://medium.com/teamarimac/how-to-develop-a-complete-leader-board-for-a-unity-game-using-firebase-facebook-sign-in-google-d865f577b303?source=rss-73a107c58bbe------2</link>
            <guid isPermaLink="false">https://medium.com/p/d865f577b303</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[google-plus]]></category>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[facebook-sdk]]></category>
            <category><![CDATA[firebase]]></category>
            <dc:creator><![CDATA[Amila Senadheera]]></dc:creator>
            <pubDate>Mon, 03 Dec 2018 05:01:00 GMT</pubDate>
            <atom:updated>2018-12-06T10:08:40.684Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>How to create a complete Leader board for a Unity mobile game using Firebase, Facebook Sign In, Google plus SDKs</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*lU-KZMp3b14KFruM.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xZJpaj3BE-gHcSi7aCRk-w.png" /><figcaption>Animation — Supah from Dribbble</figcaption></figure><p>If you are struggling to handle player stats of your Unity game with Firebase and show your leader board connecting players with Facebook and Google plus Sign in, this is the right place for you. These are main steps you should follow with me.</p><ol><li>Import Firebase SDK into Unity and configure it using Google’s Firebase console.</li><li>Integrate Facebook SDK and configure with Facebook login app in Facebook developers account.</li><li>Setup Google plus SDK in Unity and configure it for Android and IOS builds using google developer console.</li></ol><p><strong>Step 1 : Importing Firebase SDK</strong></p><p>Go to <a href="https://firebase.google.com/docs/unity/setup?gclid=CjwKCAiAlvnfBRA1EiwAVOEgfKFmz8P9hmlY_Zf-OiZfZnB2BUidjxdgmfjZ20LEYooUXwaZM98msBoCwXcQAvD_BwE">Firebase Unity section</a> at firebase.google.com. Download the SDK. It is a comprehensive package and 594 MB in size. But we will only use Firebase Realtime database and Firebase Authentication packages. Extract the package. Go to Assets =&gt; import package =&gt; custom package and choose FirebaseDatabase.unitypackage from where you extracted the SDK. Just click import to get everything including non-coding assets. Wait till the spinning circle right bottom corner of the Unity Editor.</p><p>Create a new project in google.firebase.com. You will be asked to choose Android, IOS or Web. Since this is a mobile app. You have to select either Android or IOS. If you need to build your game for these two mobile platforms, then you have to configure two times using two separate apps. Give the bundle ID and app name. Notice that bundle ID is the same ID given in Unity publishing settings. For IOS you will be asked to download GoogleService-Info.plist and for Android you will be asked to download google-services.json. Put these files inside the root Assets folder of the project. Now you can build the project for both Android and IOS using Firebase.</p><p>Since this is for player stats and leaderboard handling I will be creating a C# file called LeaderboardHandler.cs under the Scripts folder as you all do. Now Firebase is ready to go. So we can define the namespaces of Firebase and configure it inside the Start method of MonoBehaviour Script file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/29bf73ed2686853e90c0c61183ff9a2d/href">https://medium.com/media/29bf73ed2686853e90c0c61183ff9a2d/href</a></iframe><p>Firebase give everything that you want as examples in their Git Repository. See <a href="https://github.com/firebase/quickstart-unity">quick-start-unity</a>. It has a quick start project for each unity package of the SDK. I will edit the sample script for player authentication. There is a file called UIHandler.cs in that repo in;</p><p>quickstart-unity/auth/testapp/Assets/Firebase/Sample/Auth/UIHandler.cs</p><p>Make a copy of this file and edit as I do. I renamed this file as PlayerRegisterHandler.cs. Actually players don’t need to login each time they play the game, we only need to save their name, email at first time they play the game.You need a UI to get email, name so create a Canvas to get name, email, and password fields password may be used to recover the player account when needed.Get access to following three serialize fields on top of LoginHandler.cs file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/871d3fd88693258316c19cb03b50d5a3/href">https://medium.com/media/871d3fd88693258316c19cb03b50d5a3/href</a></iframe><p>Do the same configuration as we did in <em>LeaderboardHandler.cs</em> file as;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d54fb81467fe567f93474825bcd69ab5/href">https://medium.com/media/d54fb81467fe567f93474825bcd69ab5/href</a></iframe><p>All the other configurations will be done automatically by invoking <em>InitializeFirebase </em>method in Start method. Don’t worry about all the code included in that code. We just need to get what we need.</p><p>Firebase Authentication handle only authentication. Any other player stats should be saved in Firebase Database. At the Create Account button pressed, we can register the user with Firebase Authentication with email and password. Successful registration gives a Unique User ID we can save any other player related data along with this ID. See how I achieve it inside the <em>CreateUserWithEmailAsync </em>method.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d51db4885e3b287a525c818f85a63b72/href">https://medium.com/media/d51db4885e3b287a525c818f85a63b72/href</a></iframe><p>Now we have the player registration using email and username. For a good looking Learderboard it is better to show a player profile pic also. This is where you need Facebook and Google+ SDKs.</p><p><strong>Step 2: Setting up Facebook SDK</strong></p><p>Visit <a href="https://developers.facebook.com/">facebook developers web site</a> and create a Facebook developer account if you don’t have a one yet. Create a new Facebook app for your game.</p><p>Add IOS and Android Platforms. Then add a Facebook Login Product. Give the game bundle ID under the IOS setup.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*YHX41hxzoRAeLWOvbRHitg.png" /><figcaption>ios configuration in our facebook app</figcaption></figure><p>Let’s setup thing in the Editor. You need to download the <a href="https://developers.facebook.com/docs/unity/">Facebook Unity SDK </a>. Then import it into unity as we did for Firebase SDK. Once the import is over, go to Facebook =&gt; Edit Settings. See the inspector, you may not see what I see below click Regenerate Android Manifest to generate a Debug Android Key Hash. This hash will be included in Facebook android app under Key Hashes field.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/493/1*0GDw2N_4sGVTRKIVLohFWQ.png" /><figcaption>Facebook settings in Unity editor</figcaption></figure><p>To be honest I had to do some work around to successfully generate this key hash. At first time I got warning in the Inspector. I use them as clues to get rid of them. So there is a challenge for you to get rid of it. After that put the hash in Facebook App as below. You have to add the generated class name and the bundle ID also.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*WZGUVTRNdmdwfwogEs9bUA.png" /><figcaption>Android configuration in our facebook app</figcaption></figure><p>So now everything is ready to use. Let’s get back to <em>LeaderboardHandler.cs</em> file. Add the facebook namespace as,</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e975b3425127f2826289cc811f83ad0a/href">https://medium.com/media/e975b3425127f2826289cc811f83ad0a/href</a></iframe><p>and setup configuration inside the Start method as in the below code block,</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/071988cef0ddc7c04a8886ae303caa5a/href">https://medium.com/media/071988cef0ddc7c04a8886ae303caa5a/href</a></iframe><p>InitCallback method will called as callback functions after a successful initialization. Customize this method as your needs.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/82354882b1a59b6de4b3ca488cdf1bb1/href">https://medium.com/media/82354882b1a59b6de4b3ca488cdf1bb1/href</a></iframe><p>So this the my way of showing the leader board, when the player hit the leader board button he/she is asked to continue with Facebook or Google+. Then we get the email, name, profile pic of players after allowing in consent screen. Then name and photo URL will be updated along with the score/stage or whatever the player stat in Firebase Database. Under this section I will explain how to do that with Facebook. Add below functions to <em>LeaderboardHandler.cs</em>. When invoking the <em>ContinueWithFacebook</em> method, it will show up the consent screen to get access from the player. You can check this method by attaching it to the supposed button. Unity Editor version is supplied for developers by Facebook SDK. But for the Google Sign In you have to build and test it on a physical mobile device.</p><p>In this method we specify what information we retrieve from Facebook account of the player. I create a separate method called <em>GetUserDetails </em>to get the email and facebook profile pic URL.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/214bd7a55decc8a8d91b885e76bcf9e9/href">https://medium.com/media/214bd7a55decc8a8d91b885e76bcf9e9/href</a></iframe><p>Note the <em>ContinueWithUserDetails </em>method, this is common for both Facebook and Google+ account after the interaction to get email, name, and profile URL. This method save these details in the corresponding account ID in Firebase Database. Saving USERID PlayerPref in the login method was for this purpose. So go ahead and add this method to our <em>LeaderboardHandler.cs</em> file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/75aa4890028f9057ec4caa4decc5fbe9/href">https://medium.com/media/75aa4890028f9057ec4caa4decc5fbe9/href</a></iframe><p>Here I should mention about ANONY players, I gave an option to skip the create account window. Therefore, when an ANONY player choose Facebook to see the leaderboard, I save email and name too. For others I use profile pic only. It is up to you to decide as your requirement. I will explain the <em>LoadLeaderboard </em>method in a next step. Lets move to Google+ setup inside Unity.</p><p><strong>Step 3: Setup Google+ SDK</strong></p><p><a href="https://github.com/googlesamples/google-signin-unity">Google-sign-in-unity</a> explains thoroughly how to do Google+ sign in with a example consent screen. First you need to download and import <a href="https://github.com/googlesamples/google-signin-unity/releases">GoogleSignIn-1.0.0.unitypackage</a>. Visit <a href="https://console.developers.google.com/">google-developers-console</a> and create a project for our game. Then enable the Google+ API. Then we need to create credentials for our app. It will asked for from where the API will be called, select Android. Here you need to profile app fingerprint and bundle id. Google checks these when the API is called for the security purposes. In the below screen fill these two fields.</p><p>Use below command to get the <em>SHA-1</em> hash of the app from the generated KeyStore file at the signing.</p><p><em>keytool -exportcert -keystore path-to-debug-or-production-keystore -list -v</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/511/1*g77n-H35aRJArXWvAmDYiw.png" /><figcaption>credential creation for Android client</figcaption></figure><p>After this screen you will get a Android OAuth 2.0 client ID. Do the same for IOS also. Then you need to use auto generated web client ID for configuration. Let’s move into <em>LeaderboardHandler.cs</em> file. Add below namespaces to communicate with Google+ API.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dfa5e677861a00e8fb6f64ce0df2628d/href">https://medium.com/media/dfa5e677861a00e8fb6f64ce0df2628d/href</a></iframe><p>Add these fields to get the Web client ID and for the further configuration,</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/30082d648280d9bc4a9674e9a341e714/href">https://medium.com/media/30082d648280d9bc4a9674e9a341e714/href</a></iframe><p>Next add below configuration code inside the Start method,</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4b6e6cf2ac14d21e410cbfae658af0b4/href">https://medium.com/media/4b6e6cf2ac14d21e410cbfae658af0b4/href</a></iframe><p>Then copy &amp; paste below functions I edited from the <a href="https://github.com/googlesamples/google-signin-unity">google-sign-in sample code</a> to get the Google+ profile pic and email.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fff9e95651d031622b82ecb9901221fe/href">https://medium.com/media/fff9e95651d031622b82ecb9901221fe/href</a></iframe><p>Here also the same method <em>ContinueWithUserDetails </em>will be called after Google+ API communication to pass data to Firebase Database.</p><p>Now its time to show the leader board with profile avatar, name and player stats. Let dive into <em>LoadLeaderboard </em>method. This method communicate with Firebase and load the current version of the leader board. Yeah it always loads the current version of the leader board when player passes some other player it is instantly show up to whoever is watching the leader board. A real time updating leader board is a nice feature.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/04ecf998052674ed5731511287886bf1/href">https://medium.com/media/04ecf998052674ed5731511287886bf1/href</a></iframe><p>Please read the Firebase docs about retrieve data with event triggers to understand how it actually works. <a href="https://firebase.google.com/docs/database/unity/retrieve-data">Read more</a>.</p><p>I sort the players for ranking in database using <em>OrderByChild </em>function. See how I coded all these things together in the above function. Hint: Use negative sign in front of integer value of the score or stage to use the default ascending ordering to generate a descending ordering.</p><p>I know that I did not mention everything you expect in this article. But I know what I mentioned here is enough to develop a leader board with Facebook and Google+ Sign In. However if you follow me with all the steps + your percentage of work will have get a leader board something look like below,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/240/1*0Yp2jWyCPWxZ2muPr9F0Iw.png" /><figcaption>Finally I got this nice leader board</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/427/1*Hb4zonlmHsvlz4Y0dpgEvg.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d865f577b303" width="1" height="1" alt=""><hr><p><a href="https://medium.com/teamarimac/how-to-develop-a-complete-leader-board-for-a-unity-game-using-firebase-facebook-sign-in-google-d865f577b303">How to develop a complete Leader board for a Unity game using Firebase, Facebook Sign In, Google…</a> was originally published in <a href="https://medium.com/teamarimac">Arimac</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>