Ejemplo n.º 1
0
 /// <summary>
 /// Sets the current item according to the data from storage.
 /// This method is called shopManager while populating the shop list in UI
 /// </summary>
 /// <param name="_skin">item data.</param>
 public void setItem(ShopItemData _skin)
 {
     itemData = _skin;
     thumbNailImage.sprite = _skin.thumbnail;
     costText.text         = _skin.cost.ToString();
     toggleLock(_skin.isLocked);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Populates the shop list in UI. Sets the unlocked items and the last selected.
        /// </summary>
        public void InitShopList()
        {
            availableCash   = Getcash();
            unlockedItemIDs = GetUnlockedItemIDs();
            selectedItemID  = GetSelectedItemID();

            //Get the default list typcasted in base data class(ItemData). We don't require the extra properties in the derived data class.
            List <ShopItemData> items = GetDefaultList().ConvertAll(x => (ShopItemData)x);

            //Populating the Shop list UI
            for (int i = 0; i < items.Count; i++)
            {
                GameObject shopItem = (GameObject)Instantiate(shopItemPrefab, container.transform, false);

                ShopItemData itemData = items[i];

                //Set itemData and click listener for every item
                shopItem.GetComponent <ShopItem>().setItem(itemData);
                shopItem.GetComponentInChildren <Button>().onClick.AddListener(delegate
                {
                    selectItem(shopItem.GetComponent <ShopItem>());
                });

                //If this Item ID exists in unlockedItemIDs list, remove lock
                if (unlockedItemIDs.Exists(x => x == itemData.ID))
                {
                    shopItem.GetComponent <ShopItem>().toggleLock(false);
                }

                //If it is equal to selectedItemID, set it as selected
                if (items[i].ID == selectedItemID)
                {
                    shopItem.GetComponent <ShopItem>().toggleselection(true);
                    selectedShopItem = shopItem.GetComponent <ShopItem>();
                }
            }

            shopItemsInitialised();
        }