コード例 #1
0
    /// <summary>
    /// Grise les boutons des unités si le joueur n'a pas les fonds
    /// </summary>
    public void darkenUnavailable()
    {
        Color32 grey             = new Color32(128, 128, 128, 128);
        Color32 transparent      = new Color32(0, 0, 0, 0);
        int     fonds            = joueur.Credits;
        bool    canBuyNavalUnits = joueur.CanBuyNavalUnits();

        // Le joueur peut-il acheter l'unité ? bouton grisé : bouton transparent
        shopSelections[0].GetComponent <Image>().color = fonds - total < Utils.GetUnitPrice((int)Utils.unitCode.Infanterie) ? grey : transparent;
        shopSelections[1].GetComponent <Image>().color = fonds - total < Utils.GetUnitPrice((int)Utils.unitCode.Tank) ? grey : transparent;
        shopSelections[2].GetComponent <Image>().color = fonds - total < Utils.GetUnitPrice((int)Utils.unitCode.Artillerie) ? grey : transparent;
        shopSelections[3].GetComponent <Image>().color = fonds - total < Utils.GetUnitPrice((int)Utils.unitCode.DCA) ? grey : transparent;
        shopSelections[6].GetComponent <Image>().color = fonds - total < Utils.GetUnitPrice((int)Utils.unitCode.Bombardier) ? grey : transparent;

        // Pour le croiseur, il faut vérifier si le joueur a les fonds et qu'un des territoires du joueur est connecté à une route libre ou occupée
        // par le joueur
        if (fonds - total > Utils.GetUnitPrice((int)Utils.unitCode.Croiseur) && canBuyNavalUnits)
        {
            shopSelections[4].GetComponent <Image>().color = transparent;
        }
        else
        {
            shopSelections[4].GetComponent <Image>().color = grey;
        }

        // De même pour le sous-marin
        if (fonds - total < Utils.GetUnitPrice((int)Utils.unitCode.Submarin) && canBuyNavalUnits)
        {
            shopSelections[5].GetComponent <Image>().color = grey;
        }
        else
        {
            shopSelections[5].GetComponent <Image>().color = transparent;
        }
    }