private void InvSlotSetup(int i, Item item) { ItemSlotUI itemSlot = null; if (itemSlotPool.childCount > 0) { // Pull from pool itemSlot = itemSlotPool.GetChild(0).GetComponent <ItemSlotUI>(); itemSlot.transform.SetParent(invContent, false); } else { // Instantiate new entries itemSlot = Instantiate(itemSlotPrefab, invContent); } invSlotLookup[item.itemType] = itemSlot; // Supposed to separate camel case? string itemName = Regex.Replace(item.itemType.ToString(), "(//B[A-Z])", "$1 "); itemSlot.SetupItemEntry(item.icon, itemName, item.amount, false); // Position slot in content window itemSlot.transform.localPosition = new Vector2(itemSlot.transform.localPosition.x, i * -itemSpacing); itemSlot.gameObject.SetActive(true); }
// Loop through ShopItemsDB and set up item slots for each entry private void SetupShopMenuSlots() { int i = 0; ItemSlotUI itemSlot = null; foreach (Item.ItemType itemType in shopItemsDB.GetItems()) { if (itemSlotPool.childCount > 0) { // Pull from pool itemSlot = itemSlotPool.GetChild(0).GetComponent <ItemSlotUI>(); itemSlot.transform.SetParent(shopContent, false); } else { // Instantiate new entries itemSlot = Instantiate(itemSlotPrefab, shopContent); } // Add listener for buy button Button slotButton = itemSlot.GetButton(); slotButton.onClick.RemoveAllListeners(); int itemCost = shopItemsDB.GetItemCost(i); slotButton.onClick.AddListener(() => BuyItem(itemType, itemCost)); // Supposed to separate camel case? string itemName = Regex.Replace(itemType.ToString(), "(//B[A-Z])", " $1"); itemSlot.SetupItemEntry(itemIconDB.GetSprite(itemType), itemName, itemCost, true); // Position slot in content window itemSlot.transform.localPosition = new Vector2(itemSlot.transform.localPosition.x, i * -itemSpacing); itemSlot.gameObject.SetActive(true); i++; // Resize shop menu int contentHeight = i * itemSpacing; shopContent.sizeDelta = new Vector2(shopContent.sizeDelta.x, contentHeight); } }