private void AddScore(ScoreItem newScore) { if (Scores.Count < NUM_SCORES) { Scores.Add(newScore); } else if (newScore.score >= Scores[NUM_SCORES - 1].score) { Scores[NUM_SCORES - 1] = newScore; } else { return; } Scores = Scores.OrderByDescending(x => x.score).ToList(); }
private IEnumerator PostScoreRoutine(ScoreItem newScore) { string uri = "https://qbk1zvwag3.execute-api.ap-southeast-2.amazonaws.com/v1"; string resource = "scores"; string json = JsonUtility.ToJson(newScore); var req = new UnityWebRequest(uri + "/" + resource, "POST"); byte[] jsonBytes = new System.Text.UTF8Encoding().GetBytes(json); req.uploadHandler = new UploadHandlerRaw(jsonBytes); req.downloadHandler = new DownloadHandlerBuffer(); req.SetRequestHeader("Content-Type", "application/json"); yield return(req.SendWebRequest()); if (req.isHttpError || req.isNetworkError) { Debug.Log("error while saving: " + req.error); yield break; } Debug.Log("new score saved to mongo: " + newScore.name + " : " + newScore.score); }