//private async Task UploadNewHighScoreAsync(float newScore) //{ // var newHighScoreInfo = new HighScoreInfo { Name = playerName, Time = newScore }; // try // { // Debug.Log("Uploading high score data to Azure..."); // await Leaderboard.HighScoreTable.InsertAsync(newHighScoreInfo); // Debug.Log("Finished uploading high score data."); // } // catch (System.Exception e) // { // Debug.Log("Error uploading high score data: " + e.Message); // } //} private IEnumerator UploadNewHighScore(float newScore) { bool completed = false; var newHighScoreInfo = new HighScoreInfo { Name = playerName, Time = newScore }; EasyTablesClient.Instance.Insert <HighScoreInfo>(newHighScoreInfo, serverResponse => { if (serverResponse.Status == CallBackResult.Success) { string result = "High score insert completed"; Debug.Log(result); } else { Debug.Log("High score insert failed... " + serverResponse.Exception.Message); } completed = true; } ); while (!completed) { yield return(null); } }
IEnumerator AddNewHighScore(string name, int score) { //https://forum.unity.com/threads/unitywebrequest-post-url-jsondata-sending-broken-json.414708/ WWWForm form = new WWWForm(); HighScoreInfo myHighScore = new HighScoreInfo(name, score); string json = JsonUtility.ToJson(myHighScore); byte[] bodyRaw = System.Text.Encoding.UTF8.GetBytes(json); Debug.Log(json); using (UnityWebRequest www = new UnityWebRequest("https://ocean-defenders.firebaseio.com/highscores.json", "POST")) { www.uploadHandler = (UploadHandler) new UploadHandlerRaw(bodyRaw); www.downloadHandler = (DownloadHandler) new DownloadHandlerBuffer(); www.SetRequestHeader("Content-Type", "application/json"); yield return(www.SendWebRequest()); if (www.isNetworkError || www.isHttpError) { Debug.Log(www.error); } else { Debug.Log("Form upload complete!"); } } }
private HighScoreInfo GetHighScores() { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(String.Format("http://infy-app.herokuapp.com/api/scores?key={0}", API_KEY)); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); StreamReader reader = new StreamReader(response.GetResponseStream()); string jsonResponse = reader.ReadToEnd(); HighScoreInfo highScores = JsonUtility.FromJson <HighScoreInfo>(jsonResponse); return(highScores); }
public int Load() { if (File.Exists(Application.persistentDataPath + "/HighScore.cas")) { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(Application.persistentDataPath + "/HighScore.cas", FileMode.Open); HighScoreInfo myLoadedInfo = (HighScoreInfo)bf.Deserialize(file); highScore = myLoadedInfo.highScore; } return(highScore); }
//Save the score info out to a binary file public void Save(int _highScore) { highScore = _highScore; BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(Application.persistentDataPath + "/HighScore.cas", FileMode.OpenOrCreate); HighScoreInfo myInfo = new HighScoreInfo(); //put what ever you're saving as myInfo.whatever myInfo.highScore = highScore; bf.Serialize(file, myInfo); file.Close(); }
public int Compare(object x, object y) { HighScoreInfo myX = (HighScoreInfo)x; HighScoreInfo myY = (HighScoreInfo)y; if (myX.Score > myY.Score) { return(0); } else { return(1); } }
IEnumerator GetHighScores() { myScores = null; myScores = new ArrayList(); size = 0; using (UnityWebRequest webRequest = UnityWebRequest.Get("https://ocean-defenders.firebaseio.com/highscores.json")) { // Request and wait for the desired page. yield return(webRequest.SendWebRequest()); if (webRequest.isNetworkError) { Debug.Log(": Error: " + webRequest.error); } else { string jsonString = webRequest.downloadHandler.text; var node = JSONNode.Parse(jsonString); if (node.Tag == JSONNodeType.Object) { foreach (KeyValuePair <string, JSONNode> kvp in (JSONObject)node) { //Debug.Log (string.Format ("{0}: {1} {2}",kvp.Key, kvp.Value["Name"].Value, kvp.Value["Score"].Value)); myScores.Add(new HighScoreInfo(kvp.Value["Name"].Value, System.Int32.Parse(kvp.Value["Score"].Value))); size++; } } } myScores.Sort(); if (size < 7) { lowestScore = (HighScoreInfo)myScores[myScores.Count - 1]; } else { lowestScore = (HighScoreInfo)myScores[6]; } StaticEndGame.LowestHighScore = lowestScore; // Stores the lowest high score in a static class LoadHighScores(); } }
private async Task UploadNewHighScoreAsync(float newScore) { var newHighScoreInfo = new HighScoreInfo { Name = playerName, Time = newScore }; try { Debug.Log("Uploading high score data to Azure..."); await Leaderboard.HighScoreTable.InsertAsync(newHighScoreInfo); Debug.Log("Finished uploading high score data."); } catch (System.Exception e) { Debug.Log("Error uploading high score data: " + e.Message); } }
public void DisplayHighScores() { string localName = PlayerPrefs.GetString("player_name"); int localHighScore = PlayerPrefs.GetInt("score", 0); if ((Application.internetReachability != NetworkReachability.NotReachable)) { List <IMultipartFormSection> formData = new List <IMultipartFormSection>(); UnityWebRequest www = UnityWebRequest.Post(String.Format("http://infy-app.herokuapp.com/api/score?name={0}&score={1}&key={2}", localName, localHighScore, API_KEY), formData); www.SendWebRequest(); } int i = 0; if (language == "en") { highScoreNameText.text = "NAME\n"; highScoreScoreText.text = "SCORE\n"; } else { highScoreNameText.text = "İSİM\n"; highScoreScoreText.text = "SKOR\n"; } highScores = GetHighScores(); foreach (Player p in highScores.message) { if (i > 9) { break; } highScoreNameText.text += (i + 1) + ") " + p.name + "\n"; highScoreScoreText.text += p.score + "\n"; ++i; } highScoreNameText.text += localName + "\n"; highScoreScoreText.text += localHighScore + "\n"; }
/* A method that compares high score info */ public int CompareTo(object other) { if (other == null) { return(-1); } HighScoreInfo myOther = other as HighScoreInfo; if (this.Score > myOther.Score) { return(-1); } else if (this.Score == myOther.Score) { return(0); } else { return(this.Score); } }
// Use this for initialization void Start() { Debug.Log("Start"); // Win / Lose GameObject status = GameObject.Find("Status"); // A,B,C,etc GameObject scoreGrade = GameObject.Find("ScoreGrade"); // Siberian Guru, etc GameObject scoreRankText = GameObject.Find("ScoreRankText"); // 1,2,3,4 GameObject placeRankText = GameObject.Find("PlaceRankText"); GameObject rationScore = GameObject.Find("RationScore"); GameObject goldScore = GameObject.Find("GoldScore"); GameObject repScore = GameObject.Find("RepScore"); GameObject enemyScore = GameObject.Find("EnemyScore"); GameObject squadScore = GameObject.Find("SquadScore"); GameObject attributeScore = GameObject.Find("AttributeScore"); GameObject totalScore = GameObject.Find("TotalScore"); GameInfo game = BaseSaver.getGame(); HighScoreInfo.EndInfo end = HighScoreInfo.makeEndInfo(game); status.GetComponent <Text> ().text = "Victory!"; scoreGrade.GetComponent <Text> ().text = HighScoreInfo.returnGrade(end.score); scoreRankText.GetComponent <Text> ().text = "Title: \n\n" + HighScoreInfo.returnRank(end.score); placeRankText.GetComponent <Text> ().text = "Map Rank: 1st"; rationScore.GetComponent <Text> ().text = "Rations: " + end.getRationsScore() + " (" + end.rations.ToString() + ")"; goldScore.GetComponent <Text> ().text = "Gold: " + end.getGoldScore() + " (" + end.gold.ToString() + ")"; repScore.GetComponent <Text> ().text = "Reputation: " + end.getRepScore() + " (" + end.rep.ToString() + ")"; enemyScore.GetComponent <Text> ().text = "Enemies Killed: " + end.enemies.ToString(); squadScore.GetComponent <Text> ().text = "Squad Score: " + end.squad.ToString(); attributeScore.GetComponent <Text> ().text = "Attributes: " + end.attributes.ToString(); totalScore.GetComponent <Text> ().text = "Total: " + end.score.ToString(); }