Ejemplo n.º 1
0
    /// <summary>
    /// This method figures out and sets the correct sprite image based on the resource to buy
    /// </summary>
    /// <param name="resourceToBuy"></param>
    void SetItemSprite(BuyResources.ResourcesList resourceToBuy)
    {
        Sprite currentItemImage = null;

        switch (resourceToBuy)
        {
        case BuyResources.ResourcesList.CASH:
            currentItemImage = spriteManager.CoinImage;
            break;

        case BuyResources.ResourcesList.CRYSTAL:
            currentItemImage = spriteManager.CrystalImage;
            break;

        case BuyResources.ResourcesList.CRATES:
            currentItemImage = spriteManager.CrateImage;
            break;

        default:
            currentItemImage = spriteManager.MissingImage;
            break;
        }

        itemImage.sprite = currentItemImage;
    }
Ejemplo n.º 2
0
    void Start()
    {
        spriteManager = FindObjectOfType <SpriteManager>();

        buyResourceScript = GetComponent <BuyResources>();
        buyItemButton     = GetComponentInChildren <Button>();

        itemDescriptionText = GetComponentInChildren <Text>();
        itemImage           = transform.Find(gameObjectNameWithImage).gameObject.GetComponent <Image>();

        resourceRequired = buyResourceScript.resourceRequired;
        resourceToBuy    = buyResourceScript.resourceToBuy;

        buyQuantity      = buyResourceScript.QuantityToBuy;
        quantityRequired = buyResourceScript.RequiredQuantity;

        string formattedDescription = string.Format(itemDescriptionTemplate, buyQuantity, resourceToBuy);
        string formattedButtonText  = string.Format(buttonTextTemplate, quantityRequired, resourceRequired);

        SetItemDescription(formattedDescription);
        SetItemSprite(resourceToBuy);
        SetButtonText(formattedButtonText);
    }