Search Unity

Google Play Services API vs Unity's Social class

Discussion in 'Scripting' started by gk104, May 21, 2017.

  1. gk104

    gk104

    Joined:
    Apr 25, 2014
    Posts:
    57
    Currently im working on a 2D game project that should work with Google Play Services and i'm kinda confused..
    what is difference between using the Social class of Unity or GooglePlayGames namespace? just for basic functions(Login into Google, sign out etc...)

    Code (CSharp):
    1.  
    2. (1)
    3. PlayGamesPlatform.Instance.GetUserId();
    4. Social.localUser.userName;
    5.  
    6. (2)
    7. if (Social.localUser.authenticated) { }
    8. if (PlayGamesPlatform.Instance.IsAuthenticated()) { }
    I guess that both functions do the same thing?
     
    Last edited: May 21, 2017
    IgorAherne likes this.
  2. RakshithAnand

    RakshithAnand

    Joined:
    Jun 30, 2013
    Posts:
    56
    I need to know the answer for this too.
     
  3. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,532
    From the documentation:
    https://docs.unity3d.com/Manual/net-SocialAPI.html
    Since it's a unified interface, it means as long as you use this interface... no matter the ISocialPlatform you set to Social.Active property, you can access it the same way:
    https://docs.unity3d.com/ScriptReference/Social.Active.html

    This means technically speaking you should be able to implement your own interfaces with varying social platforms just by implementing the ISocialPlatform interface:
    https://docs.unity3d.com/ScriptReference/SocialPlatforms.ISocialPlatform.html

    How this differs from using the GooglePlayServices API is that:
    1) you don't have to integrate the api, instead unity has it baked in (if you're on the appropriate platform that is)
    2) the interface is generalized, so that way you don't have to right completely different code for each and every social platform... but instead just write code against the generalized Social API which is made possible by ISocialPlatform
    3) the interface is generalize, meaning that specialized stuff specific to a given platform is not accessible... you can only to the basics, since the interface is general

    If all you need is simple trophies, authentication, etc.... then use the Social API. It works, and if you compile for both Android and iOS, they'll both just work.... no need for 2 separate API includes.

    If you need specialized access to the social platform api's, because you want to use a specific GameCenter or Google Play Services features, that is not part of the generalized Unity Social API... then import the necessary API and use it.
     
    greatastrocow and RakshithAnand like this.