public static Vector3 Redondear(Vector3 posicion, Construccion edificio) { if (edificio != null) { float posicionX = posicion.x; float posicionZ = posicion.z; if (edificio.dimensiones.x > 1 && edificio.dimensiones.y > 1) { posicionX = posicionX + (edificio.dimensiones.x / 2); posicionZ = posicionZ + (edificio.dimensiones.y / 2); } if (edificio.dimensiones.x == 1 && edificio.dimensiones.y > 1) { posicionZ = posicionZ + (edificio.dimensiones.y / 2); } if (edificio.dimensiones.x > 1 && edificio.dimensiones.y == 1) { posicionX = posicionX + (edificio.dimensiones.x / 2); } edificio.posicionX = (int)posicionX; edificio.posicionZ = (int)posicionZ; return(new Vector3(Mathf.Round(posicionX), .5f, Mathf.Round(posicionZ))); } else { return(new Vector3(Mathf.Round(posicion.x), .5f, Mathf.Round(posicion.z))); } }
private void OnTriggerStay(Collider colision) { Construccion carretera = colision.gameObject.GetComponent <Construccion>(); if (carretera != null) { if (carretera.categoria == 1) { enCarretera = true; } } luzRojaSemaforo = colision.gameObject.GetComponent <Light>(); if (luzRojaSemaforo != null) { if (luzRojaSemaforo.intensity == 0f) { semaforoRojo = false; } else { semaforoRojo = true; } } }
public static int RotacionGuardadoZ(int z, Construccion edificio) { if (edificio.dimensiones.x == 2 && edificio.dimensiones.y == 1) { if (edificio.rotacionColocacion == -270 || edificio.rotacionColocacion == -90) { z = z + 1; } } else if (edificio.dimensiones.x == 2 && edificio.dimensiones.y == 2) { z = z + 1; } else if (edificio.dimensiones.x == 4 && edificio.dimensiones.y == 3) { if (edificio.rotacionColocacion == -180 || edificio.rotacionColocacion == 0) { z = z + 1; } else { z = z + 2; } } return(z); }
public static int RotacionGuardadoX(int x, Construccion edificio) { if (edificio.dimensiones.x == 2 && edificio.dimensiones.y == 1) { if (edificio.rotacionColocacion == -180 || edificio.rotacionColocacion == 0) { x = x + 1; } } else if (edificio.dimensiones.x == 2 && edificio.dimensiones.y == 2) { x = x + 1; } else if (edificio.dimensiones.x == 4 && edificio.dimensiones.y == 3) { if (edificio.rotacionColocacion == -180 || edificio.rotacionColocacion == 0) { x = x + 2; } else { x = x + 1; } } return(x); }
void Start() { scriptInv = GameObject.FindGameObjectWithTag("Player").GetComponent <Inventario>(); scriptCons = GameObject.FindGameObjectWithTag("Player").GetComponent <Construccion>(); sel = GameObject.FindGameObjectWithTag("Selecion"); obj = GameObject.FindGameObjectWithTag("Objetos"); controlador = GameObject.FindGameObjectWithTag("Controlador").GetComponent <Controlador>(); }
public void ConstruirSeleccionarEdificio(int edificio) { demolerActivar = false; DemolerCambiarColor(); construirActivar = true; ConstruirOcultarPanelEdificios(); edificioSeleccionado = edificios[edificio]; ayuda.AbrirAyuda6o7(edificioSeleccionado.categoria); sonidoBoton.Play(); }
public void ConstruirSeleccionarEdificio(int edificio) { sonido.RatonClick(); demolerActivar = false; construirActivar = true; vistaPrevia.QuitarTodosEdificios(); abajoIzqInterfaz.CerrarMenu(); edificioSeleccionado = edificios[edificio]; ayudaInterfaz.AbrirAyuda6o7(edificioSeleccionado.categoria); }
private void OnCollisionEnter(Collision tanque) { GameObject colision = tanque.gameObject; Rigidbody colisionCuerpo = colision.GetComponent <Rigidbody>(); if (tanque.gameObject.CompareTag("Jugador")) { Motor other = (Motor)tanque.gameObject.GetComponent(typeof(Motor)); other.Destruir(); } if (tanque.gameObject.CompareTag("Construccion")) { Construccion other = (Construccion)cons.gameObject.GetComponent(typeof(Construccion)); } }
public void CargarEdificios(Guardado partida) { if (partida != null) { velocidad.contadorDias = partida.dia; velocidad.arranqueDia = partida.hora; velocidad.ActualizarLuces(); int i = 0; while (i < partida.edificiosID.Count) { Construccion edificioGuardado = edificios[partida.edificiosID[i]]; if (edificioGuardado != null) { edificioGuardado.rotacionColocacion = partida.edificiosRotacion[i]; Vector3 posicion = new Vector3(partida.edificiosX[i], 0.5f, partida.edificiosZ[i]); posicion = Posicion.EdificioAjusteCarga(edificioGuardado, posicion); construir.AñadirConstruccion(edificioGuardado, posicion, velocidad.encender); } i++; } //camara.transform.position = new Vector3(guardado.camaraPosicionX, guardado.camaraPosicionY, guardado.camaraPosicionZ); //camara.transform.Rotate(new Vector3(guardado.camaraRotacionX, guardado.camaraRotacionY, guardado.camaraRotacionZ)); ciudad.Dinero = partida.dinero; ciudad.ModoFacil = partida.modoFacil; ciudad.Banco = partida.banco; ciudad.BancoCredito1 = partida.bancoCredito1; ciudad.BancoCredito2 = partida.bancoCredito2; ciudad.BancoCredito3 = partida.bancoCredito3; ciudad.BancoContadorTiempoCredito1 = partida.bancoContadorTiempoCredito1; ciudad.BancoContadorTiempoCredito2 = partida.bancoContadorTiempoCredito2; ciudad.BancoContadorTiempoCredito3 = partida.bancoContadorTiempoCredito3; ciudad.PoblacionActual = partida.poblacionActual; ciudad.PoblacionTope = partida.poblacionTope; ciudad.TrabajosActual = partida.trabajosActual; ciudad.TrabajosTope = partida.trabajosTope; ciudad.Comida = partida.comida; } }
public void AñadirConstruccion(Construccion edificio, Vector3 posicion, bool encender) { edificio.GetComponent <Renderer>().receiveShadows = true; edificio.GetComponent <Renderer>().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.On; posicion = Posicion.Edificio(edificio, posicion); ComprobarLucesEdificio(encender, edificio); Construccion edificioConstruido = Instantiate(edificio, posicion, Quaternion.identity); edificioConstruido.transform.Rotate(Vector3.up, edificio.rotacionAdicional + edificio.rotacionColocacion, Space.World); edificioConstruido.posicionX = (int)posicion.x; edificioConstruido.posicionZ = (int)posicion.z; edificioConstruido.id2 = contadorIdsConstrucciones; contadorIdsConstrucciones += 1; edificios[(int)posicion.x, (int)posicion.z] = edificioConstruido; colisiones.Añadir(edificios, edificio, posicion); }
void EdificioVistaPreviaDemoler() { Vector3 raton = Posicion.Raton(); if (raton != Vector3.zero) { Vector3 gridPosicion = Posicion.Redondear(raton, edificioSeleccionado); if (Posicion.Limites(gridPosicion, 100) == true) { edificioSeleccionado = construir.ComprobarPosicion(null, gridPosicion); if (edificioSeleccionado != null) { construir.DemolerCambiarColores(edificioSeleccionado.id2); } } } }
public void GenerarArbol(Construccion arbol, Vector3 posicion, Construir construir) { bool añadir = true; if (ComprobarEdificable(arbol, posicion) == false) { añadir = false; } if (construir.ComprobarPosicion(arbol, posicion) != null) { añadir = false; } if (añadir == true) { construir.AñadirConstruccion(arbol, posicion, false); } }
public void AñadirConstruccion(Construccion edificio, Vector3 posicion) { if (edificio.gameObject.GetComponentsInChildren <Light>().Length > 0) { foreach (Light luz in edificio.gameObject.GetComponentsInChildren <Light>()) { luz.intensity = 0; } } edificio.GetComponent <Renderer>().receiveShadows = false; edificio.GetComponent <Renderer>().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; posicion = Posicion.Edificio(edificio, posicion); Construccion edificioVistaPrevia = Instantiate(edificio, posicion, Quaternion.identity); edificioVistaPrevia.transform.Rotate(Vector3.up, edificio.rotacionAdicional + edificio.rotacionColocacion, Space.World); edificiosPrevio[(int)posicion.x, (int)posicion.z] = edificioVistaPrevia; //colisiones.Añadir(edificiosPrevio, edificio, posicion); //--------------------------------- Material[] materiales = edificiosPrevio[(int)posicion.x, (int)posicion.z].gameObject.GetComponent <MeshRenderer>().materials; materiales[0].SetFloat("_Mode", 3); materiales[0].SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One); materiales[0].SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha); materiales[0].SetInt("_ZWrite", 0); materiales[0].DisableKeyword("_ALPHATEST_ON"); materiales[0].DisableKeyword("_ALPHABLEND_ON"); materiales[0].EnableKeyword("_ALPHAPREMULTIPLY_ON"); materiales[0].renderQueue = 3000; materiales[0].color = new Color(1.0f, 1.0f, 1.0f, 0.5f); materiales[0].DisableKeyword("_EMISSION"); materiales[0].globalIlluminationFlags = MaterialGlobalIlluminationFlags.EmissiveIsBlack; edificiosPrevio[(int)posicion.x, (int)posicion.z].gameObject.GetComponent <MeshRenderer>().materials = materiales; }
private void OnTriggerExit(Collider other) { Construccion carretera = other.gameObject.GetComponent <Construccion>(); if (carretera != null) { if (carretera.categoria == 1) { enCarretera = false; } } if (luzRojaSemaforo != null) { luzRojaSemaforo = null; } if (otroVehiculo != null) { otroVehiculo = null; } }
public static Construccion[,] QuitarEdificios(Construccion[,] edificios, Construccion edificio, Vector3 posicion) { if (edificio != null) { int id2 = edificio.id2; foreach (Construccion subedificio in edificios) { if (subedificio != null) { if (id2 == subedificio.id2) { int x = subedificio.posicionX; int z = subedificio.posicionZ; Object.DestroyImmediate(subedificio.gameObject, true); edificios[x, z] = null; } } } } return(edificios); }
void Update() { if (canvas.gameObject.GetComponent <CanvasGroup>().alpha == 1) { if (Input.GetKeyDown(teclaMenu)) { abajoIzqInterfaz.AbrirMenu(); } if (Input.GetMouseButtonDown(1)) { if (construirActivar == true) { construirActivar = false; vistaPrevia.QuitarTodosEdificios(); construirInterfaz.RatonSaleBotonEdificios(); edificioSeleccionado = null; panelCoste.gameObject.GetComponent <CanvasGroup>().alpha = 0; } if (demolerActivar == true) { demolerActivar = false; construir.DemolerCambiarColores(0); } } if (edificioSeleccionado != null) { if (construirActivar == true) { if (Input.GetKeyDown(teclaRotacionEdificioDerecha)) { int rotacion = edificioSeleccionado.rotacionColocacion + 90; if (rotacion > 0) { rotacion = -270; } edificioSeleccionado.rotacionColocacion = rotacion; } if (Input.GetKeyDown(teclaRotacionEdificioIzquierda)) { int rotacion = edificioSeleccionado.rotacionColocacion - 90; if (rotacion < -270) { rotacion = 0; } edificioSeleccionado.rotacionColocacion = rotacion; } if (Input.GetKey(teclaArrastrarConstruccion)) { if (edificioSeleccionado.id == 6) { EdificioVistaPrevia(true, 1); } else if (edificioSeleccionado.id == 12) { EdificioVistaPrevia(true, 2); } } else { mantenerEjeX = true; mantenerEjeZ = true; foreach (Construccion2 edificio in edificiosSeleccionados) { vistaPrevia.QuitarEdificio(edificio.edificio, edificio.posicion); } edificiosSeleccionados.Clear(); EdificioVistaPrevia(false, 0); } } if (Input.GetMouseButtonDown(0)) { EdificioConstruir(0); } } if (demolerActivar == true) { EdificioVistaPreviaDemoler(); if (Input.GetMouseButtonDown(0)) { EdificioConstruir(1); } } } //----------------------------------------------- if (canvas.gameObject.GetComponent <CanvasGroup>().alpha == 1) { if (Input.GetKeyDown(teclaOcultarInterfaz)) { ocultarEnseñarInterfaz = true; Objetos.Ocultar(canvas.gameObject); } } else { if (Input.GetKeyDown(teclaOcultarInterfaz) && ocultarEnseñarInterfaz == true) { ocultarEnseñarInterfaz = false; Objetos.Mostrar(canvas.gameObject); } } //----------------------------------------------- if (panelCoste.gameObject.GetComponent <CanvasGroup>().alpha == 1) { Vector3 posicion = Input.mousePosition; posicion.x = posicion.x + 10; posicion.y = posicion.y - 35; panelCoste.gameObject.transform.position = posicion; } }
// Start is called before the first frame update void Awake() { rb = GetComponent <Rigidbody>(); motor = GetComponent <Motor>(); cons = GetComponent <Construccion>(); }
public static void VistaPrevia(List <Construccion2> carreteras, Ciudad ciudad, Construccion carretera, Vector3 posicionCarretera, Construir construir, VistaPrevia vistaPrevia, Construccion[] edificios, bool mantenerEjeX, bool mantenerEjeZ, Panel panelCoste, Text mensajeCoste, CarreterasIDs ids, Escenario escenario) { int eje = 0; if (carreteras.Count == 0) { bool añadir = true; if (escenario.ComprobarEdificable(carretera, posicionCarretera) == false) { añadir = false; } if (vistaPrevia.ComprobarPosicion(carretera, posicionCarretera) != null) { añadir = false; } if (construir.ComprobarPosicion(carretera, posicionCarretera) != null) { añadir = false; } if (añadir == true) { carreteras.Add(new Construccion2(carretera, posicionCarretera)); } } else if (carreteras.Count > 0) { if (mantenerEjeX == true) { if (((carreteras[0].posicion.z == posicionCarretera.z) && (carreteras[0].posicion.x < posicionCarretera.x)) || ((carreteras[0].posicion.z == posicionCarretera.z) && (carreteras[0].posicion.x > posicionCarretera.x))) { if (carretera.id == ids.recta) { carretera.rotacionColocacion = -270; } float mantenerOrigenX = carreteras[0].posicion.x; float mantenerDestinoX = posicionCarretera.x; Vector3 nuevaPosicion = carreteras[0].posicion; if (mantenerDestinoX > mantenerOrigenX) { while (nuevaPosicion.x <= mantenerDestinoX) { bool añadir = true; int coste = 0; foreach (Construccion2 subcarretera in carreteras) { coste = coste + subcarretera.edificio.coste; if (subcarretera.posicion == nuevaPosicion) { añadir = false; } } if (ciudad.Dinero < coste) { añadir = false; } if (añadir == true) { carreteras.Add(new Construccion2(carretera, nuevaPosicion)); } nuevaPosicion.x = nuevaPosicion.x + 1; } eje = 1; } else { while (nuevaPosicion.x >= mantenerDestinoX) { bool añadir = true; foreach (Construccion2 edificio in carreteras) { if (edificio.posicion == nuevaPosicion) { añadir = false; } } if (añadir == true) { carreteras.Add(new Construccion2(carretera, nuevaPosicion)); } nuevaPosicion.x = nuevaPosicion.x - 1; } eje = 2; } mantenerEjeZ = false; } } if (mantenerEjeZ == true) { if (((carreteras[0].posicion.x == posicionCarretera.x) && (carreteras[0].posicion.z < posicionCarretera.z)) || ((carreteras[0].posicion.x == posicionCarretera.x) && (carreteras[0].posicion.z > posicionCarretera.z))) { if (carretera.id == ids.recta) { carretera.rotacionColocacion = 0; } float mantenerOrigenZ = carreteras[0].posicion.z; float mantenerDestinoZ = posicionCarretera.z; Vector3 nuevaPosicion = carreteras[0].posicion; if (mantenerDestinoZ > mantenerOrigenZ) { while (nuevaPosicion.z <= mantenerDestinoZ) { bool añadir = true; foreach (Construccion2 subcarretera in carreteras) { if (subcarretera.posicion == nuevaPosicion) { añadir = false; } } if (añadir == true) { carreteras.Add(new Construccion2(carretera, nuevaPosicion)); } nuevaPosicion.z = nuevaPosicion.z + 1; } eje = 3; } else { while (nuevaPosicion.z >= mantenerDestinoZ) { bool añadir = true; foreach (Construccion2 subcarretera in carreteras) { if (subcarretera.posicion == nuevaPosicion) { añadir = false; } } if (añadir == true) { carreteras.Add(new Construccion2(carretera, nuevaPosicion)); } nuevaPosicion.z = nuevaPosicion.z - 1; } eje = 4; } mantenerEjeX = false; } } } int costeTotal = 0; foreach (Construccion2 subcarretera in carreteras) { if (escenario.ComprobarEdificable(subcarretera.edificio, subcarretera.posicion) == false) { int rotacion = subcarretera.edificio.rotacionColocacion; subcarretera.edificio = edificios[ids.puente]; subcarretera.edificio.rotacionColocacion = rotacion; } costeTotal = costeTotal + subcarretera.edificio.coste; bool carretera1 = false; Vector3 posicion1 = subcarretera.posicion; bool carretera2 = false; Vector3 posicion2 = subcarretera.posicion; bool carretera3 = false; Vector3 posicion3 = subcarretera.posicion; if (eje == 1) { posicion1.x = posicion1.x + 1; posicion2.z = posicion2.z + 1; posicion3.z = posicion3.z - 1; } else if (eje == 2) { posicion1.x = posicion1.x - 1; posicion2.z = posicion2.z + 1; posicion3.z = posicion3.z - 1; } else if (eje == 3) { posicion1.z = posicion1.z + 1; posicion2.x = posicion2.x + 1; posicion3.x = posicion3.x - 1; } else if (eje == 4) { posicion1.z = posicion1.z - 1; posicion2.x = posicion2.x + 1; posicion3.x = posicion3.x - 1; } carretera1 = BuscarCarreteras(carretera1, construir, vistaPrevia, carreteras, subcarretera.edificio, posicion1, eje, ids); carretera2 = BuscarCarreteras(carretera2, construir, vistaPrevia, carreteras, subcarretera.edificio, posicion2, eje, ids); carretera3 = BuscarCarreteras(carretera3, construir, vistaPrevia, carreteras, subcarretera.edificio, posicion3, eje, ids); if ((carretera1 == false) && (carretera2 == true) && (carretera3 == false)) { subcarretera.edificio = edificios[ids.curva]; if (eje == 1) { subcarretera.edificio.rotacionColocacion = 0; } else if (eje == 2) { subcarretera.edificio.rotacionColocacion = -270; } else if (eje == 3) { subcarretera.edificio.rotacionColocacion = -180; } else if (eje == 4) { subcarretera.edificio.rotacionColocacion = -270; } } if ((carretera1 == false) && (carretera2 == false) && (carretera3 == true)) { subcarretera.edificio = edificios[ids.curva]; if (eje == 1) { subcarretera.edificio.rotacionColocacion = -90; } else if (eje == 2) { subcarretera.edificio.rotacionColocacion = -180; } else if (eje == 3) { subcarretera.edificio.rotacionColocacion = -90; } else if (eje == 4) { subcarretera.edificio.rotacionColocacion = 0; } } if ((carretera1 == true) && (carretera2 == true) && (carretera3 == false)) { subcarretera.edificio = edificios[ids.cruce3]; if ((eje == 1) || (eje == 2)) { subcarretera.edificio.rotacionColocacion = 0; } else if ((eje == 3) || (eje == 4)) { subcarretera.edificio.rotacionColocacion = -270; } } if ((carretera1 == true) && (carretera2 == false) && (carretera3 == true)) { subcarretera.edificio = edificios[ids.cruce3]; if ((eje == 1) || (eje == 2)) { subcarretera.edificio.rotacionColocacion = -180; } else if ((eje == 3) || (eje == 4)) { subcarretera.edificio.rotacionColocacion = -90; } } if ((carretera1 == false) && (carretera2 == true) && (carretera3 == true)) { subcarretera.edificio = edificios[ids.cruce3]; if (eje == 1) { subcarretera.edificio.rotacionColocacion = -90; } else if (eje == 2) { subcarretera.edificio.rotacionColocacion = -270; } else if (eje == 3) { subcarretera.edificio.rotacionColocacion = -180; } else if (eje == 4) { subcarretera.edificio.rotacionColocacion = 0; } } if ((carretera1 == true) && (carretera2 == true) && (carretera3 == true)) { if ((eje == 1) || (eje == 2) || (eje == 3) || (eje == 4)) { subcarretera.edificio = edificios[ids.cruce4]; } } if (vistaPrevia.ComprobarPosicion(subcarretera.edificio, subcarretera.posicion) == null) { vistaPrevia.AñadirConstruccion(subcarretera.edificio, subcarretera.posicion); } } panelCoste.gameObject.GetComponent <CanvasGroup>().alpha = 1; mensajeCoste.text = string.Format("-{0} €", costeTotal); }
//----------------------------------------------------- public static Vector3 Edificio(Construccion edificio, Vector3 posicion) { if (edificio.categoria == 1) { posicion.y = 1f; } else { posicion.y = 0.5f; } if (edificio.id == 42 || edificio.id == 43) { posicion.y = 0.51f; } if (edificio.dimensiones.x > 1) { float ajuste = -0.5f; if (edificio.dimensiones.x > 3) { ajuste = -1f; } if ((edificio.rotacionColocacion == -270) || (edificio.rotacionColocacion == -90)) { posicion.x = posicion.x - Mathf.Round(edificio.dimensiones.x / 2) + ajuste; } else { posicion.z = posicion.z - Mathf.Round(edificio.dimensiones.x / 2) + ajuste; //Edificio 2x1 Comercio if (edificio.id == 32) { posicion.x = posicion.x - 1f; posicion.z = posicion.z + 2f; } } } if (edificio.dimensiones.y > 1) { float ajuste = -0.5f; if (edificio.dimensiones.y > 3) { ajuste = -1f; } if ((edificio.rotacionColocacion == -270) || (edificio.rotacionColocacion == -90)) { posicion.z = posicion.z - Mathf.Round(edificio.dimensiones.y / 2) + ajuste; } else { posicion.x = posicion.x - Mathf.Round(edificio.dimensiones.y / 2) + ajuste; //Edificio 2x1 Viviendas if (edificio.dimensiones.x == 1) { posicion.x = posicion.x + 1f; posicion.z = posicion.z - Mathf.Round(edificio.dimensiones.y / 2); } } } return(posicion); }
public void Añadir(Construccion[,] edificios, Construccion edificio, Vector3 posicion) { posicion.y = 1.5f; if (edificio.dimensiones.x == 2 && edificio.dimensiones.y == 1) { if ((edificio.rotacionColocacion == -270) || (edificio.rotacionColocacion == -90)) { posicion.x = posicion.x + 0.5f; } else { posicion.z = posicion.z + 0.5f; } edificios[(int)posicion.x, (int)posicion.z] = Instantiate(edificioVacioAñadir, posicion, Quaternion.identity); } if (edificio.dimensiones.x == 1 && edificio.dimensiones.y == 2) { if ((edificio.rotacionColocacion == -270) || (edificio.rotacionColocacion == -90)) { posicion.z = posicion.z + 0.5f; } else { posicion.x = posicion.x + 0.5f; } edificios[(int)posicion.x, (int)posicion.z] = Instantiate(edificioVacioAñadir, posicion, Quaternion.identity); } if (edificio.dimensiones.x == 2 && edificio.dimensiones.y == 2) { Vector3 posicion1 = posicion; Vector3 posicion2 = posicion; Vector3 posicion3 = posicion; posicion1.x = posicion1.x + 0.5f; posicion1.z = posicion1.z + 0.5f; posicion2.x = posicion2.x - 0.5f; posicion2.z = posicion2.z + 0.5f; posicion3.x = posicion3.x + 0.5f; posicion3.z = posicion3.z - 0.5f; edificios[(int)posicion1.x, (int)posicion1.z] = Instantiate(edificioVacioAñadir, posicion1, Quaternion.identity); edificios[(int)posicion2.x, (int)posicion2.z] = Instantiate(edificioVacioAñadir, posicion2, Quaternion.identity); edificios[(int)posicion3.x, (int)posicion3.z] = Instantiate(edificioVacioAñadir, posicion3, Quaternion.identity); } if (edificio.dimensiones.x == 2 && edificio.dimensiones.y == 3) { Vector3 posicion1 = posicion; Vector3 posicion2 = posicion; Vector3 posicion3 = posicion; Vector3 posicion4 = posicion; Vector3 posicion5 = posicion; Vector3 posicion6 = posicion; Vector3 posicion7 = posicion; if ((edificio.rotacionColocacion == -270) || (edificio.rotacionColocacion == -90)) { posicion1.x = posicion1.x + 0.5f; posicion1.z = posicion1.z + 0.5f; posicion2.x = posicion2.x + 0.5f; posicion2.z = posicion2.z + 1.5f; posicion3.x = posicion3.x + 0.5f; posicion3.z = posicion3.z - 0.5f; posicion4.x = posicion4.x + 0.5f; posicion4.z = posicion4.z - 1.5f; posicion5.x = posicion5.x - 0.5f; posicion5.z = posicion5.z + 1.5f; posicion6.x = posicion6.x - 0.5f; posicion6.z = posicion6.z - 0.5f; posicion7.x = posicion7.x - 0.5f; posicion7.z = posicion7.z - 1.5f; } else { posicion1.x = posicion1.x + 0.5f; posicion1.z = posicion1.z + 0.5f; posicion2.x = posicion2.x + 1.5f; posicion2.z = posicion2.z + 0.5f; posicion3.x = posicion3.x + 1.5f; posicion3.z = posicion3.z - 0.5f; posicion4.x = posicion4.x + 0.5f; posicion4.z = posicion4.z - 0.5f; posicion5.x = posicion5.x - 1.5f; posicion5.z = posicion5.z - 0.5f; posicion6.x = posicion6.x - 1.5f; posicion6.z = posicion6.z + 0.5f; posicion7.x = posicion7.x - 0.5f; posicion7.z = posicion7.z + 0.5f; } edificios[(int)posicion1.x, (int)posicion1.z] = Instantiate(edificioVacioAñadir, posicion1, Quaternion.identity); edificios[(int)posicion2.x, (int)posicion2.z] = Instantiate(edificioVacioAñadir, posicion2, Quaternion.identity); edificios[(int)posicion3.x, (int)posicion3.z] = Instantiate(edificioVacioAñadir, posicion3, Quaternion.identity); edificios[(int)posicion4.x, (int)posicion4.z] = Instantiate(edificioVacioAñadir, posicion4, Quaternion.identity); edificios[(int)posicion5.x, (int)posicion5.z] = Instantiate(edificioVacioAñadir, posicion5, Quaternion.identity); edificios[(int)posicion6.x, (int)posicion6.z] = Instantiate(edificioVacioAñadir, posicion6, Quaternion.identity); edificios[(int)posicion7.x, (int)posicion7.z] = Instantiate(edificioVacioAñadir, posicion7, Quaternion.identity); } if (edificio.dimensiones.x == 4 && edificio.dimensiones.y == 3) { Vector3 posicion1 = posicion; Vector3 posicion2 = posicion; Vector3 posicion3 = posicion; Vector3 posicion4 = posicion; Vector3 posicion5 = posicion; Vector3 posicion6 = posicion; Vector3 posicion7 = posicion; Vector3 posicion8 = posicion; Vector3 posicion9 = posicion; Vector3 posicion10 = posicion; Vector3 posicion11 = posicion; if ((edificio.rotacionColocacion == -270) || (edificio.rotacionColocacion == -90)) { posicion1.x = posicion1.x + 1f; posicion1.z = posicion1.z + 1.5f; posicion2.x = posicion2.x + 1f; posicion2.z = posicion2.z + 0.5f; posicion3.x = posicion3.x + 1f; posicion3.z = posicion3.z - 0.5f; posicion4.x = posicion4.x + 1f; posicion4.z = posicion4.z - 1.5f; posicion5.x = posicion5.x + 0f; posicion5.z = posicion5.z + 1.5f; posicion6.x = posicion6.x + 0f; posicion6.z = posicion6.z + 0.5f; posicion7.x = posicion7.x + 0f; posicion7.z = posicion7.z - 1.5f; posicion8.x = posicion8.x - 1f; posicion8.z = posicion8.z + 1.5f; posicion9.x = posicion9.x - 1f; posicion9.z = posicion9.z + 0.5f; posicion10.x = posicion10.x - 1f; posicion10.z = posicion10.z - 0.5f; posicion11.x = posicion11.x - 1f; posicion11.z = posicion11.z - 1.5f; } else { posicion1.x = posicion1.x + 1.5f; posicion1.z = posicion1.z + 1f; posicion2.x = posicion2.x + 0.5f; posicion2.z = posicion2.z + 1f; posicion3.x = posicion3.x - 0.5f; posicion3.z = posicion3.z + 1f; posicion4.x = posicion4.x - 1.5f; posicion4.z = posicion4.z + 1f; posicion5.x = posicion5.x + 1.5f; posicion5.z = posicion5.z + 0f; posicion6.x = posicion6.x + 0.5f; posicion6.z = posicion6.z + 0f; posicion7.x = posicion7.x - 1.5f; posicion7.z = posicion7.z + 0f; posicion8.x = posicion8.x + 1.5f; posicion8.z = posicion8.z - 1f; posicion9.x = posicion9.x + 0.5f; posicion9.z = posicion9.z - 1f; posicion10.x = posicion10.x - 0.5f; posicion10.z = posicion10.z - 1f; posicion11.x = posicion11.x - 1.5f; posicion11.z = posicion11.z - 1f; } edificios[(int)posicion1.x, (int)posicion1.z] = Instantiate(edificioVacioAñadir, posicion1, Quaternion.identity); edificios[(int)posicion2.x, (int)posicion2.z] = Instantiate(edificioVacioAñadir, posicion2, Quaternion.identity); edificios[(int)posicion3.x, (int)posicion3.z] = Instantiate(edificioVacioAñadir, posicion3, Quaternion.identity); edificios[(int)posicion4.x, (int)posicion4.z] = Instantiate(edificioVacioAñadir, posicion4, Quaternion.identity); edificios[(int)posicion5.x, (int)posicion5.z] = Instantiate(edificioVacioAñadir, posicion5, Quaternion.identity); edificios[(int)posicion6.x, (int)posicion6.z] = Instantiate(edificioVacioAñadir, posicion6, Quaternion.identity); edificios[(int)posicion7.x, (int)posicion7.z] = Instantiate(edificioVacioAñadir, posicion7, Quaternion.identity); edificios[(int)posicion8.x, (int)posicion8.z] = Instantiate(edificioVacioAñadir, posicion8, Quaternion.identity); edificios[(int)posicion9.x, (int)posicion9.z] = Instantiate(edificioVacioAñadir, posicion9, Quaternion.identity); edificios[(int)posicion10.x, (int)posicion10.z] = Instantiate(edificioVacioAñadir, posicion10, Quaternion.identity); edificios[(int)posicion11.x, (int)posicion11.z] = Instantiate(edificioVacioAñadir, posicion11, Quaternion.identity); } }
public void ComprobarLucesEdificio(bool encender, Construccion edificio) { bool modificar = false; Material material = edificio.gameObject.GetComponent <Renderer>().sharedMaterial; if (encender == true) { if (edificio.categoria == 1) { bool lucesCarretera = true; if (edificio.categoria == 1) { if (edificio.id == 10) { lucesCarretera = false; } else if (edificio.id == 11) { lucesCarretera = false; } } if (lucesCarretera == true) { Light[] luces = edificio.GetComponentsInChildren <Light>(); foreach (Light luz in luces) { luz.intensity = edificio.luzIntesidad; luz.range = edificio.luzRango; } } } if (edificio.categoria == 2) { modificar = true; } else if (edificio.categoria == 4) { modificar = true; } else if (edificio.categoria == 5) { modificar = true; } if (modificar == true) { material.EnableKeyword("_EMISSION"); material.globalIlluminationFlags = MaterialGlobalIlluminationFlags.RealtimeEmissive; } } else { if (edificio.categoria == 1) { bool lucesCarretera = true; if (edificio.categoria == 1) { if (edificio.id == 10) { lucesCarretera = false; } else if (edificio.id == 11) { lucesCarretera = false; } } if (lucesCarretera == true) { Light[] luces = edificio.GetComponentsInChildren <Light>(); foreach (Light luz in luces) { luz.intensity = 0; luz.range = 0; } } } if (edificio.categoria == 2) { modificar = true; } else if (edificio.categoria == 4) { modificar = true; } else if (edificio.categoria == 5) { modificar = true; } if (modificar == true) { material.DisableKeyword("_EMISSION"); material.globalIlluminationFlags = MaterialGlobalIlluminationFlags.EmissiveIsBlack; } } }
public bool ComprobarEdificable(Construccion edificio, Vector3 posicion) { return(colisiones.Terreno(terrenos2, edificio, posicion)); }
public void PonerArboles(Guardado partida, Construir construir) { if (partida != null) { if (partida.edificiosID.Count > 0) { int i = 0; while (i < partida.edificiosID.Count) { Vector3 posicion = new Vector3(partida.edificiosX[i], 0.5f, partida.edificiosZ[i]); Construccion arbol = null; foreach (Construccion arbol2 in arboles) { if (arbol2.id == partida.edificiosID[i]) { arbol = arbol2; } } if (arbol != null) { GenerarArbol(arbol, posicion, construir); } i += 1; } } } else { if (arboles != null) { if (arboles.Length > 0) { int arbolesTramo1 = 250; int i = 0; while (i < arbolesTramo1) { Vector3 posicion = new Vector3(Random.Range(0, 30), 1, Random.Range(0, 99)); int j = Random.Range(0, arboles.Length); if (arboles[j] != null) { GenerarArbol(arboles[j], posicion, construir); } i++; } int arbolesTramo2 = 30; i = 0; while (i < arbolesTramo2) { Vector3 posicion = new Vector3(Random.Range(31, 69), 1, Random.Range(0, 99)); int j = Random.Range(0, arboles.Length); if (arboles[j] != null) { GenerarArbol(arboles[j], posicion, construir); } i++; } int arbolesTramo3 = 250; i = 0; while (i < arbolesTramo3) { Vector3 posicion = new Vector3(Random.Range(70, 99), 1, Random.Range(0, 99)); int j = Random.Range(0, arboles.Length); if (arboles[j] != null) { GenerarArbol(arboles[j], posicion, construir); } i++; } } } } }
public void QuitarEdificio(Construccion edificio, Vector3 posicion) { edificios = Funciones.QuitarEdificios(edificios, edificio, posicion); }
public Construccion ComprobarPosicion(Construccion edificio, Vector3 posicion) { return(colisiones.Detectar(edificios, edificio, posicion)); }
public static void Construir(List <Construccion2> carreteras, Ciudad ciudad, Construir construir, DiaNoche diaNoche, Construccion[] edificios, AudioSource sonidoBotonConstruir) { if (carreteras.Count > 0) { int coste = 0; foreach (Construccion2 subcarretera in carreteras) { coste = coste + subcarretera.edificio.coste; } if (ciudad.Dinero >= coste) { sonidoBotonConstruir.Play(); foreach (Construccion2 subcarretera in carreteras) { if (construir.ComprobarPosicion(subcarretera.edificio, subcarretera.posicion) == null) { construir.AñadirConstruccion(subcarretera.edificio, subcarretera.posicion, diaNoche.EstadoEncendidoLuces()); } else { Construccion edificioEncontrado = construir.ComprobarPosicion(subcarretera.edificio, subcarretera.posicion); if (edificioEncontrado.categoria == 0) { construir.QuitarEdificio(edificioEncontrado, subcarretera.posicion); construir.AñadirConstruccion(subcarretera.edificio, subcarretera.posicion, diaNoche.EstadoEncendidoLuces()); ciudad.DepositoDinero(edificioEncontrado.coste / 2); } if (edificioEncontrado.categoria == 1) { bool eliminar = false; if (edificioEncontrado.id != subcarretera.edificio.id) { eliminar = true; } else { if (edificioEncontrado.rotacionColocacion != subcarretera.edificio.rotacionColocacion) { eliminar = true; } } if (eliminar == true) { if (edificioEncontrado.categoria != 0) { ciudad.DepositoDinero(edificioEncontrado.coste / 3); } ciudad.ActualizarUI(false); construir.QuitarEdificio(edificioEncontrado, subcarretera.posicion); construir.AñadirConstruccion(subcarretera.edificio, subcarretera.posicion, diaNoche.EstadoEncendidoLuces()); } } } } ciudad.DepositoDinero(-coste); ciudad.ActualizarUI(false); } } }
void EdificioConstruir(int accion) { Vector3 raton = Posicion.Raton(); if (raton != Vector3.zero) { Vector3 posicion = Posicion.Redondear(raton, edificioSeleccionado); if (Posicion.Limites(posicion, 100) == true) { if (edificiosSeleccionados.Count > 0) { if (edificiosSeleccionados[0].edificio.categoria == 1) { Carreteras.Construir(edificiosSeleccionados, ciudad, construir, velocidad); } } else { if (accion == 0) { bool añadir = true; if (escenario.ComprobarEdificable(edificioSeleccionado, posicion) == false) { añadir = false; } if (construir.ComprobarPosicion(edificioSeleccionado, posicion) != null) { añadir = false; } if (ciudad.Dinero < edificioSeleccionado.coste) { añadir = false; } if (añadir == true) { construirActivar = false; vistaPrevia.QuitarTodosEdificios(); construirInterfaz.RatonSaleBotonEdificios(); panelCoste.gameObject.GetComponent <CanvasGroup>().alpha = 0; ciudad.DepositoDinero(-edificioSeleccionado.coste); ciudad.ActualizarUI(false); construir.AñadirConstruccion(edificioSeleccionado, posicion, velocidad.EstadoEncendidoLuces()); sonido.Construir(); } } if (accion == 1) { if (edificioSeleccionado != null) { demolerActivar = false; vistaPrevia.QuitarTodosEdificios(); demolerInterfaz.RatonSale(); Construccion edificioEliminar = edificioSeleccionado; if (edificioEliminar.categoria != 0) { ciudad.DepositoDinero(edificioEliminar.coste / 3); } ciudad.ActualizarUI(false); construir.QuitarEdificio(edificioEliminar, posicion); sonido.Demoler(); } } } } } }
public static Vector3 EdificioAjusteCarga(Construccion edificio, Vector3 posicion) { if (edificio.dimensiones.x > 1) { float ajuste = 0.5f; if (edificio.dimensiones.x > 3) { ajuste = 1f; } if ((edificio.rotacionColocacion == -270) || (edificio.rotacionColocacion == -90)) { posicion.x = posicion.x - Mathf.Round(edificio.dimensiones.x / 2) + ajuste; if (edificio.dimensiones.x == 2 && edificio.dimensiones.y == 1) { posicion.x = posicion.x + 2.5f; posicion.z = posicion.z - 1f; } } else { posicion.z = posicion.z - Mathf.Round(edificio.dimensiones.x / 2) + ajuste; if (edificio.dimensiones.x == 2 && edificio.dimensiones.y == 1) { posicion.x = posicion.x + 0f; posicion.z = posicion.z + 0.5f; } } } if (edificio.dimensiones.y > 1) { float ajuste = 0.5f; if (edificio.dimensiones.y > 3) { ajuste = 1f; } if ((edificio.rotacionColocacion == -270) || (edificio.rotacionColocacion == -90)) { posicion.z = posicion.z - Mathf.Round(edificio.dimensiones.y / 2) + ajuste; if (edificio.dimensiones.x == 2 && edificio.dimensiones.y == 2) { posicion.x = posicion.x + 1.5f; posicion.z = posicion.z + 1.5f; } if (edificio.dimensiones.x == 1 && edificio.dimensiones.y == 2) { posicion.z = posicion.z + 2.5f; } if (edificio.dimensiones.x == 2 && edificio.dimensiones.y == 3) { posicion.x = posicion.x + 2.5f; posicion.z = posicion.z + 4.5f; } if (edificio.dimensiones.x == 4 && edificio.dimensiones.y == 3) { posicion.x = posicion.x + 3f; posicion.z = posicion.z + 2.5f; } } else { posicion.x = posicion.x - Mathf.Round(edificio.dimensiones.y / 2) + ajuste; if (edificio.dimensiones.x == 2 && edificio.dimensiones.y == 2) { posicion.x = posicion.x + 1.5f; posicion.z = posicion.z + 1.5f; } if (edificio.dimensiones.x == 1 && edificio.dimensiones.y == 2) { posicion.x = posicion.x + 1.5f; posicion.z = posicion.z + Mathf.Round(edificio.dimensiones.y / 2); } if (edificio.dimensiones.x == 2 && edificio.dimensiones.y == 3) { posicion.x = posicion.x + 4.5f; posicion.z = posicion.z + 2.5f; } if (edificio.dimensiones.x == 4 && edificio.dimensiones.y == 3) { posicion.x = posicion.x + 2.5f; posicion.z = posicion.z + 3f; } } } return(posicion); }
public bool Terreno(Terreno[,] terrenos, Construccion edificio, Vector3 posicion) { if (edificio.dimensiones.x == 1 && edificio.dimensiones.y == 1) { if (terrenos[(int)posicion.x, (int)posicion.z] != null) { if (terrenos[(int)posicion.x, (int)posicion.z].edificable == false) { return(false); } } } if (edificio.dimensiones.x == 2 && edificio.dimensiones.y == 1) { Vector3 posicion1 = posicion; if ((edificio.rotacionColocacion == -270) || (edificio.rotacionColocacion == -90)) { posicion.x = posicion.x - 2f; posicion1.x = posicion1.x - 1f; posicion1.z = posicion1.z + 0f; } else { posicion.x = posicion.x - 1f; posicion1.x = posicion1.x - 1f; posicion1.z = posicion1.z + 1f; } if (terrenos[(int)posicion.x, (int)posicion.z] != null) { if (terrenos[(int)posicion.x, (int)posicion.z].edificable == false) { return(false); } } if (terrenos[(int)posicion1.x, (int)posicion1.z] != null) { if (terrenos[(int)posicion1.x, (int)posicion1.z].edificable == false) { return(false); } } } if (edificio.dimensiones.x == 1 && edificio.dimensiones.y == 2) { Vector3 posicion1 = posicion; if ((edificio.rotacionColocacion == -270) || (edificio.rotacionColocacion == -90)) { posicion.x = posicion.x - 0f; posicion.z = posicion.z - 2f; posicion1.x = posicion1.x + 0f; posicion1.z = posicion1.z - 1f; } else { posicion.x = posicion.x - 1f; posicion.z = posicion.z - 1f; posicion1.x = posicion1.x + 0f; posicion1.z = posicion1.z - 1f; } if (terrenos[(int)posicion.x, (int)posicion.z] != null) { if (terrenos[(int)posicion.x, (int)posicion.z].edificable == false) { return(false); } } if (terrenos[(int)posicion1.x, (int)posicion1.z] != null) { if (terrenos[(int)posicion1.x, (int)posicion1.z].edificable == false) { return(false); } } } if (edificio.dimensiones.x == 2 && edificio.dimensiones.y == 2) { Vector3 posicion1 = posicion; Vector3 posicion2 = posicion; Vector3 posicion3 = posicion; posicion.x = posicion.x - 2f; posicion.z = posicion.z - 2f; posicion1.x = posicion1.x - 1f; posicion1.z = posicion1.z - 2f; posicion2.x = posicion2.x - 2f; posicion2.z = posicion2.z - 1f; posicion3.x = posicion3.x - 1f; posicion3.z = posicion3.z - 1f; if (terrenos[(int)posicion.x, (int)posicion.z] != null) { if (terrenos[(int)posicion.x, (int)posicion.z].edificable == false) { return(false); } } if (terrenos[(int)posicion1.x, (int)posicion1.z] != null) { if (terrenos[(int)posicion1.x, (int)posicion1.z].edificable == false) { return(false); } } if (terrenos[(int)posicion2.x, (int)posicion2.z] != null) { if (terrenos[(int)posicion2.x, (int)posicion2.z].edificable == false) { return(false); } } if (terrenos[(int)posicion3.x, (int)posicion3.z] != null) { if (terrenos[(int)posicion3.x, (int)posicion3.z].edificable == false) { return(false); } } } if (edificio.dimensiones.x == 2 && edificio.dimensiones.y == 3) { Vector3 posicion1 = posicion; Vector3 posicion2 = posicion; Vector3 posicion3 = posicion; Vector3 posicion4 = posicion; Vector3 posicion5 = posicion; Vector3 posicion6 = posicion; Vector3 posicion7 = posicion; if ((edificio.rotacionColocacion == -270) || (edificio.rotacionColocacion == -90)) { posicion.x = posicion.x - 1f; posicion.z = posicion.z - 1f; posicion1.x = posicion1.x - 1f; posicion1.z = posicion1.z - 2f; posicion2.x = posicion2.x - 1f; posicion2.z = posicion2.z - 3f; posicion3.x = posicion3.x - 1f; posicion3.z = posicion3.z - 4f; posicion4.x = posicion4.x - 2f; posicion4.z = posicion4.z - 1f; posicion5.x = posicion5.x - 2f; posicion5.z = posicion5.z - 2f; posicion6.x = posicion6.x - 2f; posicion6.z = posicion6.z - 3f; posicion7.x = posicion7.x - 2f; posicion7.z = posicion7.z - 4f; } else { posicion.x = posicion.x - 1f; posicion.z = posicion.z - 1f; posicion1.x = posicion1.x - 2f; posicion1.z = posicion1.z - 1f; posicion2.x = posicion2.x - 3f; posicion2.z = posicion2.z - 1f; posicion3.x = posicion3.x - 4f; posicion3.z = posicion3.z - 1f; posicion4.x = posicion4.x - 1f; posicion4.z = posicion4.z - 2f; posicion5.x = posicion5.x - 2f; posicion5.z = posicion5.z - 2f; posicion6.x = posicion6.x - 3f; posicion6.z = posicion6.z - 2f; posicion7.x = posicion7.x - 4f; posicion7.z = posicion7.z - 2f; } if (terrenos[(int)posicion.x, (int)posicion.z] != null) { if (terrenos[(int)posicion.x, (int)posicion.z].edificable == false) { return(false); } } if (terrenos[(int)posicion1.x, (int)posicion1.z] != null) { if (terrenos[(int)posicion1.x, (int)posicion1.z].edificable == false) { return(false); } } if (terrenos[(int)posicion2.x, (int)posicion2.z] != null) { if (terrenos[(int)posicion2.x, (int)posicion2.z].edificable == false) { return(false); } } if (terrenos[(int)posicion3.x, (int)posicion3.z] != null) { if (terrenos[(int)posicion3.x, (int)posicion3.z].edificable == false) { return(false); } } if (terrenos[(int)posicion4.x, (int)posicion4.z] != null) { if (terrenos[(int)posicion4.x, (int)posicion4.z].edificable == false) { return(false); } } if (terrenos[(int)posicion5.x, (int)posicion5.z] != null) { if (terrenos[(int)posicion5.x, (int)posicion5.z].edificable == false) { return(false); } } if (terrenos[(int)posicion6.x, (int)posicion6.z] != null) { if (terrenos[(int)posicion6.x, (int)posicion6.z].edificable == false) { return(false); } } if (terrenos[(int)posicion7.x, (int)posicion7.z] != null) { if (terrenos[(int)posicion7.x, (int)posicion7.z].edificable == false) { return(false); } } } if (edificio.dimensiones.x == 4 && edificio.dimensiones.y == 3) { Vector3 posicion1 = posicion; Vector3 posicion2 = posicion; Vector3 posicion3 = posicion; Vector3 posicion4 = posicion; Vector3 posicion5 = posicion; Vector3 posicion6 = posicion; Vector3 posicion7 = posicion; Vector3 posicion8 = posicion; Vector3 posicion9 = posicion; Vector3 posicion10 = posicion; Vector3 posicion11 = posicion; //Debug.Log(edificio.rotacionColocacion); //Instantiate(edificioVacioDetectar, posicion, Quaternion.identity); if ((edificio.rotacionColocacion == -270) || (edificio.rotacionColocacion == -90)) { posicion.x = posicion.x - 2f; posicion.z = posicion.z - 1f; posicion1.x = posicion1.x - 2f; posicion1.z = posicion1.z - 2f; posicion2.x = posicion2.x - 2f; posicion2.z = posicion2.z - 3f; posicion3.x = posicion3.x - 2f; posicion3.z = posicion3.z - 4f; posicion4.x = posicion4.x - 3f; posicion4.z = posicion4.z - 1f; posicion5.x = posicion5.x - 3f; posicion5.z = posicion5.z - 2f; posicion6.x = posicion6.x - 3f; posicion6.z = posicion6.z - 3f; posicion7.x = posicion7.x - 3f; posicion7.z = posicion7.z - 4f; posicion8.x = posicion8.x - 4f; posicion8.z = posicion8.z - 1f; posicion9.x = posicion9.x - 4f; posicion9.z = posicion9.z - 2f; posicion10.x = posicion10.x - 4f; posicion10.z = posicion10.z - 3f; posicion11.x = posicion11.x - 4f; posicion11.z = posicion11.z - 4f; } else { posicion.x = posicion.x - 1f; posicion.z = posicion.z - 2f; posicion1.x = posicion1.x - 2f; posicion1.z = posicion1.z - 2f; posicion2.x = posicion2.x - 3f; posicion2.z = posicion2.z - 2f; posicion3.x = posicion3.x - 4f; posicion3.z = posicion3.z - 2f; posicion4.x = posicion4.x - 1f; posicion4.z = posicion4.z - 3f; posicion5.x = posicion5.x - 2f; posicion5.z = posicion5.z - 3f; posicion6.x = posicion6.x - 3f; posicion6.z = posicion6.z - 3f; posicion7.x = posicion7.x - 4f; posicion7.z = posicion7.z - 3f; posicion8.x = posicion8.x - 1f; posicion8.z = posicion8.z - 4f; posicion9.x = posicion9.x - 2f; posicion9.z = posicion9.z - 4f; posicion10.x = posicion10.x - 3f; posicion10.z = posicion10.z - 4f; posicion11.x = posicion11.x - 4f; posicion11.z = posicion11.z - 4f; } if (terrenos[(int)posicion.x, (int)posicion.z] != null) { if (terrenos[(int)posicion.x, (int)posicion.z].edificable == false) { return(false); } } if (terrenos[(int)posicion1.x, (int)posicion1.z] != null) { if (terrenos[(int)posicion1.x, (int)posicion1.z].edificable == false) { return(false); } } if (terrenos[(int)posicion2.x, (int)posicion2.z] != null) { if (terrenos[(int)posicion2.x, (int)posicion2.z].edificable == false) { return(false); } } if (terrenos[(int)posicion3.x, (int)posicion3.z] != null) { if (terrenos[(int)posicion3.x, (int)posicion3.z].edificable == false) { return(false); } } if (terrenos[(int)posicion4.x, (int)posicion4.z] != null) { if (terrenos[(int)posicion4.x, (int)posicion4.z].edificable == false) { return(false); } } if (terrenos[(int)posicion5.x, (int)posicion5.z] != null) { if (terrenos[(int)posicion5.x, (int)posicion5.z].edificable == false) { return(false); } } if (terrenos[(int)posicion6.x, (int)posicion6.z] != null) { if (terrenos[(int)posicion6.x, (int)posicion6.z].edificable == false) { return(false); } } if (terrenos[(int)posicion7.x, (int)posicion7.z] != null) { if (terrenos[(int)posicion7.x, (int)posicion7.z].edificable == false) { return(false); } } if (terrenos[(int)posicion8.x, (int)posicion8.z] != null) { if (terrenos[(int)posicion8.x, (int)posicion8.z].edificable == false) { return(false); } } if (terrenos[(int)posicion9.x, (int)posicion9.z] != null) { if (terrenos[(int)posicion9.x, (int)posicion9.z].edificable == false) { return(false); } } if (terrenos[(int)posicion10.x, (int)posicion10.z] != null) { if (terrenos[(int)posicion10.x, (int)posicion10.z].edificable == false) { return(false); } } if (terrenos[(int)posicion11.x, (int)posicion11.z] != null) { if (terrenos[(int)posicion11.x, (int)posicion11.z].edificable == false) { return(false); } } } return(true); }
private void AñadirBotonEdificios(Construccion edificio, Panel panel) { GameObject botonObjeto = Instantiate(botonPrefab); botonObjeto.transform.SetParent(panel.transform, false); GameObject panelBoton = botonObjeto.transform.GetChild(0).gameObject; Panel subpanelBotonImagen = panelBoton.transform.GetChild(0).transform.GetComponent <Panel>(); Image imagen = subpanelBotonImagen.transform.GetChild(0).transform.GetComponent <Image>(); imagen.sprite = edificio.botonImagen; //----------------------------------- Panel subpanelBotonDatos = panelBoton.transform.GetChild(1).transform.GetComponent <Panel>(); Text coste = subpanelBotonDatos.transform.GetChild(0).transform.GetComponent <Text>(); coste.text = string.Format("{0} €", edificio.coste); coste.color = colorRojo; Panel panelBotonComida = subpanelBotonDatos.gameObject.transform.GetChild(1).transform.GetComponent <Panel>(); if (panelBotonComida != null) { if (edificio.comida != 0) { panelBotonComida.gameObject.SetActive(true); Transform iconoT = panelBotonComida.gameObject.transform.GetChild(0); TextMeshProUGUI icono = iconoT.gameObject.GetComponent <TextMeshProUGUI>(); Text comida = panelBotonComida.transform.GetChild(1).transform.GetComponent <Text>(); comida.text = string.Format("{0}", edificio.comida); if (edificio.comida > 0) { icono.color = colorVerde; comida.text = string.Format("+{0}", comida.text); comida.color = colorVerde; } else if (edificio.comida < 0) { icono.color = colorRojo; comida.color = colorRojo; } } else { panelBotonComida.gameObject.SetActive(false); } } Panel panelBotonPoblacion = subpanelBotonDatos.gameObject.transform.GetChild(2).transform.GetComponent <Panel>(); if (panelBotonPoblacion != null) { if (edificio.poblacion != 0) { panelBotonPoblacion.gameObject.SetActive(true); Transform iconoT = panelBotonPoblacion.gameObject.transform.GetChild(0); TextMeshProUGUI icono = iconoT.gameObject.GetComponent <TextMeshProUGUI>(); Text poblacion = panelBotonPoblacion.transform.GetChild(1).transform.GetComponent <Text>(); poblacion.text = string.Format("{0}", edificio.poblacion); if (edificio.poblacion > 0) { icono.color = colorVerde; poblacion.text = string.Format("+{0}", poblacion.text); poblacion.color = colorVerde; } else if (edificio.poblacion < 0) { icono.color = colorRojo; poblacion.color = colorRojo; } } else { panelBotonPoblacion.gameObject.SetActive(false); } } Panel panelBotonTrabajo = subpanelBotonDatos.gameObject.transform.GetChild(3).transform.GetComponent <Panel>(); if (panelBotonTrabajo != null) { if (edificio.trabajo != 0) { panelBotonTrabajo.gameObject.SetActive(true); Transform iconoT = panelBotonTrabajo.gameObject.transform.GetChild(0); TextMeshProUGUI icono = iconoT.gameObject.GetComponent <TextMeshProUGUI>(); Text trabajo = panelBotonTrabajo.transform.GetChild(1).transform.GetComponent <Text>(); trabajo.text = string.Format("{0}", edificio.trabajo); if (edificio.trabajo > 0) { icono.color = colorVerde; trabajo.text = string.Format("+{0}", trabajo.text); trabajo.color = colorVerde; } else if (edificio.trabajo < 0) { icono.color = colorRojo; trabajo.color = colorRojo; } } else { panelBotonTrabajo.gameObject.SetActive(false); } } //----------------------------------- Button boton = botonObjeto.GetComponent <Button>(); boton.onClick.AddListener(() => juego.ConstruirSeleccionarEdificio(edificio.id)); boton.onClick.AddListener(() => CerrarPaneles()); EventTrigger evento = botonObjeto.AddComponent <EventTrigger>(); EventTrigger.Entry pointerEnter = new EventTrigger.Entry { eventID = EventTriggerType.PointerEnter }; pointerEnter.callback.AddListener((data) => { CursorEntraEdificio((PointerEventData)data, boton, edificio.categoria); }); evento.triggers.Add(pointerEnter); EventTrigger.Entry pointerExit = new EventTrigger.Entry { eventID = EventTriggerType.PointerExit }; pointerExit.callback.AddListener((data) => { CursorSaleEdificio((PointerEventData)data, boton); }); evento.triggers.Add(pointerExit); }