public void Initialise(int index, IconData data, int userLevel, bool selected, Action iconPressed) { this.dataIndex = index; this.backgroundImage.color = selected ? this.selectedColor : this.defaultColor; this.iconImage.sprite = data.iconSprite; if (data.purchased) { this.lockImage.gameObject.SetActive(false); this.levelImage.gameObject.SetActive(false); this.coinsImage.gameObject.SetActive(false); this.iconPressedAction = iconPressed; return; } if (userLevel < data.requiredLevel) { this.lockImage.gameObject.SetActive(true); this.levelImage.gameObject.SetActive(true); this.levelTMP.text = "Level " + data.requiredLevel; this.coinsImage.gameObject.SetActive(false); } else { this.lockImage.gameObject.SetActive(false); this.levelImage.gameObject.SetActive(false); this.coinsImage.gameObject.SetActive(true); this.coinsTMP.text = data.price.ToString(); this.iconPressedAction = iconPressed; } }
private void BuyItem(StoreCategory category, int index) { CategoryData categoryData = this.cosmeticData.categories.FindFirst(data => data.category == category); IconData iconData = categoryData.icons[index]; if (!iconData.purchased && iconData.requiredLevel <= GameManager.UserLevel && iconData.price <= GameManager.UserCoins) { GameManager.UserCoins -= iconData.price; iconData.purchased = true; this.InitialiseCategory(category); } }
private void InitialiseCategory(StoreCategory category) { CategoryData categoryData = this.cosmeticData.categories.FindFirst(data => data.category == category); this.DestroyAllChildren(); this.iconControllers.Clear(); int selectedInCategory = category == StoreCategory.Eyes ? this.selectedEyes : category == StoreCategory.Mouths ? this.selectedMouth : this.selectedOutfit; GameEventInt categoryEvent = category == StoreCategory.Eyes ? this.selectEyes : category == StoreCategory.Mouths ? this.selectMouth : this.selectOutfit; for (int index = 0; index < categoryData.icons.Length; index++) { IconController controller = Object.Instantiate(this.iconContainerPrefab, this.transform) .GetComponent <IconController>(); int localIndex = index; bool itemSelected = index == selectedInCategory; IconData iconData = categoryData.icons[localIndex]; void IconAction() { if (itemSelected) { return; } if (iconData.purchased) { this.SelectInCategory(category, localIndex); categoryEvent.Raise(localIndex); this.InitialiseCategory(category); return; } this.BuyItem(category, localIndex); } controller.Initialise(localIndex, iconData, GameManager.UserLevel, itemSelected, IconAction); } }