예제 #1
0
        private void InstantiateBagButton(InventoryBagUI bagUI)
        {
            // Spawn a button opening the given bagUI, name it like the bag and change its text so we can identify it
            Button bagButton = Instantiate(_bagButtonPrefab, _bagButtonHolder);

            bagButton.name = $"{bagUI.name} Button";
            bagButton.GetComponentInChildren <TextMeshProUGUI>().text = bagUI.name;

            // If the bag button gets clicked, show the respective bag, hide all others and update _lastOpenBagIndex
            bagButton.onClick.AddListener(() =>
            {
                foreach (InventoryBagUI inventoryBagUI in _inventoryBags)
                {
                    if (inventoryBagUI.Equals(bagUI))
                    {
                        inventoryBagUI.Show();
                        _lastOpenBagIndex = _inventoryBags.IndexOf(inventoryBagUI);
                    }
                    else
                    {
                        inventoryBagUI.Hide();
                    }
                }
            });
        }
예제 #2
0
 private void SpawnInventoryUI()
 {
     // Instantiate bags and their respective buttons according to inventory SO
     foreach (ItemBag itemBag in _inventory.Bags)
     {
         InventoryBagUI bagUI = InstantiateBagUI(itemBag);
         InstantiateBagButton(bagUI);
     }
 }
예제 #3
0
        private InventoryBagUI InstantiateBagUI(ItemBag itemBag)
        {
            // Spawn the InventoryBagUI resembling the given bag, set its name to the name of the bag so we can identify it
            InventoryBagUI bagUI = Instantiate(_bagUIPrefab, _bagHolder);

            bagUI.name = itemBag.BagName;

            // Add bag to list of all bags
            _inventoryBags.Add(bagUI);

            // configure bag initially
            bagUI.SetupForBag(itemBag);

            return(bagUI);
        }