private IEnumerator Internal_UpdateHighScores(int from, int count) { //Debug.Log ($"[{nameof (HighScoreManager)}]: Started high score update from server."); using (var webRequest = UnityWebRequest.Get( $"{HighScoreURL}/{PublicCode}/pipe/{from.ToString ()}/{count.ToString ()}")) { yield return(webRequest.SendWebRequest()); yield return(webRequest.downloadHandler); //Debug.Log (webRequest.downloadHandler.isDone.ToString()); if (webRequest.isNetworkError) { Debug.LogError( $"[{nameof (HighScore)}]: Failed to upload user's score! {webRequest.error}"); yield break; } //Debug.Log ($"WEB {webRequest.downloadHandler?.text ?? "NULL"}"); //Debug.Log ($"[{nameof (HighScoreManager)}]: High score update finished!"); ScoresCount = HighScoresUtility.FormatAndUpdateData(webRequest.downloadHandler.text, from, HighScores); HighScoresUpdated?.Invoke(from, count); } }
public static bool UploadScore(string username, string score, Action <bool> callback) { if (!HighScoresUtility.ValidateUserDataString(username) || !HighScoresUtility.ValidateUserDataString(score)) { Debug.LogError( $"[{nameof (HighScore)}]: Provided 'username' or 'score' was null of empty, or it contained invalid characters!"); callback.Invoke(false); return(false); } if (!HighScoresUtility.IsSamePlayer(CurrentPlayerLastData, username) && HighScoresUtility.CompareScores(CurrentPlayerLastData.Score, score) < 0) { CurrentPlayerLastData.Score = score; } else { CurrentPlayerLastData = new PlayerHighScoreData { Username = username, Score = score }; } Instance.StartCoroutine(Instance.Internal_PostHighScore(username, score, callback)); return(true); }
private IEnumerator Internal_FetchScoreForPlayer( string username, Action <PlayerHighScoreData> callback) { using (var webRequest = new UnityWebRequest( $"{HighScoreURL}{PrivateCode}/pipe-get/{username}")) { yield return(webRequest.SendWebRequest()); if (webRequest.isNetworkError) { Debug.LogError($"[{nameof (HighScore)}]: Failed to fetch user's score! {webRequest.error}"); callback?.Invoke(new PlayerHighScoreData()); yield break; } if (!HighScoresUtility.TryParsePlayerData(webRequest.downloadHandler.text, -1, out var playerData)) { yield break; } Debug.Log(webRequest.downloadHandler.text); callback?.Invoke(playerData); } }