Exemplo n.º 1
0
    // Use this for initialization
    void Start()
    {
        onChange = false;

        collapseGroup = gameObject.GetComponent <UICollapseGroup>();

        if (null != collapseGroup)
        {
            collapseGroup.initializeGroup();
        }

        heightParent = gameObject.GetComponent <RectTransform>().rect.height;
        witdhParent  = gameObject.GetComponent <RectTransform>().rect.width;

        GameObject panelTitre = UIUtils.createPanelAnchorCenterHigh("Titre_UICollapseElement", gameObject, ancreSuperieur.x, ancreSuperieur.y, witdhParent, tailleTitre);

        rectTitre     = panelTitre.GetComponent <RectTransform> ();
        txtTitre      = UIUtils.createTextStretch("Titre_Texte_UICollapseElement", panelTitre, (int)(rectTitre.sizeDelta.y * .75f / 2), 5, 5, 5, 5);
        txtTitre.text = titre;

        //On ancre le panel de description au centre en haut à la limite du panel titre
        GameObject panelDescription = UIUtils.createPanelAnchorCenterHigh("Description_UICollapseElement", gameObject, ancreSuperieur.x, ancreSuperieur.y - tailleTitre, witdhParent, collapse? 0 : tailleDescription);

        rectDescription = panelDescription.GetComponent <RectTransform> ();

        //On ancre le text au centre et avec une hauteur extensible
        txtDescription          = UIUtils.createTextStretch("Description_Texte_UICollapseElement", rectDescription.gameObject, (int)(rectDescription.sizeDelta.y * .75f / 5), 5, 5, 5, 5);
        txtDescription.text     = description;
        txtDescription.fontSize = (int)(tailleDescription * 3 / 20);
        //Distance entre borne parent et enfant
        //Rect rect
        //rectTxtDescription.yMin = 5;
        //rectTxtDescription.rect.yMax = 5;

        GameObject buttonGO = UIUtils.createPanel("Button_UICollapseElement", panelTitre, witdhParent * 3 / 8, 0, witdhParent / 8, tailleTitre / 2);

        buttonAction = buttonGO.AddComponent <Button> ();
        buttonAction.onClick.AddListener(collapseChange);
    }
Exemplo n.º 2
0
    //TODO utilsé l'id de la carte pour le nommage des objet
    public DesignCarteConstructionV2(GameObject goParent, float height, float width, int nbNiveau, Joueur joueurClick)
    {
        this.goParent       = goParent;
        this.joueurCliquant = joueurClick;

        GameObject paternBoutonCancel = UIUtils.createPanel("BoutonFermeture", goParent,
                                                            width * (ConstanteInGame.propBoutonRetour.x - 0.5f), height * (0.5f - ConstanteInGame.propBoutonRetour.y),
                                                            width * ConstanteInGame.propBoutonRetour.z, height * ConstanteInGame.propBoutonRetour.w);

        paternBoutonCancel.GetComponent <Image> ().sprite = ConstanteInGame.spriteCroixCancel;
        Button buttonFermeture = paternBoutonCancel.AddComponent <Button> ();

        buttonFermeture.onClick.AddListener(deleteVisual);

        txtTitre = UIUtils.createText("Titre", goParent, 1,
                                      width * (ConstanteInGame.propDesignTitre.x - 0.5f), height * (0.5f - ConstanteInGame.propDesignTitre.y),
                                      width * ConstanteInGame.propDesignTitre.z, height * ConstanteInGame.propDesignTitre.w);

        imageCarte = UIUtils.createImage(null, "Image", goParent,
                                         width * (ConstanteInGame.propDesignImage.x - 0.5f), height * (0.5f - ConstanteInGame.propDesignImage.y),
                                         width * ConstanteInGame.propDesignImage.z, height * ConstanteInGame.propDesignImage.w);

        //Creation bloc des ressources
        float widthRessource  = width * ConstanteInGame.propDesignRessource.z;
        float heightRessource = height * ConstanteInGame.propDesignRessource.w;

        GameObject paternRessource = UIUtils.createPanel("Ressource", goParent,
                                                         width * (ConstanteInGame.propDesignRessource.x - 0.5f), height * (0.5f - ConstanteInGame.propDesignRessource.y),
                                                         widthRessource, heightRessource);

        GameObject paternRessourceMetal = UIUtils.createPanel("RessourceMetal", paternRessource,
                                                              widthRessource * (ConstanteInGame.propDesignMetalRessource.x - 0.5f), heightRessource * (0.5f - ConstanteInGame.propDesignMetalRessource.y),
                                                              widthRessource * ConstanteInGame.propDesignMetalRessource.z, heightRessource * ConstanteInGame.propDesignMetalRessource.w);

        txtMetal = UIUtils.createText("textMetal", paternRessourceMetal, 1, 0, 0,
                                      .9f * widthRessource * ConstanteInGame.propDesignMetalRessource.z, heightRessource * ConstanteInGame.propDesignMetalRessource.w);

        GameObject paternRessourceNiveauActuel = UIUtils.createPanel("RessourceNiveauActuel", paternRessource,
                                                                     widthRessource * (ConstanteInGame.propDesignNiveauRessource.x - 0.5f), heightRessource * (0.5f - ConstanteInGame.propDesignNiveauRessource.y),
                                                                     widthRessource * ConstanteInGame.propDesignNiveauRessource.z, heightRessource * ConstanteInGame.propDesignNiveauRessource.w);

        txtNiveauActuel = UIUtils.createText("textNiveauActuel", paternRessourceNiveauActuel, 1, 0, 0,
                                             .9f * widthRessource * ConstanteInGame.propDesignNiveauRessource.z, heightRessource * ConstanteInGame.propDesignNiveauRessource.w);

        paternRessourceCarburant = UIUtils.createPanel("RessourceCarburant", paternRessource,
                                                       widthRessource * (ConstanteInGame.propDesignCarburantRessource.x - 0.5f), heightRessource * (0.5f - ConstanteInGame.propDesignCarburantRessource.y),
                                                       widthRessource * ConstanteInGame.propDesignCarburantRessource.z, heightRessource * ConstanteInGame.propDesignCarburantRessource.w);
        txtCarburant = UIUtils.createText("textCarburant", paternRessourceCarburant, 1, 0, 0,
                                          .9f * widthRessource * ConstanteInGame.propDesignCarburantRessource.z, heightRessource * ConstanteInGame.propDesignCarburantRessource.w);

        GameObject paternListNiveaux = UIUtils.createPanel("ListNiveaux", goParent,
                                                           width * (ConstanteInGame.propDesignListNiveaux.x - 0.5f), height * (0.5f - ConstanteInGame.propDesignListNiveaux.y),
                                                           width * ConstanteInGame.propDesignListNiveaux.z, height * ConstanteInGame.propDesignListNiveaux.w);

        collapseGroup = paternListNiveaux.AddComponent <UICollapseGroup> ();
        List <UICollapseElement> listCollapseElement = new List <UICollapseElement> ();

        for (int i = 0; i < nbNiveau; i++)
        {
            UICollapseElement collapseElement = paternListNiveaux.AddComponent <UICollapseElement> ();
            collapseElement.TailleTitre        = 50;
            collapseElement.TailleDescription  = 75;
            collapseElement.TempsDecompression = 3;
            listCollapseElement.Add(collapseElement);
        }

        collapseGroup.ListCollapseElement = listCollapseElement;


        GameObject paternBouton = UIUtils.createPanel("BoutonAction", goParent,
                                                      width * (ConstanteInGame.propDesignBouton.x - 0.5f), height * (0.5f - ConstanteInGame.propDesignBouton.y),
                                                      width * ConstanteInGame.propDesignBouton.z, height * ConstanteInGame.propDesignBouton.w);
        Button buttonAction = paternBouton.AddComponent <Button> ();


        paternPA = UIUtils.createPanel("PointAttaque", goParent,
                                       width * (ConstanteInGame.propDesignPointAttaque.x - 0.5f), height * (0.5f - ConstanteInGame.propDesignPointAttaque.y),
                                       width * ConstanteInGame.propDesignPointAttaque.z, height * ConstanteInGame.propDesignPointAttaque.w);
        txtPointAttaque = UIUtils.createText("textPA", paternPA, 1, 0, 0,
                                             .9f * width * ConstanteInGame.propDesignPointAttaque.z, height * ConstanteInGame.propDesignPointAttaque.w);

        GameObject paternPD = UIUtils.createPanel("PointDefense", goParent,
                                                  width * (ConstanteInGame.propDesignPointDefense.x - 0.5f), height * (0.5f - ConstanteInGame.propDesignPointDefense.y),
                                                  width * ConstanteInGame.propDesignPointDefense.z, height * ConstanteInGame.propDesignPointDefense.w);

        txtPointDefense = UIUtils.createText("textPD", paternPD, 1, 0, 0,
                                             .9f * width * ConstanteInGame.propDesignPointDefense.z, height * ConstanteInGame.propDesignPointDefense.w);
    }