Beispiel #1
0
 public static AGSRequestScoresResponse FromJSON(string json)
 {
     try {
         AGSRequestScoresResponse response = new AGSRequestScoresResponse();
         Hashtable hashtable = json.hashtableFromJson();
         response.error         = hashtable.ContainsKey("error") ? hashtable ["error"].ToString() : "";
         response.userData      = hashtable.ContainsKey("userData") ? int.Parse(hashtable ["userData"].ToString()) : 0;
         response.leaderboardId = hashtable.ContainsKey("leaderboardId") ? hashtable ["leaderboardId"].ToString() : "";
         if (hashtable.ContainsKey("leaderboard"))
         {
             response.leaderboard = AGSLeaderboard.fromHashtable(hashtable ["leaderboard"] as Hashtable);
         }
         else
         {
             response.leaderboard = AGSLeaderboard.GetBlankLeaderboard();
         }
         response.scores = new List <AGSScore> ();
         if (hashtable.Contains("scores"))
         {
             foreach (Hashtable scoreHashtable in hashtable["scores"] as ArrayList)
             {
                 response.scores.Add(AGSScore.fromHashtable(scoreHashtable));
             }
         }
         response.scope = (LeaderboardScope)Enum.Parse(typeof(LeaderboardScope), hashtable["scope"].ToString());
         return(response);
     } catch (Exception e) {
         AGSClient.LogGameCircleError(e.ToString());
         return(GetBlankResponseWithError(JSON_PARSE_ERROR));
     }
 }
 /// <summary>
 /// Callback method for when native failed to collect score information
 /// </summary>
 public static void RequestScoresFailed(string json)
 {
     if (RequestScoresCompleted != null)
     {
         RequestScoresCompleted(AGSRequestScoresResponse.FromJSON(json));
     }
 }
Beispiel #3
0
    private void OnRequestScoresCompleted(AGSRequestScoresResponse response)
    {
        // Put scores in leaderboard.
        AGSSocialLeaderboard leaderboard = leaderboardForRequest.ContainsKey(response.userData) ? leaderboardForRequest[response.userData] : null;

        if (null != leaderboard && !response.IsError())
        {
            leaderboard.scores = new IScore[response.scores.Count];
            for (int i = 0; i < response.scores.Count; i++)
            {
                leaderboard.scores[i] = new AGSSocialLeaderboardScore(response.scores[i], response.leaderboard);
            }
        }
        // Handle any callbacks
        Action <bool> callback = simpleCallbacks.ContainsKey(response.userData) ? simpleCallbacks[response.userData] : null;

        if (null != callback)
        {
            callback(!response.IsError());
        }
        Action <IScore[]> scoreCallback = loadScoresCallbacks.ContainsKey(response.userData) ? loadScoresCallbacks[response.userData] : null;

        if (null != scoreCallback)
        {
            IScore[] scores = new IScore[response.scores.Count];
            for (int i = 0; i < response.scores.Count; i++)
            {
                scores[i] = new AGSSocialLeaderboardScore(response.scores[i], response.leaderboard);
            }
            scoreCallback(scores);
        }
        // cleanup
        leaderboardForRequest.Remove(response.userData);
        simpleCallbacks.Remove(response.userData);
    }
    /// <summary>
    /// Request scores
    /// </summary>
    /// <remarks>
    /// RequestScoresCompleted will be called if event is registered.
    /// </remarks>
    /// <param name="leaderboardId">the id of the leaderboard for the score request.</param>
    /// <param name="scope">enum value of leaderboard scope</param>
    /// <param name="userData">
    /// ANDROID ONLY
    /// An optional code that will be returned in the response. Used to associate a function call to its response.
    /// A value of 0 is not recommended because 0 is the value returned when userData is not specified.
    /// </param>
    public static void RequestScores(string leaderboardId, LeaderboardScope scope, int userData = 0)
    {
#if UNITY_EDITOR && (UNITY_ANDROID || UNITY_IOS)
        // GameCircle only functions on device.
#elif UNITY_ANDROID
        JavaObject.Call("requestScores", leaderboardId, (int)scope, userData);
#else
        if (RequestScoresCompleted != null)
        {
            RequestScoresCompleted(AGSRequestScoresResponse.GetPlatformNotSupportedResponse(leaderboardId, scope, userData));
        }
#endif
    }
Beispiel #5
0
    public static AGSRequestScoresResponse GetBlankResponseWithError(string error,
                                                                     string leaderboardId   = "",
                                                                     LeaderboardScope scope = LeaderboardScope.GlobalAllTime,
                                                                     int userData           = 0)
    {
        AGSRequestScoresResponse response = new AGSRequestScoresResponse();

        response.error         = error;
        response.userData      = userData;
        response.leaderboardId = leaderboardId;
        response.scope         = scope;
        response.scores        = new List <AGSScore>();
        return(response);
    }
Beispiel #6
0
        private void OnRequestScoresCompleted(AGSRequestScoresResponse response)
        {
            var scoreCallback = loadScoresCallbacks.ContainsKey(response.userData)
                ? loadScoresCallbacks[response.userData]
                : null;

            if (scoreCallback != null)
            {
                var scores = new IScore[response.scores.Count];
                for (var i = 0; i < response.scores.Count; i++)
                {
                    scores[i] = new AGSSocialLeaderboardScore(response.scores[i], response.leaderboard);
                }

                scoreCallback(scores);
            }

            if (loadScoresCallbacks.ContainsKey(response.userData))
            {
                loadScoresCallbacks.Remove(response.userData);
            }
        }
Beispiel #7
0
    private void OnTopScoresLoaded(AGSRequestScoresResponse response)
    {
        AMN_ScoresLoadedResult result = null;

        if (response.IsError())
        {
            Debug.Log("[OnTopScoresLoaded] error " + response.error);
            result = new AMN_ScoresLoadedResult(response.leaderboardId, response.error);
        }
        else
        {
            Debug.Log("[OnTopScoresLoaded] " + response.scores.Count + " scores loaded");
            GC_Leaderboard lb = GetLeaderboard(response.leaderboardId);
            if (lb != null)
            {
                foreach (AGSScore score in response.scores)
                {
                    Debug.Log(string.Format("[OnTopScoresLoaded] AGSScore {0}|{1}|{2}|{3}|{4}",
                                            score.player.playerId,
                                            response.leaderboardId,
                                            score.rank,
                                            score.scoreValue,
                                            response.scope.GetGCTimeSpan().ToString()));

                    GC_Player player = new GC_Player(score.player);
                    AddPlayer(player);

                    GC_Score s = new GC_Score(score.player.playerId, response.leaderboardId, score.rank, score.scoreValue, response.scope.GetGCTimeSpan());
                    lb.UpdateScore(s);
                }
            }
            result = new AMN_ScoresLoadedResult(lb);
        }

        OnScoresLoaded(result);
    }
    private void OnRequestScoresCompleted( AGSRequestScoresResponse response )
    {
        List<string> formattedResult = new List<string>();

        if (response.IsError ()) {
            formattedResult.Add(string.Format ("Error with scores request: {0}", response.error));
        } else {
            formattedResult.Add(string.Format("Leaderboard: [{0}]", response.leaderboard.ToString()));
            formattedResult.Add (string.Format("Scope: {0}", response.scope));
            foreach (AGSScore score in response.scores){
                formattedResult.Add(string.Format(topScoreItemLabel, score.player.ToString(), score.scoreValue, score.scoreString, score.rank));
            }
        }

        leaderboardsScoresStatus[response.leaderboardId] = formattedResult;
    }
Beispiel #9
0
 private void OnRequestScoresCompleted(AGSRequestScoresResponse response)
 {
     // Put scores in leaderboard.
     AGSSocialLeaderboard leaderboard = leaderboardForRequest.ContainsKey (response.userData) ? leaderboardForRequest[response.userData] : null;
     if (null != leaderboard && !response.IsError()) {
         leaderboard.scores = new IScore[response.scores.Count];
         for (int i = 0; i < response.scores.Count; i++) {
             leaderboard.scores[i] = new AGSSocialLeaderboardScore(response.scores[i], response.leaderboard);
         }
     }
     // Handle any callbacks
     Action<bool> callback = simpleCallbacks.ContainsKey(response.userData) ? simpleCallbacks[response.userData] : null;
     if (null != callback) {
         callback(!response.IsError());
     }
     Action<IScore[]> scoreCallback = loadScoresCallbacks.ContainsKey (response.userData) ? loadScoresCallbacks[response.userData] : null;
     if (null != scoreCallback) {
         IScore[] scores = new IScore[response.scores.Count];
         for (int i = 0; i < response.scores.Count; i++) {
             scores[i] = new AGSSocialLeaderboardScore(response.scores[i], response.leaderboard);
         }
         scoreCallback(scores);
     }
     // cleanup
     leaderboardForRequest.Remove (response.userData);
     simpleCallbacks.Remove (response.userData);
 }