Beispiel #1
0
        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);
        }
Beispiel #2
0
        public void Arranque(Construccion[] edificios)
        {
            RectTransform rtDecoracion = panelDecoracion.GetComponent <RectTransform>();

            rtDecoracion.sizeDelta = new Vector2(rtDecoracion.sizeDelta.x, 0);
            alturaDecoracion       = 0;

            RectTransform rtCarreteras = panelCarreteras.GetComponent <RectTransform>();

            rtCarreteras.sizeDelta = new Vector2(rtCarreteras.sizeDelta.x, 0);
            alturaCarreteras       = 0;

            RectTransform rtPoblacion = panelPoblacion.GetComponent <RectTransform>();

            rtPoblacion.sizeDelta = new Vector2(rtPoblacion.sizeDelta.x, 0);
            alturaPoblacion       = 0;

            RectTransform rtComida = panelComida.GetComponent <RectTransform>();

            rtComida.sizeDelta = new Vector2(rtComida.sizeDelta.x, 0);
            alturaComida       = 0;

            RectTransform rtTiendas = panelTiendas.GetComponent <RectTransform>();

            rtTiendas.sizeDelta = new Vector2(rtTiendas.sizeDelta.x, 0);
            alturaTiendas       = 0;

            RectTransform rtIndustria = panelIndustria.GetComponent <RectTransform>();

            rtIndustria.sizeDelta = new Vector2(rtIndustria.sizeDelta.x, 0);
            alturaIndustria       = 0;

            foreach (Transform boton in panelDecoracion.gameObject.transform)
            {
                GameObject.Destroy(boton.gameObject);
            }

            foreach (Transform boton in panelCarreteras.gameObject.transform)
            {
                GameObject.Destroy(boton.gameObject);
            }

            foreach (Transform boton in panelPoblacion.gameObject.transform)
            {
                GameObject.Destroy(boton.gameObject);
            }

            foreach (Transform boton in panelComida.gameObject.transform)
            {
                GameObject.Destroy(boton.gameObject);
            }

            foreach (Transform boton in panelTiendas.gameObject.transform)
            {
                GameObject.Destroy(boton.gameObject);
            }

            foreach (Transform boton in panelIndustria.gameObject.transform)
            {
                GameObject.Destroy(boton.gameObject);
            }

            foreach (Construccion edificio in edificios)
            {
                bool añadir = true;

                if (edificio.categoria == 1)
                {
                    if ((edificio.id != 6) && (edificio.id != 12))
                    {
                        añadir = false;
                    }
                }

                if (añadir == true)
                {
                    GameObject botonObjeto = Instantiate(botonEdificiosPrefab);

                    if (edificio.categoria == 0)
                    {
                        botonObjeto.transform.SetParent(panelDecoracion.transform, false);
                        alturaDecoracionContador += 1;

                        if (alturaDecoracionContador == 1)
                        {
                            alturaDecoracion += 120;
                        }
                        else if (alturaDecoracionContador == 3)
                        {
                            alturaDecoracionContador = 0;
                        }
                    }
                    else if (edificio.categoria == 1)
                    {
                        botonObjeto.transform.SetParent(panelCarreteras.transform, false);
                        alturaCarreterasContador += 1;

                        if (alturaCarreterasContador == 1)
                        {
                            alturaCarreteras += 120;
                        }
                        else if (alturaCarreterasContador == 3)
                        {
                            alturaCarreterasContador = 0;
                        }
                    }
                    else if (edificio.categoria == 2)
                    {
                        botonObjeto.transform.SetParent(panelPoblacion.transform, false);
                        alturaPoblacionContador += 1;

                        if (alturaPoblacionContador == 1)
                        {
                            alturaPoblacion += 120;
                        }
                        else if (alturaPoblacionContador == 3)
                        {
                            alturaPoblacionContador = 0;
                        }
                    }
                    else if (edificio.categoria == 3)
                    {
                        botonObjeto.transform.SetParent(panelComida.transform, false);
                        alturaComidaContador += 1;

                        if (alturaComidaContador == 1)
                        {
                            alturaComida += 120;
                        }
                        else if (alturaComidaContador == 3)
                        {
                            alturaComidaContador = 0;
                        }
                    }
                    else if (edificio.categoria == 4)
                    {
                        botonObjeto.transform.SetParent(panelTiendas.transform, false);
                        alturaTiendasContador += 1;

                        if (alturaTiendasContador == 1)
                        {
                            alturaTiendas += 120;
                        }
                        else if (alturaTiendasContador == 3)
                        {
                            alturaTiendasContador = 0;
                        }
                    }
                    else if (edificio.categoria == 5)
                    {
                        botonObjeto.transform.SetParent(panelIndustria.transform, false);
                        alturaIndustriaContador += 1;

                        if (alturaIndustriaContador == 1)
                        {
                            alturaIndustria += 120;
                        }
                        else if (alturaIndustriaContador == 3)
                        {
                            alturaIndustriaContador = 0;
                        }
                    }

                    GameObject panelBoton = botonObjeto.transform.GetChild(0).gameObject;

                    Image imagen = panelBoton.transform.GetChild(0).transform.GetComponent <Image>();
                    imagen.sprite = edificio.botonImagen;

                    //-----------------------------------

                    Panel subpanelBoton = panelBoton.transform.GetChild(1).transform.GetComponent <Panel>();

                    Text coste = subpanelBoton.transform.GetChild(0).transform.GetComponent <Text>();
                    coste.text = string.Format("{0} €", edificio.coste);
                    Color colorTextoCoste = new Color();
                    ColorUtility.TryParseHtmlString(colorTextoRojo, out colorTextoCoste);
                    coste.color = colorTextoCoste;

                    Panel panelBotonComida = subpanelBoton.gameObject.transform.GetChild(1).transform.GetComponent <Panel>();

                    if (panelBotonComida != null)
                    {
                        if (edificio.comida != 0)
                        {
                            panelBotonComida.gameObject.SetActive(true);

                            Text comida = panelBotonComida.transform.GetChild(1).transform.GetComponent <Text>();
                            comida.text = string.Format("{0}", edificio.comida);
                            Color colorTexto = new Color();

                            if (edificio.comida > 0)
                            {
                                comida.text = string.Format("+{0}", comida.text);
                                ColorUtility.TryParseHtmlString(colorTextoVerde, out colorTexto);
                            }
                            else if (edificio.comida < 0)
                            {
                                ColorUtility.TryParseHtmlString(colorTextoRojo, out colorTexto);
                            }

                            comida.color = colorTexto;
                        }
                        else
                        {
                            panelBotonComida.gameObject.SetActive(false);
                        }
                    }

                    Panel panelBotonPoblacion = subpanelBoton.gameObject.transform.GetChild(2).transform.GetComponent <Panel>();

                    if (panelBotonPoblacion != null)
                    {
                        if (edificio.poblacion != 0)
                        {
                            panelBotonPoblacion.gameObject.SetActive(true);

                            Text poblacion = panelBotonPoblacion.transform.GetChild(1).transform.GetComponent <Text>();
                            poblacion.text = string.Format("{0}", edificio.poblacion);
                            Color colorTexto = new Color();

                            if (edificio.poblacion > 0)
                            {
                                poblacion.text = string.Format("+{0}", poblacion.text);
                                ColorUtility.TryParseHtmlString(colorTextoVerde, out colorTexto);
                            }
                            else if (edificio.poblacion < 0)
                            {
                                ColorUtility.TryParseHtmlString(colorTextoRojo, out colorTexto);
                            }

                            poblacion.color = colorTexto;
                        }
                        else
                        {
                            panelBotonPoblacion.gameObject.SetActive(false);
                        }
                    }

                    Panel panelBotonTrabajo = subpanelBoton.gameObject.transform.GetChild(3).transform.GetComponent <Panel>();

                    if (panelBotonTrabajo != null)
                    {
                        if (edificio.trabajo != 0)
                        {
                            panelBotonTrabajo.gameObject.SetActive(true);

                            Text trabajo = panelBotonTrabajo.transform.GetChild(1).transform.GetComponent <Text>();
                            trabajo.text = string.Format("{0}", edificio.trabajo);
                            Color colorTexto = new Color();

                            if (edificio.trabajo > 0)
                            {
                                trabajo.text = string.Format("+{0}", trabajo.text);
                                ColorUtility.TryParseHtmlString(colorTextoVerde, out colorTexto);
                            }
                            else if (edificio.trabajo < 0)
                            {
                                ColorUtility.TryParseHtmlString(colorTextoRojo, out colorTexto);
                            }

                            trabajo.color = colorTexto;
                        }
                        else
                        {
                            panelBotonTrabajo.gameObject.SetActive(false);
                        }
                    }

                    //-----------------------------------

                    Button boton = botonObjeto.GetComponent <Button>();
                    boton.onClick.AddListener(() => juego.ConstruirSeleccionarEdificio(edificio.id));

                    EventTrigger       evento       = botonObjeto.AddComponent <EventTrigger>();
                    EventTrigger.Entry pointerEnter = new EventTrigger.Entry
                    {
                        eventID = EventTriggerType.PointerEnter
                    };

                    pointerEnter.callback.AddListener((data) => { CursorEntraEdificioInferior((PointerEventData)data); });
                    evento.triggers.Add(pointerEnter);

                    EventTrigger.Entry pointerExit = new EventTrigger.Entry
                    {
                        eventID = EventTriggerType.PointerExit
                    };

                    pointerExit.callback.AddListener((data) => { CursorSaleEdificioInferior((PointerEventData)data); });
                    evento.triggers.Add(pointerExit);
                }
            }

            rtDecoracion.sizeDelta = new Vector2(rtDecoracion.sizeDelta.x, alturaDecoracion);
            rtCarreteras.sizeDelta = new Vector2(rtCarreteras.sizeDelta.x, alturaCarreteras);
            rtPoblacion.sizeDelta  = new Vector2(rtPoblacion.sizeDelta.x, alturaPoblacion);
            rtComida.sizeDelta     = new Vector2(rtComida.sizeDelta.x, alturaComida);
            rtTiendas.sizeDelta    = new Vector2(rtTiendas.sizeDelta.x, alturaTiendas);
            rtIndustria.sizeDelta  = new Vector2(rtIndustria.sizeDelta.x, alturaIndustria);
        }