Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Unity Social API

Discussion in 'Scripting' started by pokobros, Mar 30, 2014.

  1. pokobros

    pokobros

    Joined:
    Jan 30, 2014
    Posts:
    119
    I want to integrate into my game some sort of leaderboard. I want it to be compatible with all platforms. I have researched and found that the Social API provided by Unity is a good choice, but there is not that much documentation on it and there are no tutorials on it. http://docs.unity3d.com/Documentation/ScriptReference/Social.html Has anybody worked with it? Does anyone know of any tutorials out there about it? Thanks.
     
  2. pokobros

    pokobros

    Joined:
    Jan 30, 2014
    Posts:
    119
  3. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    I use it all the time, works great. Make a call to Social.localUser.Authenticate() initially, then call Social.ReportScore() whenever you want to submit a score.

    It's really that simple, what part specifically was confusing you?
     
  4. pokobros

    pokobros

    Joined:
    Jan 30, 2014
    Posts:
    119
    Does Social API = Game Center?
     
  5. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    No, Unity Social's API is a wrapper around... something. On iOS, the "something" is GameCenter.

    Its goal is to provide you an unified interface toward all the GameCenter, GooglePlay, etc. that each have their own API.
     
    shadoath and Harinezumi like this.
  6. pokobros

    pokobros

    Joined:
    Jan 30, 2014
    Posts:
    119
    Thank you for the replies... I wanted to display the leaderboard in my game somewhere. Is there a tutorial on how to implement that? I know there is ShowLeaderboardUI but just calling that method can't be all.
     
  7. pokobros

    pokobros

    Joined:
    Jan 30, 2014
    Posts:
    119
    Are there any tutorials or code snippets I can learn from to implement into my game?
     
  8. DalerHakimov

    DalerHakimov

    Joined:
    Mar 14, 2014
    Posts:
    302
    It's not a Unity Social API, as I'm not aware of it. But I can recommend you a Google Play Service lib. Here is a link on how to start:
    1. https://developers.google.com/games/services/console/enabling

    and here is a link for direct github project:
    https://github.com/playgameservices/play-games-plugin-for-unity or https://developers.google.com/games/services/integration/ (for other engines).

    It will give you
    sign in
    unlock/reveal/increment achievement
    post score to leaderboard
    cloud save read/write
    show built-in achievement/leaderboards UI
    turn-based multiplayer (new)
    real-time multiplayer (new)


    For both iOS and Android... and by the way the Plugin is managed by Google itself, so it's pretty good.
     
  9. psykojello2

    psykojello2

    Joined:
    Jul 19, 2013
    Posts:
    37
    _Daniel_, I was hoping you could share some more information about the Social API since you said you're familiar with it. Like the OP, I've been hunting around for examples but have found none.

    More than examples, I'd like a good explanation of how this is supposed to work.

    I have a Unity project currently. I haven't published it to any of the stores. I intend to publish it to Apple, Android and Windows stores eventually.

    On start, I try to authenticate current user. That is successful (in Unity). I create a leaderboard and load scores. Unity gives me some default 4 scores.

    When my game is finished, I post my score using Social.ReportScore() . I get a success here.

    Should I expect to see my saved score when I run my game again? I don't. I'm guessing that's because this is running in Unity and I'm seeing Unity's default "social manager". When I connect to the app stores, will this just magically work?

    When I try to call Social.ShowLeaderboardUI(), I get a not implemented error.
    Is this something that will also magically work when I connect it to the app stores? Or is this something I need to implement on my end?

    This all seems very powerful, but to a newbie like me, it's hard to understand what is expected.
     
    Zaborius likes this.
  10. ben-rasooli

    ben-rasooli

    Joined:
    May 1, 2014
    Posts:
    40
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class SocialAPI : MonoBehaviour
    4. {
    5.     void Start ()
    6.     {
    7.         if (!Social.localUser.authenticated)
    8.             Social.localUser.Authenticate (success => {
    9.                 //do something on success if you like
    10.             });
    11.     }
    12.  
    13.     public void ShowLeaderboard ()
    14.     {
    15.         if (Social.localUser.authenticated)
    16.             Social.ShowLeaderboardUI ();
    17.     }
    18.  
    19.     public void ReportScoreToLeaderboard ()
    20.     {
    21.         if (Social.localUser.authenticated) {
    22.             Social.ReportScore ("integer data to be sent", leaderboardID, success => {
    23.                 if (success)
    24.                     Social.ShowLeaderboardUI ();
    25.             });
    26.         }
    27.     }
    28. }

    I tested this code on iOS. You need to set your leaderboards in iTuneConnect first. Then attach this script to a gameobject in your scene and then call those two public methods whenever you need to show or report to leaderboard.
     
    luma2057 likes this.