Comments (2)
Here is an example in the awake function. After login it will load the best score of the logged in user from a specific leaderboard:
#if UNITY_ANDROID
using UnityEngine;
using System.Collections;
using GooglePlayGames;
using UnityEngine.SocialPlatforms;
using GooglePlayGames.BasicApi;
using UnityEngine.SceneManagement;
public class GooglePlayGamesScript : MonoBehaviour
{
private int TotalPoints;
void Awake()
{
TotalPoints = PlayerPrefs.GetInt("TotalPoints");
PlayGamesPlatform.Activate();
Social.localUser.Authenticate(
(bool success) =>
{
if (success)
{
Debug.Log("Authentication was successful");
LoadTotalPoints();
}
if (!success)
{
Debug.Log("Authentication failed");
LoadGameScene();
}
}
);
}
void LoadTotalPoints()
{
PlayGamesPlatform.Instance.LoadScores(
"CgkIxOLRsfsXXXXXXX",
LeaderboardStart.PlayerCentered,
1,
LeaderboardCollection.Public,
LeaderboardTimeSpan.AllTime,
(LeaderboardScoreData data) =>
{
if (data == null || data.PlayerScore == null)
{
Debug.Log("There was no PlayerScore in LeaderboardScoreData");
LoadGameScene();
}
if (data != null && data.PlayerScore != null)
{
Debug.Log(data.Valid);
Debug.Log(data.Id);
Debug.Log(data.PlayerScore);
Debug.Log(data.PlayerScore.userID);
Debug.Log(data.PlayerScore.formattedValue);
if (int.Parse(data.PlayerScore.formattedValue) > TotalPoints)
{
PlayerPrefs.SetInt(
"TotalPoints",
int.Parse(data.PlayerScore.formattedValue)
);
}
Debug.Log("LoadTotalPoints has finished");
LoadGameScene();
}
}
);
}
void LoadGameScene()
{
Scene scene = SceneManager.GetActiveScene();
if (scene.buildIndex == 0)
{
SceneManager.LoadScene(1);
}
}
}
#endif
from play-games-plugin-for-unity.
Here is an example in the awake function. After login it will load the best score of the logged in user from a specific leaderboard:
#if UNITY_ANDROID using UnityEngine; using System.Collections; using GooglePlayGames; using UnityEngine.SocialPlatforms; using GooglePlayGames.BasicApi; using UnityEngine.SceneManagement; public class GooglePlayGamesScript : MonoBehaviour { private int TotalPoints; void Awake() { TotalPoints = PlayerPrefs.GetInt("TotalPoints"); PlayGamesPlatform.Activate(); Social.localUser.Authenticate( (bool success) => { if (success) { Debug.Log("Authentication was successful"); LoadTotalPoints(); } if (!success) { Debug.Log("Authentication failed"); LoadGameScene(); } } ); } void LoadTotalPoints() { PlayGamesPlatform.Instance.LoadScores( "CgkIxOLRsfsXXXXXXX", LeaderboardStart.PlayerCentered, 1, LeaderboardCollection.Public, LeaderboardTimeSpan.AllTime, (LeaderboardScoreData data) => { if (data == null || data.PlayerScore == null) { Debug.Log("There was no PlayerScore in LeaderboardScoreData"); LoadGameScene(); } if (data != null && data.PlayerScore != null) { Debug.Log(data.Valid); Debug.Log(data.Id); Debug.Log(data.PlayerScore); Debug.Log(data.PlayerScore.userID); Debug.Log(data.PlayerScore.formattedValue); if (int.Parse(data.PlayerScore.formattedValue) > TotalPoints) { PlayerPrefs.SetInt( "TotalPoints", int.Parse(data.PlayerScore.formattedValue) ); } Debug.Log("LoadTotalPoints has finished"); LoadGameScene(); } } ); } void LoadGameScene() { Scene scene = SceneManager.GetActiveScene(); if (scene.buildIndex == 0) { SceneManager.LoadScene(1); } } } #endif
Thank you so much!
from play-games-plugin-for-unity.
Related Issues (20)
- Unity splash Auto Login
- [Bug] Non-secure network connections error
- How would this plugin behave when granular permissions of Google OAuth is enabled? HOT 6
- Authentication failed. Prompt shows 400 Bad Request
- Sign in doesn't work. Returning an error code. HOT 11
- Only One Player data Saved
- Automated testing isn't possible with auto sign in as it hangs on the create profile screen
- Cloud saves sometimes deleted?
- `SavedGameMetadata` is closed after `CommitUpdate` HOT 1
- Is it possible to do a silent login with play games platform? HOT 1
- Errors on install from Package Manager (missing .meta files) HOT 4
- Cannot create a new save data file with OpenWithAutomaticConflictResolution HOT 1
- Issue getting Saved Games to work on device HOT 3
- Exception java.lang.NullPointerException: null reference at com.google.android.gms.games.ui.signinflow.SignInChimeraActivity.F HOT 15
- How to validate an auth token in my custom backend? HOT 1
- When uploading to google play get message (Update your Play Core Maven dependency to an Android 14 compatible version! ) HOT 5
- How to map Google Services Leaderboard user id to current user?
- Google play serices doesn't call authentificate function HOT 1
- Not up to date for google requirements HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from play-games-plugin-for-unity.