/// <summary> /// Este metodo se encarga de cargar todo el contenido de la nebulosa en la escena: /// -Sistemas planetarios, planetas, teletransportadores,estaciones de combustible. /// </summary> public void cargar(bool isSimulacion) { List <GameObject> SistemaTemporal = new List <GameObject>(); foreach (var item in nebulosa.sistemasPlanetarios) { Vector3 posicion = new Vector3(item.x, item.y, item.z); GameObject sistemaAux = Instantiate(sistemaPlanetarioPrefab, posicion, Quaternion.identity); SistemaplanetarioPrefab spp = sistemaAux.GetComponent <SistemaplanetarioPrefab>(); spp.setSistema(item); spp.isSimulacion = isSimulacion; SistemaTemporal.Add(sistemaAux); GameObject sistema = spp.transform.Find("sistema").gameObject; List <GameObject> nodosTemp = new List <GameObject>(); foreach (var planeta in item.nodos) { Vector3 pos = new Vector3(planeta.x, planeta.y, planeta.z); GameObject aux = Instantiate(planetas[int.Parse(planeta.idModelo)], sistema.transform); aux.GetComponent <PlanetaPrebab>().setPlaneta(planeta); aux.transform.localPosition = pos; if (planeta.teletransportador.planetaFK != 0) { item.tieneTeletransportador = true; Vector3 posTele = aux.transform.position + new Vector3(4, 0, 0); GameObject tele = Instantiate(teletrasnportadorPrefab, aux.transform); tele.transform.position = posTele; tele.transform.localScale = new Vector3(2, 2, 2); TeletransportadorPrefab tp = tele.GetComponent <TeletransportadorPrefab>(); tp.teletransportador = planeta.teletransportador; tp.planeta = aux; } if (planeta.deposito.planetaFK != 0) { item.tieneDeposito = true; Vector3 posTele = aux.transform.position + new Vector3(-4, 0, 0); GameObject deposito = Instantiate(depositoPrefab, aux.transform); deposito.transform.position = posTele; deposito.transform.localScale = new Vector3(2, 2, 2); DepositoPrefab dp = deposito.GetComponent <DepositoPrefab>(); dp.deposito = planeta.deposito; dp.planeta = aux; } nodosTemp.Add(aux); } cargarAristasNodos(item.grafo, nodosTemp); } cargarAristasSistema(nebulosa.grafo, SistemaTemporal); }
public void cargarAristasSistema(List <AristaSistema> grafo, List <GameObject> sistemas) { foreach (var item in grafo) { GameObject lineaP = Instantiate(lineaSistemaPrefab); AristaPrefab arista = lineaP.GetComponent <AristaPrefab>(); foreach (var sistema in sistemas) { SistemaplanetarioPrefab sp = sistema.GetComponent <SistemaplanetarioPrefab>(); if (sp.sistemaPlanetario.id == item.origenFK) { arista.origen = sistema; item.origen = sp.sistemaPlanetario; } if (sp.sistemaPlanetario.id == item.destinoFK) { arista.destino = sistema; item.destino = sp.sistemaPlanetario; } } arista.terminado = true; } }
/// <summary> /// Crea la nebulosa en la escena y envia la información al servidor. /// </summary> /// <returns></returns IEnumerator crearSistemaCOR() { GameObject newSistema = Instantiate(prefabSistema); while (!Input.GetMouseButtonDown(0)) { Vector3 posMouse; Vector3 pos = Input.mousePosition; Ray ray = Camera.main.ScreenPointToRay(pos); Plane xy = new Plane(Vector3.up, new Vector3(0, 0, 0)); float distance; xy.Raycast(ray, out distance); posMouse = ray.GetPoint(distance); newSistema.transform.position = posMouse; yield return(new WaitForSeconds(0.01f)); } SistemaplanetarioPrefab sistemaP = newSistema.GetComponent <SistemaplanetarioPrefab>(); sistemaP.actualizarDatos(); sistemaP.sistemaPlanetario = SistemaPlanetarioService.PostSistema(sistemaP.sistemaPlanetario); sistemaP.refrescarInfo(); }