void init() { friendScoreLoaded = false; #if UNITY_EDITOR testMode = true; #endif if (testMode) { // Test values for Unity Editor IScore[] testScores = new IScore[4]; for (int i = 0; i < testScores.Length; i++) { testScores[i] = new IScoreTestImpl(50 * i, testScores.Length - i, "TEST_USER_" + i); } scores = testScores; SocialPlatformManager.cache.myProfile = new IUserProfileTestImpl("TESTMYSELF", null, false, "TEST_MYSELF!!!"); friendScoreLoaded = true; } else { if (SocialPlatformManager.isAuthenticated()) { lb = Social.CreateLeaderboard(); lb.id = SocialPlatformManager.spm.leaderboardInfoMap[AchievementManager.LB_SINGLE]; lb.range = new Range(1, SocialPlatformManager.cache.MaxLoadCount); lb.userScope = SocialPlatformManager.cache.userScope; lb.timeScope = TimeScope.AllTime; lb.LoadScores(loadFriendScores); } } }
/// <summary> /// 获得我的排名 /// </summary> /// <param name="id"></param> /// <param name="onComplete"></param> public void GetMyScore(string id, System.Action <bool, IScore> onComplete) { if (!Social.localUser.authenticated) { return; } ILeaderboard lb = Social.CreateLeaderboard(); lb.id = id; lb.SetUserFilter(new string[] { Social.localUser.id }); lb.LoadScores(b => { onComplete(b, lb.localUserScore); }); }
private void FetchCurrentUserScore(string id, LeaderboardTimeSpan timeSpan) { if (!userSignedIn || leaderboardUserLoadState != LeaderboardLoadState.DoneLoading) { return; } leaderboardUserLoadState = LeaderboardLoadState.LoadingValues; curUserLeaderboardItem.cachedGo.SetActive(false); // Hide current result while loading. curUserLeaderboard = PlayGamesPlatform.Instance.CreateLeaderboard(); curUserLeaderboard.id = id; curUserLeaderboard.range = new Range(int.MaxValue, 0); // We are only getting our local value. So this range doesn't matter. curUserLeaderboard.SetUserFilter(curUserFilter); curUserLeaderboard.timeScope = TimeSpanToTimeScope(timeSpan); curUserLeaderboard.LoadScores(OnLoadedCurrentUserScore); }
public void InitLeaderboardPanel(Transform container, int level) { ILeaderboard leaderboard = Social.CreateLeaderboard(); leaderboard.id = "Level_" + level; leaderboard.timeScope = TimeScope.AllTime; leaderboard.userScope = UserScope.Global; leaderboard.LoadScores((success) => { if (success) { var scores = leaderboard.scores; print("Load Leaderbaord Success : LV-" + level); print("Score Length : " + scores.Length); if (scores.Length > 0) { GameObject LBItem = Resources.Load <GameObject>("Prefabs/LBUserItem"); List <string> userIDs = new List <string>(); foreach (var score in scores) { userIDs.Add(score.userID); } Social.LoadUsers(userIDs.ToArray(), (userList) => { if (level == LevelManager.Instance.currentLevel) { for (int i = 0; i < userList.Length; i++) { var score = scores[i]; GameObject item = Instantiate(LBItem); item.transform.SetParent(container); item.transform.localScale = Vector3.one; item.transform.localPosition = Vector3.zero; item.GetComponent <LBItem>().Init(userList[i].image, userList[i].userName, score.value.ToString(), score.rank); } } }); } } else { print("Error Loading Leaderboard"); } }); }
internal void DoLoadLeaderboard() { ILeaderboard lb = PlayGamesPlatform.Instance.CreateLeaderboard(); lb.id = GPGSIds.leaderboard_leaders_in_smoketesting; lb.LoadScores(ok => { if (ok) { LoadUsersAndDisplay(lb); } else { mStatus = "Leaderboard loading: " + lb.title + " ok = " + ok; } }); }
public void LoadBoard(string id) { ILeaderboard lb = PlayGamesPlatform.Instance.CreateLeaderboard(); lb.id = id; lb.LoadScores(ok => { if (ok) { LoadUsersAndDisplay(lb); } else { Debug.Log("Error retrieving leaderboard"); } }); }
public void init() { if (SocialPlatformManager.isAuthenticated()) { Debug.Log("SocialDataCache: Start initializing..."); #if UNITY_IOS // Write for Game Center lb = Social.CreateLeaderboard(); #elif UNITY_ANDROID lb = PlayGamesPlatform.Instance.CreateLeaderboard(); #endif lb.id = SocialPlatformManager.spm.leaderboardInfoMap[AchievementManager.LB_SINGLE]; lb.range = new Range(1, MaxLoadCount); lb.userScope = userScope; lb.timeScope = TimeScope.AllTime; lb.LoadScores(loadFriendScores); } else { Debug.Log("SocialDataCache: Not authorized yet"); } }
public void LoadLeaderboardScores() { if (this.Authenticated && !Application.isEditor) { foreach (string id in this.m_leaderboardIDs) { ILeaderboard lb = Social.CreateLeaderboard(); lb.id = id; lb.LoadScores(delegate(bool result) { LeaderboardDataStruct value = default(LeaderboardDataStruct); value.title = lb.title; value.rank = lb.localUserScore.rank; long.TryParse(lb.localUserScore.formattedValue, out value.score); this.m_leaderboardList.Add(lb.id, value); }); } } }
public override bool LoadLeaderboardAsync(bool forceLoadingNewScores) { bool returnFlag = false; // Check if the leaderboard is created, and scores haven't been loaded yet (or we want to force the score loading) if ((CurrentState == State.NothingLoaded) || (forceLoadingNewScores == true)) { // Setup flags returnFlag = true; CurrentState = State.AttemptingToLoadScores; // Start loading in scores if (Debug.isDebugBuild == true) { Debug.Log("Loading Scores for: " + DebugId); } reference.LoadScores(OnScoresLoaded); } return(returnFlag); }
/// <summary> /// 获取排行榜的排名 /// </summary> /// <param name="id">排行榜ID</param> /// <param name="range">区间</param> /// <param name="onComplete">完成回调</param> /// <param name="scope">时间区间</param> /// <param name="userScope">用户区间</param> public void GetTopByByLeaderboardID(string id, Range range, System.Action <bool, IScore[]> onComplete, TimeScope scope = TimeScope.AllTime, UserScope userScope = UserScope.Global) { if (!Social.localUser.authenticated) { return; } ILeaderboard lb = Social.CreateLeaderboard(); Debug.Log(lb); if (lb == null) { return; } lb.id = id; lb.range = range; lb.timeScope = scope; lb.userScope = userScope; lb.LoadScores(ok => { onComplete(ok, lb.scores); }); }
// Use this for initialization private void LoadLeaderBoard() { #if UNITY_IOS && !UNITY_EDITOR memory = Social.CreateLeaderboard(); memory.id = "MemoryLeaderBoard"; memory.LoadScores(result => DidLoadLeaderboard(result, memory)); ninja = Social.CreateLeaderboard(); ninja.id = "NinjaLeaderBoard"; ninja.LoadScores(result => DidLoadLeaderboard(result, ninja)); doctor = Social.CreateLeaderboard(); doctor.id = "DoctorLeaderBoard"; doctor.LoadScores(result => DidLoadLeaderboard(result, doctor)); shooter = Social.CreateLeaderboard(); shooter.id = "ShooterLeaderBoard"; shooter.LoadScores(result => DidLoadLeaderboard(result, shooter)); runner = Social.CreateLeaderboard(); runner.id = "RUNNERLeaderBoard"; runner.LoadScores(result => DidLoadLeaderboard(result, runner)); micromix = Social.CreateLeaderboard(); micromix.id = "MicroMixLeaderBoard"; micromix.LoadScores(result => DidLoadLeaderboard(result, micromix)); #endif }
public static void GetLeaderboard(string id, string userid, Action <long> callbackSuccess = null, Action callbackFailure = null) { ILeaderboard lb = PlayGamesPlatform.Instance.CreateLeaderboard(); lb.id = id; lb.SetUserFilter(new string[] { userid }); lb.LoadScores(ok => { if (ok) { if (callbackSuccess != null) { callbackSuccess.Invoke(lb.localUserScore.value); } } else { if (callbackFailure != null) { callbackFailure.Invoke(); } } }); }
//this actually fills the list in public void Populate_Scores_List() { if (Lookup_Scope(Scopes.CurrentScreen()) == "Local") { string gameMode = Lookup_Game_Type(Modes.CurrentScreen()); for (int i = 0; i < 15; i++) { int currScore = PlayerPrefs.GetInt(gameMode + " score " + i, 0); if (currScore == 0) { ScoreList[i].text = (i + 1) + ". -------"; } else { ScoreList[i].text = (i + 1) + ". " + currScore; } } } else { //TODO: Implement global and friends lists for real for (int i = 0; i < 14; i++) { ScoreList[i].text = (i + 1) + " -------"; } if (gpgh != null && gpgh.isSignedIn()) { ScoreList[14].text = "Called this"; ILeaderboard lb = PlayGamesPlatform.Instance.CreateLeaderboard(); switch (Lookup_Game_Type(Modes.CurrentScreen())) { case "Wiz": lb.id = GPG_Ids.leaderboard_wiz_split_leaderboard; break; case "Quick": lb.id = GPG_Ids.leaderboard_quick_split_leaderboard; break; case "Wit": lb.id = GPG_Ids.leaderboard_wit_split_leaderboard; break; case "Holy": lb.id = GPG_Ids.leaderboard_holy_split_leaderboard; break; default: lb.id = GPG_Ids.leaderboard_wiz_split_leaderboard; break; } ScoreList[3].text = Lookup_Game_Type(Modes.CurrentScreen()); lb.LoadScores(ok => { if (ok) { ScoreList[4].text = "Good"; LoadUsersandScores(lb); } else { Debug.Log("Error retrieving leaderboardi"); ScoreList[4].text = "Error"; LoadUsersandScores(null); } }); } } }
void ProcessAuthentication(bool success) { if (success) { Debug.Log ("Authenticated, checking achievements"); leaderboard = Social.CreateLeaderboard(); if (paidVersion) { leaderboard.id = "com.hemant.triplecommaclubpaid"; } else { leaderboard.id = "com.hemant.triplecommaclub"; } leaderboard.LoadScores(scoreSuccess => { if (scoreSuccess && leaderboard.scores.Length > 0) { Debug.Log ("Got " + leaderboard.scores.Length + " scores"); string myScores = "Leaderboard:\n"; foreach (IScore score in leaderboard.scores) myScores += "\t" + score.userID + " " + score.formattedValue + " " + score.date + "\n"; Debug.Log (myScores); } }); } else { Debug.Log ("Failed to authenticate"); } }
static void DoNextLoadScoreRequest() { LoadScoreRequest request; if (isLoadingScore) { if (Debug.isDebugBuild) { Debug.Log("DoNextLoadScoreRequest POSTPONED: is loading another request."); } return; } if (loadScoreRequests.Count == 0) { if (Debug.isDebugBuild) { Debug.Log("DoNextLoadScoreRequest DONE: no more requests in queue."); } return; } if (Debug.isDebugBuild) { Debug.Log("Performing next score loading request..."); } isLoadingScore = true; request = loadScoreRequests[0]; // fetch the next request loadScoreRequests.RemoveAt(0); // then remove it from the queue // Now create a new leaderboard and start loading scores ILeaderboard ldb = Social.CreateLeaderboard(); ldb.id = request.leaderboardId; if (request.useLeaderboardDefault) { // The current iOS implementation of ISocialPlatform behaves weirdly with Social.LoadScores. // Experiment showed that only the first score on the leaderboard was returned. // On Android scores were returned properly. // We'll have different code for the two platforms in an attempt to provide consistent behavior from the outside. #if UNITY_ANDROID // On Android, we'll use LoadScores directly from Social. Social.LoadScores(ldb.id, (IScore[] scores) => { if (Debug.isDebugBuild) { Debug.Log("Successfully loaded default set of scores from leaderboard: " + ldb.id); Debug.Log("Got " + scores.Length + " scores."); } request.callback(request.leaderboardName, scores); // Load next request isLoadingScore = false; DoNextLoadScoreRequest(); }); #elif UNITY_IOS // On iOS, we use LoadScores from ILeaderboard with default parameters. ldb.LoadScores((bool success) => { if (Debug.isDebugBuild) { Debug.Log("Successfully loaded default set of scores from leaderboard: " + ldb.id); Debug.Log("Got " + ldb.scores.Length + " scores."); } request.callback(request.leaderboardName, ldb.scores); // Load next request isLoadingScore = false; DoNextLoadScoreRequest(); }); #endif } else { ldb.timeScope = request.timeScope; ldb.userScope = request.userScope; if (request.fromRank > 0 && request.scoreCount > 0) { ldb.range = new Range(request.fromRank, request.scoreCount); } ldb.LoadScores((bool success) => { if (request.loadLocalUserScore) { if (Debug.isDebugBuild) { Debug.Log("Successfully loaded local user score from leaderboard: " + ldb.id); } IScore[] returnScores = new IScore[] { ldb.localUserScore }; request.callback(request.leaderboardName, returnScores); } else { if (Debug.isDebugBuild) { Debug.Log("Successfully loaded custom set of scores from leaderboard: " + ldb.id); Debug.Log("Got " + ldb.scores.Length + " scores:"); } request.callback(request.leaderboardName, ldb.scores); } // Load next request isLoadingScore = false; DoNextLoadScoreRequest(); }); } }
/************************************************************************************************ * NAME : DoLeaderboard * ACTION : Called from DoLeaderboard when game center has been authenticated * INPUT : none * OUTPUT : none *************************************************************************************************/ void DoLeaderboard() { Leaderboard = Social.CreateLeaderboard(); Leaderboard.id = "TorpedoRun_L7"; /* your game centre leaderboard ID goes here */ D.logx("Loading Leaderboard {0}",Leaderboard.id); Leaderboard.range = new Range(1,100); Leaderboard.LoadScores(result => DidLoadScores(result)); }
/// <summary> /// Loads the scores. /// </summary> /// <param name='board'> /// Board. /// </param> /// <param name='callback'> /// Callback. /// </param> public void LoadScores(ILeaderboard board, System.Action<bool> callback) { // This function doesn't do anything with a null leaderboard. if(null == board) { AGSClient.LogGameCircleError("LoadScores \"board\" argument should not be null"); return; } board.LoadScores(callback); }
void DoLeaderboard() { leaderboard = Social.CreateLeaderboard(); leaderboard.id = "Leaderboard012"; leaderboard.LoadScores(result => DidLoadLeaderboard(result)); }
/// <summary> /// Get the leaderboard. /// </summary> void DoLeaderboard() { m_Leaderboard = Social.CreateLeaderboard(); m_Leaderboard.id = leaderboardID; // YOUR CUSTOM LEADERBOARD NAME m_Leaderboard.LoadScores(result => DidLoadLeaderboard(result)); }
static void DoNextLoadScoreRequest() { LoadScoreRequest request; if (isLoadingScore) { return; } if (loadScoreRequests.Count == 0) { return; } isLoadingScore = true; request = loadScoreRequests[0]; // fetch the next request loadScoreRequests.RemoveAt(0); // then remove it from the queue // Now create a new leaderboard and start loading scores ILeaderboard ldb = Social.CreateLeaderboard(); ldb.id = request.leaderboardId; if (request.useLeaderboardDefault) { // The current iOS implementation of ISocialPlatform behaves weirdly with Social.LoadScores. // Experiment showed that only the first score on the leaderboard was returned. // On Android scores were returned properly. // We'll have different code for the two platforms in an attempt to provide consistent behavior from the outside. #if UNITY_ANDROID // On Android, we'll use LoadScores directly from Social. Social.LoadScores(ldb.id, (IScore[] scores) => { if (request.callback != null) { request.callback(request.leaderboardName, scores); } // Load next request isLoadingScore = false; DoNextLoadScoreRequest(); }); #elif UNITY_IOS // On iOS, we use LoadScores from ILeaderboard with default parameters. ldb.LoadScores((bool success) => { if (request.callback != null) { request.callback(request.leaderboardName, ldb.scores); } // Load next request isLoadingScore = false; DoNextLoadScoreRequest(); }); #endif } else { ldb.timeScope = request.timeScope; ldb.userScope = request.userScope; if (request.fromRank > 0 && request.scoreCount > 0) { ldb.range = new UnityEngine.SocialPlatforms.Range(request.fromRank, request.scoreCount); } ldb.LoadScores((bool success) => { if (request.loadLocalUserScore) { IScore[] returnScores = new IScore[] { ldb.localUserScore }; if (request.callback != null) { request.callback(request.leaderboardName, returnScores); } } else { if (request.callback != null) { request.callback(request.leaderboardName, ldb.scores); } } // Load next request isLoadingScore = false; DoNextLoadScoreRequest(); }); } }