void GetScoresWithMetadata() { var leaderboard = new OKLeaderboard(SampleLeaderboardID); var request = new GhostScoresRequest(leaderboard); request.Get(response => { switch (response.Status) { case OKIOStatus.Cancelled: OKLog.Info("Cancelled the ghost scores request."); break; case OKIOStatus.FailedWithError: OKLog.Info("Ghost scores request failed with error: " + response.Err.Message); break; case OKIOStatus.Succeeded: OKLog.Info("Ghost ghost scores!"); WriteMetadata(response.scores); break; } }); // Cancel the request anytime with: // request.Cancel(); // new System.Threading.Timer(CancelGhostRequest, request, 150, -1); }
// TODO: This should return a reference to an obj that can cancel all requests. public void ExecuteAsync(GhostScoresDidLoadHandler handler) { _handler = handler; OKLeaderboard leaderboard = new OKLeaderboard(); leaderboard.LeaderboardID = this.LeaderboardID; // Kick off the chain... leaderboard.GetFacebookFriendsScores(FacebookFriendsScoresDidLoad); }
void GetSocialScores() { OKLeaderboard leaderboard = new OKLeaderboard(SampleLeaderboardID); OKLog.Info("Getting scores for leaderboard ID: " + leaderboard.LeaderboardID + " named: " + leaderboard.Name); leaderboard.GetFacebookFriendsScores((List <OKScore> scores, OKException exception2) => { if (exception2 == null) { OKLog.Info("Got facebook friends scores scores in the callback"); } else { OKLog.Info("Error getting facebook friends scores: " + exception2); } }); }
void GetMyBestScore() { OKLeaderboard leaderboard = new OKLeaderboard(); leaderboard.LeaderboardID = SampleLeaderboardID; leaderboard.GetUsersTopScore((score, err) => { if (err == null) { if (score == null) { OKLog.Info("User does not have a score for this leaderboard."); } else { OKLog.Info("Got user's best score: " + score); } } else { OKLog.Info("Error getting best score: " + err.Message); } }); }
// Get the list of leaderboards in C# (native unity) void GetLeaderboards() { OKLeaderboard.GetLeaderboards((List <OKLeaderboard> leaderboards, OKException exception) => { if (leaderboards != null) { OKLog.Info("Received " + leaderboards.Count + " leaderboards "); OKLeaderboard leaderboard = (OKLeaderboard)leaderboards[0]; OKLog.Info("Getting scores for leaderboard ID: " + leaderboard.LeaderboardID + " named: " + leaderboard.Name); leaderboard.GetGlobalScores(1, (List <OKScore> scores, OKException exception2) => { if (exception2 == null) { OKLog.Info("Got global scores in the callback"); } }); } else { OKLog.Info("Error getting leaderboards"); } }); }
void OnGUI() { #if !UNITY_EDITOR GUI.matrix = GetScaleMatrix(); #endif Rect area = (IsPortraitOrientation() ? new Rect(0, 0, 320, 480) : new Rect(0, 0, 480, 320)); GUILayout.BeginArea(area); GUILayoutOption h = GUILayout.Height(35); GUILayout.Label("Testing OpenKit..."); if (GUILayout.Button("Show Leaderboards & Achievements", h)) { ShowLeaderboards(); } if (GUILayout.Button("Show Leaderboards Landscape Only (iOS)", h)) { // For Android, to show Leaderboards landscape only you simply need to modify the AndroidManifest.xml file OKManager.ShowLeaderboardsLandscapeOnly(); } if (GUILayout.Button("Show Login UI", h)) { ShowLoginUI(); } if (GUILayout.Button("Submit Score to Level 2 Leaderboard", h)) { SubmitSampleScore(); } if (GUILayout.Button("Unlock Achievement", h)) { UnlockSampleAchievement(); } if (GUILayout.Button("Store dictionary", h)) { StoreSampleDictionary(); } if (GUILayout.Button("Retrieve Dictionary", h)) { RetrieveSampleDictionary(); } if (GUILayout.Button("Logout from OpenKit", h)) { OKManager.LogoutCurrentUserFromOpenKit(); OKLog.Info("logout of OpenKit"); } if (GUILayout.Button("Get Leaderboards", h)) { OKLeaderboard.GetLeaderboards((List <OKLeaderboard> leaderboards, OKException exception) => { if (leaderboards != null) { Debug.Log("Received " + leaderboards.Count + " leaderboards "); OKLeaderboard leaderboard = (OKLeaderboard)leaderboards[0]; Debug.Log("Getting scores for leaderboard ID: " + leaderboard.LeaderboardID + " named: " + leaderboard.Name); leaderboard.GetGlobalScores(1, (List <OKScore> scores, OKException exception2) => { if (exception2 == null) { Debug.Log("Got global scores in the callback"); } }); } else { Debug.Log("Error getting leaderboards"); } }); } if (GUILayout.Button("Get social scores Friends", h)) { GetSocialScores(); } if (GUILayout.Button("Get my best score!", h)) { GetMyBestScore(); } GUILayout.EndArea(); }