Exemple #1
0
    void GenerateShopItemsUI()
    {
        for (int i = 0; i < GameDataManager.GetAllPurchasedThemes().Count; i++)
        {
            int purchasedThemeIndex = GameDataManager.GetPurchasedTheme(i);
            themeDB.PurchaseTheme(purchasedThemeIndex);
        }


        itemHeight = shopItemsContainer.GetChild(0).GetComponent <RectTransform>().sizeDelta.y;
        Destroy(shopItemsContainer.GetChild(0).gameObject);

        shopItemsContainer.DetachChildren();

        for (int i = 0; i < themeDB.ThemesCount; i++)
        {
            Theme      theme  = themeDB.GetTheme(i);
            ShopItemUI uiItem = Instantiate(itemPrefab, shopItemsContainer).GetComponent <ShopItemUI>();

            uiItem.SetItemPosition(Vector2.down * i * (itemHeight + itemSpacing));
            uiItem.gameObject.name = "Theme " + i + "-" + theme.name;

            uiItem.SetThemeName(theme.name);
            uiItem.SetThemeImage(theme.image);
            uiItem.SetPriceText(theme.price);

            if (theme.isPurchased)
            {
                uiItem.SetThemeAsPurchased();
                uiItem.OnItemSelect(i, OnItemSelected);
            }
            else
            {
                uiItem.SetPriceText(theme.price);
                uiItem.OnItemPurchase(i, OnItemPurchased);
            }

            shopItemsContainer.GetComponent <RectTransform>().sizeDelta = Vector2.up * (itemHeight + itemSpacing) * themeDB.ThemesCount;
        }
    }