Skip to content

Instantly share code, notes, and snippets.

@jeffquach
Last active October 30, 2016 22:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffquach/b11951ab328f5e52c0d7ed5031d5a494 to your computer and use it in GitHub Desktop.
Save jeffquach/b11951ab328f5e52c0d7ed5031d5a494 to your computer and use it in GitHub Desktop.
Final script for integrating Google Play Games and Game Center into a Unity game
using UnityEngine;
using UnityEngine.SocialPlatforms;
#if UNITY_ANDROID
using GooglePlayGames;
using GooglePlayGames.BasicApi;
#endif
public class SocialFeatures : MonoBehaviour {
void Start () {
// Authenticate and register a ProcessAuthentication callback
// This call needs to be made before we can proceed to other calls in the Social API
#if UNITY_ANDROID
PlayGamesPlatform.Activate();
#endif
Social.localUser.Authenticate (ProcessAuthentication);
}
// This function gets called when Authenticate completes
// Note that if the operation is successful, Social.localUser will contain data from the server.
void ProcessAuthentication (bool success) {
if (success) DontDestroyOnLoad(gameObject);
}
public static void ShowLeaderboard(){
if(Social.localUser.authenticated) Social.ShowLeaderboardUI();
}
public static void ShowAchievements(){
if(Social.localUser.authenticated) Social.ShowAchievementsUI();
}
public static void ReportLeaderboard(long score, string leaderboard){
if(Social.localUser.authenticated) Social.ReportScore (score, leaderboard, success => {});
}
public static void ReportAchievement(string achievementID, double progress){
if(Social.localUser.authenticated) Social.ReportProgress(achievementID, progress, stuff=>{});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment