public void CreatEmptyCells() { //Создаем пустые ячейки в которых затем будем отображать предметы NPC for (int i = 0; i < 25; i++) { GameObject newCell = Instantiate(itemCollectionCellPrefab); newCell.transform.SetParent(itemCollectionPanel.transform); ItemCollectionButton itemButton = newCell.transform.GetChild(0).GetComponent <ItemCollectionButton>(); if (itemButton != null) { itemButton.index = i; } } }
public void UpdateItemCollectionInterface() { for (int i = 0; i < itemCollectionPanel.transform.childCount; i++) { ItemCollectionButton itemButton = itemCollectionPanel.transform.GetChild(i).GetChild(0).GetComponent <ItemCollectionButton>(); if (itemButton != null) { itemButton.index = i; if (i > npc.gameItemList.Count - 1) { if (itemButton != null) { itemButton._gameItemRef = null; } itemCollectionPanel.transform.GetChild(i).GetChild(0).GetComponent <Image>().sprite = itemButton.emptyButtonSprite; itemCollectionPanel.transform.GetChild(i).GetChild(0).GetComponent <Image>().color = itemButton.emptyButtonColor; itemButton.transform.GetChild(0).GetChild(0).GetComponent <Text>().text = ""; continue; } else { //Установить картинку объекта itemCollectionPanel.transform.GetChild(i).GetChild(0).GetComponent <Image>().sprite = npc.gameItemList[i]._itemSprite; itemButton._gameItemRef = npc.gameItemList[i];//Установка связи между ячейкой и предметом itemButton.transform.GetChild(0).GetChild(0).GetComponent <Text>().text = ""; if (itemButton._gameItemRef._count > 0) { itemButton.transform.GetChild(0).GetChild(0).GetComponent <Text>().text = itemButton._gameItemRef._count.ToString(); } } //Делаем максимальную прозрачность ячейки Color buffColor = itemCollectionPanel.transform.GetChild(i).GetChild(0).GetComponent <Image>().color; Color newColor = new Color(buffColor.r, buffColor.g, buffColor.b, 255); itemCollectionPanel.transform.GetChild(i).GetChild(0).GetComponent <Image>().color = newColor; } } }