public void DrawTables(bool var = true, int nb = 0) { rankingContainer = GameObject.Find("RankingContainer").transform; rankingTemplate = rankingContainer.Find("RankingTemplate"); rankingTemplate.gameObject.SetActive(false); string jsonStr = PlayerPrefs.GetString("rankingTable"); Rankings rankings = JsonUtility.FromJson <Rankings>(jsonStr); rankings.rankingEntryList = SortRankingScore(rankings.rankingEntryList, ascending); if (var == false && nb != 0) { int dataToDelete = rankings.rankingEntryList.Count - nb; if (dataToDelete > 0) { rankings.rankingEntryList.RemoveRange(nb, dataToDelete); } } rankingEntryTransformList = new List <Transform>(); foreach (RankingEntry rankingEntry in rankings.rankingEntryList) { CreateRankingEntryTransform(rankingEntry, rankingContainer, rankingEntryTransformList, ascending, precision); } }
IEnumerator SimplePostRequestDeleteUserID(string userID) { string jsonStr = PlayerPrefs.GetString("rankingTable"); Rankings rankings = JsonUtility.FromJson <Rankings>(jsonStr); string userIDToCheck = "\"userID\":\"" + userID + "\""; if (!jsonStr.ToString().Contains(userIDToCheck)) { message.GetComponent <Text>().color = Color.red; message.GetComponent <Text>().fontSize = 44; message.text = "userID " + userID + " not found in Ranks"; } else { var request = new UnityWebRequest(deleteURL + userID, "DELETE"); request.downloadHandler = (DownloadHandler) new DownloadHandlerBuffer(); request.SetRequestHeader("Content-Type", "application/json"); yield return(request.SendWebRequest()); //Debug.Log("Status Code: " + request.responseCode); if (request.isNetworkError) { //Debug.LogError("isNetworkError " + request.error); message.GetComponent <Text>().color = Color.red; message.GetComponent <Text>().fontSize = 25; message.text = request.error; } if (request.isHttpError) { //Debug.LogError("isHttpError " + request.error); message.GetComponent <Text>().color = Color.red; message.GetComponent <Text>().fontSize = 25; message.text = request.error; } else { message.GetComponent <Text>().color = Color.green; message.GetComponent <Text>().fontSize = 44; message.text = "UserID deleted !"; userIDToDelete.GetComponent <InputField>().text = ""; } } }
IEnumerator SimplePostRequestGetScore(string userID) { string jsonStr = PlayerPrefs.GetString("rankingTable"); Rankings rankings = JsonUtility.FromJson <Rankings>(jsonStr); string userIDToCheck = "\"userID\":\"" + userID + "\""; if (!jsonStr.ToString().Contains(userIDToCheck)) { message.GetComponent <Text>().color = Color.red; message.GetComponent <Text>().fontSize = 44; message.text = "userID " + userID + " not found in Ranks"; } else { var request = new UnityWebRequest(getUserIDURL + userID, "Get"); request.downloadHandler = (DownloadHandler) new DownloadHandlerBuffer(); request.SetRequestHeader("Content-Type", "application/json"); yield return(request.SendWebRequest()); //Debug.Log("Status Code: " + request.responseCode); if (request.isNetworkError) { //Debug.LogError("isNetworkError " + request.error); message.GetComponent <Text>().color = Color.red; message.GetComponent <Text>().fontSize = 25; message.text = request.error; } if (request.isHttpError) { //Debug.LogError("isHttpError " + request.error); message.GetComponent <Text>().color = Color.red; message.GetComponent <Text>().fontSize = 25; message.text = request.error; } else { message.GetComponent <Text>().color = Color.green; message.GetComponent <Text>().fontSize = 44; string json = request.downloadHandler.text; RankingEntry rank = JsonConvert.DeserializeObject <RankingEntry>(json); float scoreReceived = rank.score; if (UnityEditor.EditorApplication.isPlaying) { precision = GetInstance().GetPrecision(); } else { precision = 4; } if (precision == 0) { scoreReceived = Mathf.Round(scoreReceived); } else { scoreReceived = Mathf.Round(scoreReceived * Mathf.Pow(10f, precision)) / Mathf.Pow(10f, precision); } message.text = "Score: " + scoreReceived.ToString(); userIDToGetScore.GetComponent <InputField>().text = ""; } } }