/// <summary> /// Prevent people from calling default constructor. /// </summary> public AGSSocialLeaderboard() { leaderboard = AGSLeaderboard.GetBlankLeaderboard (); localPlayerScore = -1; localPlayerRank = -1; _timeScope = TimeScope.AllTime; }
/// <summary> /// Initializes a new instance of the <see cref="AGSSocialLeaderboard"/> class. /// </summary> /// <param name='leaderboard'> /// Leaderboard. /// </param> public AGSSocialLeaderboard(AGSLeaderboard leaderboard) { if(null == leaderboard) { AGSClient.LogGameCircleError("AGSSocialLeaderboard constructor \"leaderboard\" argument should not be null"); return; } this.leaderboard = leaderboard; id = leaderboard.id; }
public static AGSLeaderboard GetBlankLeaderboard() { AGSLeaderboard leaderboard = new AGSLeaderboard (); leaderboard.name = ""; leaderboard.id = ""; leaderboard.displayText = ""; leaderboard.scoreFormat = ""; leaderboard.imageUrl = ""; return leaderboard; }
public static AGSLeaderboard fromHashtable( Hashtable hashtable ) { var board = new AGSLeaderboard(); board.name = hashtable["leaderboardName"].ToString(); board.id = hashtable["leaderboardId"].ToString(); board.displayText = hashtable["leaderboardDisplayText"].ToString(); board.scoreFormat = hashtable["leaderboardScoreFormat"].ToString(); board.imageUrl = hashtable ["leaderboardImageUrl"].ToString (); return board; }
/// <summary> /// Initializes a new instance of the <see cref="AGSSocialLeaderboardScore"/> class. /// </summary> /// <param name='score'> /// Score. /// </param> /// <param name='leaderboard'> /// Leaderboard. /// </param> public AGSSocialLeaderboardScore(AGSScore score, AGSLeaderboard leaderboard) { if(null == score) { AGSClient.LogGameCircleError("AGSSocialLeaderboardScore constructor \"score\" argument should not be null"); return; } if(null == leaderboard) { AGSClient.LogGameCircleError("AGSSocialLeaderboardScore constructor \"leaderboard\" argument should not be null"); return; } this.score = score; leaderboardID = leaderboard.id; value = score.scoreValue; }
/// <summary> /// Initializes a new instance of the <see cref="AGSSocialLeaderboard"/> class. /// </summary> /// <param name='leaderboard'> /// Leaderboard. /// </param> public AGSSocialLeaderboard(AGSLeaderboard leaderboard) { if(null == leaderboard) { AGSClient.LogGameCircleError("AGSSocialLeaderboard constructor \"leaderboard\" argument should not be null"); this.leaderboard = AGSLeaderboard.GetBlankLeaderboard(); } else { this.leaderboard = leaderboard; } id = leaderboard.id; scores = new AGSSocialLeaderboardScore[0]; localPlayerScore = -1; localPlayerRank = -1; _timeScope = TimeScope.AllTime; }
public static AGSRequestPercentilesResponse GetBlankResponseWithError(string error, string leaderboardId = "", LeaderboardScope scope = LeaderboardScope.GlobalAllTime, int userData = 0) { AGSRequestPercentilesResponse response = new AGSRequestPercentilesResponse(); response.error = error; response.userData = userData; response.leaderboardId = leaderboardId; response.scope = scope; response.leaderboard = AGSLeaderboard.GetBlankLeaderboard(); response.percentiles = new List <AGSLeaderboardPercentile>(); response.userIndex = -1; response.scope = scope; return(response); }
/// <summary> /// Initializes a new instance of the <see cref="AGSSocialLeaderboard"/> class. /// </summary> /// <param name='leaderboard'> /// Leaderboard. /// </param> public AGSSocialLeaderboard(AGSLeaderboard leaderboard) { if (null == leaderboard) { AGSClient.LogGameCircleError("AGSSocialLeaderboard constructor \"leaderboard\" argument should not be null"); this.leaderboard = AGSLeaderboard.GetBlankLeaderboard(); } else { this.leaderboard = leaderboard; } id = leaderboard.id; scores = new AGSSocialLeaderboardScore[0]; localPlayerScore = -1; localPlayerRank = -1; _timeScope = TimeScope.AllTime; }
public static AGSLeaderboard fromHashtable( Hashtable ht ) { var board = new AGSLeaderboard(); board.name = ht["name"].ToString(); board.id = ht["id"].ToString(); board.displayText = ht["displayText"].ToString(); board.scoreFormat = ht["scoreFormat"].ToString(); // handle scores if we have them if( ht.ContainsKey( "scores" ) && ht["scores"] is ArrayList ) { var scoresList = ht["scores"] as ArrayList; board.scores = AGSScore.fromArrayList( scoresList ); } return board; }
public static AGSLeaderboard fromHashtable(Hashtable ht) { var board = new AGSLeaderboard(); board.name = ht["name"].ToString(); board.id = ht["id"].ToString(); board.displayText = ht["displayText"].ToString(); board.scoreFormat = ht["scoreFormat"].ToString(); // handle scores if we have them if (ht.ContainsKey("scores") && ht["scores"] is ArrayList) { var scoresList = ht["scores"] as ArrayList; board.scores = AGSScore.fromArrayList(scoresList); } return(board); }
/// <summary> /// callback method for native code to communicate events back to unity /// </summary> public static void RequestPercentileRanksSucceeded(string json) { if (RequestPercentileRanksSucceededEvent != null) { var ht = json.hashtableFromJson(); AGSLeaderboard leaderboard = AGSLeaderboard.fromHashtable(ht["leaderboard"] as Hashtable); var arrayList = (ht["percentiles"] as ArrayList); List <AGSLeaderboardPercentile> percentiles = new List <AGSLeaderboardPercentile>(); foreach (Hashtable pht in arrayList) { percentiles.Add(AGSLeaderboardPercentile.fromHashTable(pht)); } int localPlayerIndex = int.Parse(ht["localPlayerIndex"].ToString()); RequestPercentileRanksSucceededEvent(leaderboard, percentiles, localPlayerIndex); } }
private void RequestPercentileRanksSucceeded(AGSLeaderboard leaderboard, List <AGSLeaderboardPercentile> percentiles, int localPlayerIndex) { // Make sure the percentile ranks request status dictionary has this leaderboard key. if (!leaderboardsPercentilesStatus.ContainsKey(leaderboard.id)) { leaderboardsPercentilesStatus.Add(leaderboard.id, null); } // Format the response into human readable strings. List <string> formattedResult = new List <string>(); foreach (AGSLeaderboardPercentile percentile in percentiles) { formattedResult.Add(string.Format(percentileRankLabel, percentile.player.ToString(), percentile.percentile, percentile.score)); } formattedResult.Add(string.Format(localPlayerIndexLabel, localPlayerIndex)); // Update the status for the percentile response. leaderboardsPercentilesStatus[leaderboard.id] = formattedResult; // Once the callback is received, these events do not need to be subscribed to. UnsubscribeFromPercentileRanksRequestEvents(); }
public static AGSRequestLeaderboardsResponse FromJSON(string json) { try { AGSRequestLeaderboardsResponse response = new AGSRequestLeaderboardsResponse(); Hashtable hashtable = json.hashtableFromJson(); response.error = hashtable.ContainsKey("error") ? hashtable ["error"].ToString() : ""; response.userData = hashtable.ContainsKey("userData") ? int.Parse(hashtable ["userData"].ToString()) : 0; response.leaderboards = new List <AGSLeaderboard>(); if (hashtable.ContainsKey("leaderboards")) { foreach (Hashtable leaderboardHashtable in hashtable["leaderboards"] as ArrayList) { response.leaderboards.Add(AGSLeaderboard.fromHashtable(leaderboardHashtable)); } } return(response); } catch (Exception e) { AGSClient.LogGameCircleError(e.ToString()); return(GetBlankResponseWithError(JSON_PARSE_ERROR)); } }
/// <summary> /// Displays an individual leaderboard. /// </summary> /// <param name='leaderboard'> /// Leaderboard. /// </param> void DisplayLeaderboard(AGSLeaderboard leaderboard) { // Place a box around each leaderboard, to make it clear in the UI // what controls are for what leaderboard. GUILayout.BeginVertical(GUI.skin.box); // make sure this leaderboard is in the foldout dictionary. if (!leaderboardsFoldout.ContainsKey(leaderboard.id)) { leaderboardsFoldout.Add(leaderboard.id, false); } // Display a foldout for this leaderboard. // Foldouts keep the menu tidy. leaderboardsFoldout[leaderboard.id] = AmazonGUIHelpers.FoldoutWithLabel(leaderboardsFoldout[leaderboard.id], string.Format(leaderboardIDLabel, leaderboard.id)); // If the foldout is open, display the leaderboard information. if (leaderboardsFoldout[leaderboard.id]) { // The controls for automatically word wrapping a label are not great, // so replacing every second comma in the string returned from the leaderboard's toString function // will allow for a cleaner display of each leaderboard's data AmazonGUIHelpers.AnchoredLabel(AddNewlineEverySecondComma(leaderboard.ToString()), TextAnchor.UpperCenter); // Display a centered slider, with the minimum value on the left, and maximum value on the right. // This lets the user select a value for the leaderboard's score. leaderboardScoreValue = (long)AmazonGUIHelpers.DisplayCenteredSlider(leaderboardScoreValue, leaderboardMinValue, leaderboardMaxValue, leaderboardScoreDisplayLabel); // If a leaderboard score submission is in progress, show its status. if (leaderboardsSubmissionStatus.ContainsKey(leaderboard.id) && !string.IsNullOrEmpty(leaderboardsSubmissionStatus[leaderboard.id])) { AmazonGUIHelpers.CenteredLabel(leaderboardsSubmissionStatus[leaderboard.id]); // Display any additional status message / error for this leaderboard submission. if (leaderboardsSubmissionStatusMessage.ContainsKey(leaderboard.id) && !string.IsNullOrEmpty(leaderboardsSubmissionStatusMessage[leaderboard.id])) { AmazonGUIHelpers.CenteredLabel(leaderboardsSubmissionStatusMessage[leaderboard.id]); } } // This button submits an update to the leaderboard's score to the GameCircle plugin. if (GUILayout.Button(submitLeaderboardButtonLabel)) { SubmitScoreToLeaderboard(leaderboard.id, leaderboardScoreValue); } // If a request has been made for the local user's score, display the status of that request. if (leaderboardsLocalScoreStatus.ContainsKey(leaderboard.id) && !string.IsNullOrEmpty(leaderboardsLocalScoreStatus[leaderboard.id])) { AmazonGUIHelpers.AnchoredLabel(leaderboardsLocalScoreStatus[leaderboard.id], TextAnchor.UpperCenter); // Display any additional information for the status message from the local score request. if (leaderboardsLocalScoreStatusMessage.ContainsKey(leaderboard.id) && !string.IsNullOrEmpty(leaderboardsLocalScoreStatusMessage[leaderboard.id])) { AmazonGUIHelpers.AnchoredLabel(leaderboardsLocalScoreStatusMessage[leaderboard.id], TextAnchor.UpperCenter); } } // This button requests the local user's score. if (GUILayout.Button(requestLeaderboardScoreButtonLabel)) { RequestLocalPlayerScore(leaderboard.id); } // If a request has been made for the percentile ranks, display the status of that request. if (leaderboardsPercentilesStatus.ContainsKey(leaderboard.id)) { foreach (string percentileInfo in leaderboardsPercentilesStatus[leaderboard.id]) { if (!string.IsNullOrEmpty(percentileInfo)) { AmazonGUIHelpers.AnchoredLabel(percentileInfo, TextAnchor.UpperCenter); } } // Display any additional information for the status message from the percentile ranks request. if (leaderboardsPercentilesStatusMessage.ContainsKey(leaderboard.id) && !string.IsNullOrEmpty(leaderboardsPercentilesStatusMessage[leaderboard.id])) { AmazonGUIHelpers.AnchoredLabel(leaderboardsPercentilesStatusMessage[leaderboard.id], TextAnchor.UpperCenter); } } if (GUILayout.Button(requestLeaderboardPercentilesButtonLabel)) { RequestPercentileRanks(leaderboard.id); } } GUILayout.EndVertical(); }
/// <summary> /// Initializes a new instance of the <see cref="AGSSocialLeaderboard"/> class. /// </summary> public AGSSocialLeaderboard() { this.leaderboard = null; }
/// <summary> /// Initializes a new instance of the <see cref="AmazonGameCircleExampleLeaderboards"/> class. /// </summary> private AmazonGameCircleExampleLeaderboards() { AGSLeaderboardsClient.RequestLeaderboardsCompleted += OnRequestLeaderboardsCompleted; AGSLeaderboardsClient.SubmitScoreCompleted += OnSubmitScoreCompleted; AGSLeaderboardsClient.RequestLocalPlayerScoreCompleted += OnRequestLocalPlayerScoreCompleted; AGSLeaderboardsClient.RequestScoresCompleted += OnRequestScoresCompleted; AGSLeaderboardsClient.RequestPercentileRanksCompleted += OnRequestPercentileRanksCompleted; AGSLeaderboardsClient.RequestPercentileRanksCompleted += OnRequestPercentileRanksCompleted; AGSLeaderboardsClient.RequestScoreForPlayerCompleted += OnRequestScoreForPlayerCompleted; AGSLeaderboardsClient.RequestPercentileRanksForPlayerCompleted += OnRequestPercentilesForPlayerCompleted; AGSPlayerClient.RequestFriendIdsCompleted += OnRequestFriendsCompleted; // This is used to test the GameCircle plugin's behaviour with invalid leaderboard information. // This leaderboard ID should not be in your game's list, to test what happens with invalid leaderboard submissions. invalidLeaderboard = new AGSLeaderboard(); invalidLeaderboard.id = "Invalid Leaderboard ID"; }
/// <summary> /// Displays an individual leaderboard. /// </summary> /// <param name='leaderboard'> /// Leaderboard. /// </param> void DisplayLeaderboard(AGSLeaderboard leaderboard) { // Place a box around each leaderboard, to make it clear in the UI // what controls are for what leaderboard. GUILayout.BeginVertical(GUI.skin.box); // make sure this leaderboard is in the foldout dictionary. if(!leaderboardsFoldout.ContainsKey(leaderboard.id)) { leaderboardsFoldout.Add(leaderboard.id,false); } // Display a foldout for this leaderboard. // Foldouts keep the menu tidy. leaderboardsFoldout[leaderboard.id] = AmazonGUIHelpers.FoldoutWithLabel(leaderboardsFoldout[leaderboard.id],string.Format(leaderboardIDLabel,leaderboard.id)); // If the foldout is open, display the leaderboard information. if(leaderboardsFoldout[leaderboard.id]) { // The controls for automatically word wrapping a label are not great, // so replacing every second comma in the string returned from the leaderboard's toString function // will allow for a cleaner display of each leaderboard's data AmazonGUIHelpers.AnchoredLabel(AddNewlineEverySecondComma(leaderboard.ToString()),TextAnchor.UpperCenter); // Display a centered slider, with the minimum value on the left, and maximum value on the right. // This lets the user select a value for the leaderboard's score. leaderboardScoreValue = (long)AmazonGUIHelpers.DisplayCenteredSlider(leaderboardScoreValue,leaderboardMinValue,leaderboardMaxValue,leaderboardScoreDisplayLabel); // If a leaderboard score submission is in progress, show its status. if(leaderboardsSubmissionStatus.ContainsKey(leaderboard.id) && !string.IsNullOrEmpty(leaderboardsSubmissionStatus[leaderboard.id])) { AmazonGUIHelpers.CenteredLabel(leaderboardsSubmissionStatus[leaderboard.id]); // Display any additional status message / error for this leaderboard submission. if(leaderboardsSubmissionStatusMessage.ContainsKey(leaderboard.id) && !string.IsNullOrEmpty(leaderboardsSubmissionStatusMessage[leaderboard.id])) { AmazonGUIHelpers.CenteredLabel(leaderboardsSubmissionStatusMessage[leaderboard.id]); } } // This button submits an update to the leaderboard's score to the GameCircle plugin. if(GUILayout.Button(submitLeaderboardButtonLabel)) { AGSLeaderboardsClient.SubmitScore(leaderboard.id, leaderboardScoreValue); } // If a request has been made for the local user's score, display the status of that request. if(leaderboardsLocalScoreStatus.ContainsKey(leaderboard.id) && !string.IsNullOrEmpty(leaderboardsLocalScoreStatus[leaderboard.id])) { AmazonGUIHelpers.AnchoredLabel(leaderboardsLocalScoreStatus[leaderboard.id],TextAnchor.UpperCenter); // Display any additional information for the status message from the local score request. if(leaderboardsLocalScoreStatusMessage.ContainsKey(leaderboard.id) && !string.IsNullOrEmpty(leaderboardsLocalScoreStatusMessage[leaderboard.id])) { AmazonGUIHelpers.AnchoredLabel(leaderboardsLocalScoreStatusMessage[leaderboard.id],TextAnchor.UpperCenter); } } // This button requests the local user's score. if(GUILayout.Button(requestLeaderboardScoreButtonLabel)) { AGSLeaderboardsClient.RequestLocalPlayerScore(leaderboard.id,leaderboardScoreScope); } // If a request has been made for the top scores, display the status of that request. if(leaderboardsScoresStatus.ContainsKey(leaderboard.id)) { foreach (string scoreInfo in leaderboardsScoresStatus[leaderboard.id]){ if (!string.IsNullOrEmpty(scoreInfo)){ AmazonGUIHelpers.AnchoredLabel(scoreInfo, TextAnchor.UpperCenter); } } // Display any additional information for the status message from the top scores request. if(leaderboardsScoresStatusMessage.ContainsKey(leaderboard.id) && !string.IsNullOrEmpty(leaderboardsScoresStatusMessage[leaderboard.id])) { AmazonGUIHelpers.AnchoredLabel(leaderboardsScoresStatusMessage[leaderboard.id],TextAnchor.UpperCenter); } } if(GUILayout.Button(requestTopScoresButtonLabel)) { AGSLeaderboardsClient.RequestScores(leaderboard.id, leaderboardScoreScope); } // If a request has been made for the percentile ranks, display the status of that request. if(leaderboardsPercentilesStatus.ContainsKey(leaderboard.id)) { foreach (string percentileInfo in leaderboardsPercentilesStatus[leaderboard.id]){ if (!string.IsNullOrEmpty(percentileInfo)){ AmazonGUIHelpers.AnchoredLabel(percentileInfo, TextAnchor.UpperCenter); } } // Display any additional information for the status message from the percentile ranks request. if(leaderboardsPercentilesStatusMessage.ContainsKey(leaderboard.id) && !string.IsNullOrEmpty(leaderboardsPercentilesStatusMessage[leaderboard.id])) { AmazonGUIHelpers.AnchoredLabel(leaderboardsPercentilesStatusMessage[leaderboard.id],TextAnchor.UpperCenter); } } if(GUILayout.Button(requestLeaderboardPercentilesButtonLabel)) { AGSLeaderboardsClient.RequestPercentileRanks(leaderboard.id, leaderboardScoreScope); } if (friendIds == null && GUILayout.Button("Get Friends")){ friendStatus = "Waiting for friends..."; AGSPlayerClient.RequestFriendIds(); } if (!string.IsNullOrEmpty(friendStatus)) { AmazonGUIHelpers.CenteredLabel(friendStatus); } if (friendIds != null) { if(!showPlayerScoreRequestButtons.ContainsKey(leaderboard.id)) { showPlayerScoreRequestButtons.Add(leaderboard.id,false); } GUILayout.BeginVertical(GUI.skin.box); showPlayerScoreRequestButtons[leaderboard.id] = AmazonGUIHelpers.FoldoutWithLabel(showPlayerScoreRequestButtons[leaderboard.id],"Request score for friend"); if (showPlayerScoreRequestButtons[leaderboard.id]) { foreach (string friend in friendIds) { if (GUILayout.Button(string.Format("Score for {0}", friend))){ AGSLeaderboardsClient.RequestScoreForPlayer(leaderboard.id, friend, leaderboardScoreScope); } if (scoreForPlayer.ContainsKey(leaderboard.id) && scoreForPlayer[leaderboard.id].ContainsKey(friend)){ AmazonGUIHelpers.CenteredLabel(scoreForPlayer[leaderboard.id][friend]); } } } GUILayout.EndVertical(); if(!showPlayerPercentileRequestButtons.ContainsKey(leaderboard.id)) { showPlayerPercentileRequestButtons.Add(leaderboard.id,false); } GUILayout.BeginVertical(GUI.skin.box); showPlayerPercentileRequestButtons[leaderboard.id] = AmazonGUIHelpers.FoldoutWithLabel(showPlayerPercentileRequestButtons[leaderboard.id],"Request percentiles for friend"); if (showPlayerPercentileRequestButtons[leaderboard.id]) { foreach (string friendId in friendIds) { if (GUILayout.Button(string.Format("Percentiles for {0}", friendId))){ AGSLeaderboardsClient.RequestPercentileRanksForPlayer(leaderboard.id, friendId, leaderboardScoreScope); } if (percentilesForPlayer.ContainsKey(leaderboard.id) && percentilesForPlayer[leaderboard.id].ContainsKey(friendId)) { foreach( string row in percentilesForPlayer [leaderboard.id] [friendId] ) { AmazonGUIHelpers.CenteredLabel( row ); } } } } GUILayout.EndVertical(); } } GUILayout.EndVertical(); }