private void OnScoreSubmited(FBResult result) { FB_APIResult r; if (result.Error != null) { r = new FB_APIResult(false, result.Error); r.Unity_FB_Result = result; dispatch(FacebookEvents.SUBMIT_SCORE_REQUEST_COMPLETE, r); OnSubmitScoreRequestCompleteAction(r); return; } if (result.Text.Equals("true")) { r = new FB_APIResult(true, result.Text); r.Unity_FB_Result = result; FBScore score = new FBScore(); score.AppId = FB.AppId; score.UserId = FB.UserId; score.value = lastSubmitedScore; if (_appScores.ContainsKey(FB.UserId)) { _appScores[FB.UserId].value = lastSubmitedScore; } else { _appScores.Add(score.UserId, score); } if (_userScores.ContainsKey(FB.AppId)) { _userScores[FB.AppId].value = lastSubmitedScore; } else { _userScores.Add(FB.AppId, score); } dispatch(FacebookEvents.SUBMIT_SCORE_REQUEST_COMPLETE, r); OnSubmitScoreRequestCompleteAction(r); } else { r = new FB_APIResult(false, result.Error); r.Unity_FB_Result = result; dispatch(FacebookEvents.SUBMIT_SCORE_REQUEST_COMPLETE, r); OnSubmitScoreRequestCompleteAction(r); } }
private void OnScoreDeleted(FBResult result) { FB_APIResult r; if (result.Error != null) { r = new FB_APIResult(false, result.Error); r.Unity_FB_Result = result; OnDeleteScoresRequestCompleteAction(r); return; } if (result.Text.Equals("true")) { r = new FB_APIResult(true, result.Text); r.Unity_FB_Result = result; FBScore score = new FBScore(); score.AppId = FB.AppId; score.UserId = FB.UserId; score.value = 0; if (_appScores.ContainsKey(FB.UserId)) { _appScores[FB.UserId].value = 0; } else { _appScores.Add(score.UserId, score); } if (_userScores.ContainsKey(FB.AppId)) { _userScores[FB.AppId].value = 0; } else { _userScores.Add(FB.AppId, score); } OnDeleteScoresRequestCompleteAction(r); } else { r = new FB_APIResult(false, result.Error); r.Unity_FB_Result = result; OnDeleteScoresRequestCompleteAction(r); } }
//-------------------------------------- // PUBLIC METHODS //-------------------------------------- public FBScore GetCurrentPlayerScoreByAppId(string appId) { if (_userScores.ContainsKey(appId)) { return(_userScores[appId]); } else { FBScore score = new FBScore(); score.UserId = FB.UserId; score.AppId = appId; score.value = 0; return(score); } }
private void OnLoaPlayrScoresComplete(FBResult result) { FB_APIResult r; if (result.Error != null) { r = new FB_APIResult(false, result.Error); r.Unity_FB_Result = result; dispatch(FacebookEvents.PLAYER_SCORES_REQUEST_COMPLETE, r); OnPlayerScoresRequestCompleteAction(r); return; } Dictionary <string, object> JSON = ANMiniJSON.Json.Deserialize(result.Text) as Dictionary <string, object>; List <object> data = JSON["data"] as List <object>; foreach (object row in data) { FBScore score = new FBScore(); Dictionary <string, object> dataRow = row as Dictionary <string, object>; Dictionary <string, object> userInfo = dataRow["user"] as Dictionary <string, object>; score.UserId = System.Convert.ToString(userInfo["id"]); score.UserName = System.Convert.ToString(userInfo["name"]); score.value = System.Convert.ToInt32(dataRow["score"]); Dictionary <string, object> AppInfo = dataRow["application"] as Dictionary <string, object>; score.AppId = System.Convert.ToString(AppInfo["id"]); score.AppName = System.Convert.ToString(AppInfo["name"]); AddToUserScores(score); } r = new FB_APIResult(true, result.Text); r.Unity_FB_Result = result; dispatch(FacebookEvents.PLAYER_SCORES_REQUEST_COMPLETE, r); OnPlayerScoresRequestCompleteAction(r); }
private void AddToAppScores(FBScore score) { if (_appScores.ContainsKey(score.UserId)) { _appScores[score.UserId] = score; } else { _appScores.Add(score.UserId, score); } if (_userScores.ContainsKey(score.AppId)) { _userScores[score.AppId] = score; } else { _userScores.Add(score.AppId, score); } }