public void SetupCells() { // Destroy all existing cells foreach (StoreItemCell cell in existingCells) { Destroy(cell.gameObject); } existingCells.Clear(); // If game manager exists then instantiate a cell for each item if (GameManager.Instance) { // Select items with the given category IEnumerable <LevelData.ItemData> itemsWithCategory = GameManager.Instance.LevelData.itemQuantities .Where(item => item.itemObject.ItemID.Category == groupPicker.FirstValuePicked); // For each item, create a new cell, initialize it, and add it to the list foreach (LevelData.ItemData itemData in itemsWithCategory) { StoreItemCell cell = Instantiate(itemCellPrefab, cellParent); // Initialize the cell instance cell.Initialize(itemData.itemObject, true, itemClickedEvent.Invoke); cell.RemainingAmount = GameManager.Instance.m_resourceManager.CheckRemainingResource(itemData.itemObject); existingCells.Add(cell); } } }
void InstantiateItemsPrefabs() { //Instantiate power-ups for (int p = 0; p < Data.StorePowerups.Length; p++) { GameObject GO = Instantiate(ItemPrefab); GO.transform.SetParent(ItemsParent, false); StoreItemCell Cell = GO.GetComponent <StoreItemCell>(); Cell.Initialize(this, Data.StorePowerups[p]); } }
/// <summary> /// Add item to the section. /// </summary> public void AddItem(Item item) { GameObject newItemCellGO = Instantiate(itemCellPrefab, itemGrid); StoreItemCell itemCell = newItemCellGO.GetComponent <StoreItemCell>(); itemCell.Initialize(item, false, OnItemSelected); if (this.ResourceManager.hasLimitedSupply(item.ItemName)) { this.ResourceManager.setupItemSupplyTracker(itemCell); if (!storeItems.ContainsKey(item)) { storeItems.Add(item, itemCell); } } }