public static ViaLactea PostViaLactea(ViaLactea viaLactea) { //HttpClient client = new HttpClient(); //string result = await client.PostAsync(apiCalls.url+"api/vialactea",); //Debug.Log(result); var httpWebRequest = (HttpWebRequest)WebRequest.Create(ApiCalls.url + "/api/vialactea"); httpWebRequest.ContentType = "application/json"; httpWebRequest.Method = "POST"; using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { string json = JsonUtility.ToJson(viaLactea); json = json.Replace(",\"teletransportador\":{\"planetaFK\":0},\"deposito\":{\"planetaFK\":0}", ""); json = json.Replace(",\"ViaLacteaFK\":0", ""); streamWriter.Write(json); streamWriter.Flush(); streamWriter.Close(); } var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var result = streamReader.ReadToEnd(); viaLactea = JsonUtility.FromJson <ViaLactea>(result); } return(viaLactea); }
public void setViaLactea(ViaLactea via) { viaLactea = via; }
public void nuevaViaLactea() { //TMP_InputField totalNebulosas=canvasMenuCrear.transform.Find("Canvas/Nebulosas/Total").GetComponent<TMP_InputField>(); //TMP_InputField totalSistemasPlanetarios=canvasMenuCrear.transform.Find("Canvas/SistemasPlanetarios/Total").GetComponent<TMP_InputField>(); //TMP_InputField totalSistemasPlanetas= canvasMenuCrear.transform.Find("Canvas/Planetas/Total").GetComponent<TMP_InputField>(); Slider maxNebulosas = canvasMenuCrear.transform.Find("Canvas/Nebulosas/Slider").GetComponent <Slider>(); Slider maxSistemasPlanetarios = canvasMenuCrear.transform.Find("Canvas/SistemasPlanetarios/Slider").GetComponent <Slider>(); Slider maxPlanetas = canvasMenuCrear.transform.Find("Canvas/Planetas/Slider").GetComponent <Slider>(); Toggle random = canvasMenuCrear.transform.Find("Canvas/Info/Toggle").GetComponent <Toggle>(); TMP_InputField nombreViaLactea = canvasMenuCrear.transform.Find("Canvas/Info/Nombre").GetComponent <TMP_InputField>(); ViaLactea viaLactea = new ViaLactea(); viaLactea.nombre = nombreViaLactea.text; viaLactea.Nebulosas = new List <Nebulosa>(); if (random.isOn) { int nebulosas = Random.Range((int)maxNebulosas.minValue, (int)maxNebulosas.value); for (int i = 0; i < nebulosas; i++) { Nebulosa nebulosaTemp = crearNebulosa(); viaLactea.Nebulosas.Add(nebulosaTemp); int sistemas = Random.Range((int)maxSistemasPlanetarios.minValue, (int)maxSistemasPlanetarios.value); for (int j = 0; j < sistemas; j++) { SistemaPlanetario sistemaTemp = crearsistemaPlanetario(); viaLactea.Nebulosas[i].sistemasPlanetarios.Add(sistemaTemp); for (int k = 0; k < (int)maxPlanetas.value; k++) { Planeta planeta = crearPlaneta(); viaLactea.Nebulosas[i].sistemasPlanetarios[j].nodos.Add(planeta); } } } } else { for (int i = 0; i < (int)maxNebulosas.value; i++) { Nebulosa nebulosa = crearNebulosa(); viaLactea.Nebulosas.Add(nebulosa); for (int j = 0; j < (int)maxSistemasPlanetarios.value; j++) { SistemaPlanetario sistema = crearsistemaPlanetario(); viaLactea.Nebulosas[i].sistemasPlanetarios.Add(sistema); for (int k = 0; k < (int)maxPlanetas.value; k++) { Planeta planeta = crearPlaneta(); viaLactea.Nebulosas[i].sistemasPlanetarios[j].nodos.Add(planeta); } } } } viaLactea = ViaLacteaService.PostViaLactea(viaLactea); CargarViaLactea cargar = GameObject.FindGameObjectWithTag("ViaLactea").GetComponent <CargarViaLactea>(); cargar.setViaLactea(viaLactea); StartCoroutine(CameraAnimations.animacionSalirMenuCrear("Editor")); StartCoroutine(irAEditor()); }