Beispiel #1
0
    public void addNewItemSlotPanel()
    {
        GameObject newItemSlotPanel = Instantiate(itemSlotsPanelPrefab, transform.position, transform.rotation);

        newItemSlotPanel.transform.SetParent(itemsParent);
        newItemSlotPanel.transform.localScale = new Vector3(1, 1, 1);
        ItemSlotsPanel isp = newItemSlotPanel.GetComponent <ItemSlotsPanel>();

        for (int i = 0; i < column; i++)
        {
            itemSlots.Add(isp.itemSlots[i]);
        }

        scrollPanel.GetComponent <ScrollRect>().enabled = true;
        inventoryType.refreshUIByClickButton();
    }
Beispiel #2
0
    public void setItemSlots()
    {
        if (itemsParent != null)
        {
            itemSlotsPanel = itemsParent.GetComponentsInChildren <ItemSlotsPanel>().ToList();
        }

        for (int i = 0; i < itemSlotsPanel.Count; i++)
        {
            for (int j = 0; j < column; j++)
            {
                itemSlots.Add(itemSlotsPanel[i].itemSlots[j]);
            }
        }

        int totalSlotNum = itemSlotsPanel.Count * 3;

        if (items.Count > totalSlotNum)
        {
            int leftItems = items.Count - column * row;
            int newPanel  = leftItems / column;
            newPanel = (leftItems % column == 0) ? newPanel : newPanel + 1;
            for (int i = 0; i < newPanel; i++)
            {
                GameObject newItemSlotPanel = Instantiate(itemSlotsPanelPrefab, transform.position, transform.rotation);
                newItemSlotPanel.transform.SetParent(itemsParent);
                newItemSlotPanel.transform.localScale = new Vector3(1, 1, 1);
                ItemSlotsPanel isp = newItemSlotPanel.GetComponent <ItemSlotsPanel>();
                itemSlotsPanel.Add(isp);

                for (int j = 0; j < column; j++)
                {
                    itemSlots.Add(isp.itemSlots[j]);
                }
            }
            scrollPanel.GetComponent <ScrollRect>().enabled = true;
        }
    }