public playerJson getDBData(string name){ // ini web var httpWebRequest = (HttpWebRequest)WebRequest.Create ("http://drproject.twi.tudelft.nl:8082/getStats"); httpWebRequest.ContentType = "application/json"; httpWebRequest.Method = "POST"; // write away to the node.js var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()); string json = "{\"Name\":\"" + name + "\"}"; streamWriter.Write(json); streamWriter.Flush(); streamWriter.Close(); // ini response from the server var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse (); var streamReader = new StreamReader (httpResponse.GetResponseStream ()); string userStats = streamReader.ReadToEnd(); Debug.Log ("Userstats: " + userStats); // ini JSON parser with the help of the JSONobject from downloaded from unity asset store. var N = JSON.Parse(userStats); string playerName = N [0] ["Username"]; string kills = N [0] ["AmountKills"]; string deaths = N [0] ["AmountDeaths"]; string won = N [0] ["AmountWon"]; string lost = N [0] ["AmountLost"]; // make playerJson and return playerJson playerStats = new playerJson (playerName, int.Parse(kills), int.Parse(deaths), int.Parse(won), int.Parse(lost)); resetData (); return playerStats; }
public void sentDBData(string name){ // retrieve data when calles from the playerCustomProperties playerName = name; kills = (int)PhotonNetwork.player.customProperties ["Kills"]; deaths = (int)PhotonNetwork.player.customProperties ["Deaths"]; won = (int)PhotonNetwork.player.customProperties ["Won"]; lost = (int)PhotonNetwork.player.customProperties ["Lost"]; // initialisation playerJson DBJSON = new playerJson(playerName, kills, deaths, won, lost); string json = DBJSON.toJson(); Debug.Log ("PostStatsData: " + json); // ini web var httpWebRequest = (HttpWebRequest)WebRequest.Create ("http://drproject.twi.tudelft.nl:8082/postStats"); httpWebRequest.ContentType = "application/json"; httpWebRequest.Method = "POST"; // write away to the node.js var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()); streamWriter.Write(json); streamWriter.Flush(); streamWriter.Close(); resetData (); }
void Start () { // set the username to your username. playerName.text = PlayerPrefs.GetString ("Name"); stats = dc.getDBData (PlayerPrefs.GetString ("Name")); int tempWon = stats.getWon(); Debug.Log ("tempWon= " + tempWon); int tempLost = stats.getLost(); Debug.Log ("tempLost= " + tempLost); int tempDeaths = stats.getDeaths(); Debug.Log ("tempDeaths= " + tempDeaths); int tempKills = stats.getKills(); Debug.Log ("tempKills= " + tempKills); float tempKD; if (stats.getDeaths() == 0) { tempKD = Mathf.Infinity; } else if(stats.getKills() == 0){ tempKD = 0; } else{ tempKD = stats.getKills() / stats.getKills(); } // update the values of the won.text = tempWon.ToString (); lost.text = tempLost.ToString (); deaths.text = tempDeaths.ToString (); kills.text = tempKills.ToString (); kdRatio.text = tempKD.ToString (); }
public void sentDBData(){ // initialisation playerJson DBJSON = new playerJson (playerName, kills, deaths, won, lost); String json = DBObject.toJson(); // ini web var httpWebRequest = (HttpWebRequest)WebRequest.Create ("https://drproject.twi.tudelft.nl:8082/postStats"); httpWebRequest.ContentType = "text/json"; httpWebRequest.Method = "POST"; // write away to the node.js var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream(); streamWriter.Write(json); streamWriter.Flush(); streamWriter.Close(); }
private void Start() { enemiesControllerScript = FindObjectOfType <enemiesController>(); am = FindObjectOfType <AudioManager>(); controller = GetComponent <CharacterController>(); Cursor.lockState = CursorLockMode.Locked; animator = GetComponent <Animator>(); playerJson t = JsonUtility.FromJson <playerJson>(new JSONDemo("demo.json").getJson()); transform.position = t.position; Quaternion thetas = Quaternion.Euler(t.rotation.x, t.rotation.y, t.rotation.z); transform.rotation = thetas; transform.localScale = t.scale; }
private void Start() { moveSpeed = 0; walkSpeed = 2; groundCheckDistance = 0.25f; groundMask = LayerMask.GetMask("level1Ground"); gravity = -9.81f; mouseSensetivity = 100; enemiesControllerScript = FindObjectOfType <enemiesController>(); am = FindObjectOfType <AudioManager>(); controller = GetComponent <CharacterController>(); Cursor.lockState = CursorLockMode.Locked; animator = GetComponent <Animator>(); playerJson t = JsonUtility.FromJson <playerJson>(new JSONDemo("demo.json").getJson()); //transform.position = t.position; Quaternion thetas = Quaternion.Euler(t.rotation.x, t.rotation.y, t.rotation.z); //transform.rotation = thetas; //transform.localScale = t.scale; }