コード例 #1
0
        public void SetInventory()
        {
            int dif = equipmentGrid.childCount - detective.GetMaxItemSlot();

            if (dif > 0)
            {
                for (int i = 0; i < dif; i++)
                {
                    Destroy(equipmentGrid.GetChild(equipmentGrid.childCount - 1 - i).gameObject);
                }
            }
            else if (dif < 0)
            {
                for (int i = 0; i < -dif; i++)
                {
                    Instantiate(inventoryIcon, equipmentGrid);
                }
            }
            for (int i = 0; i < detective.GetMaxItemSlot(); i++)
            {
                InventoryIcon icon = equipmentGrid.GetChild(i).GetComponent <InventoryIcon>();
                if (i < detective.GetMaxItemSlot() - detective.blockedSlots)
                {
                    if (i < detective.GetEquipment().Count)
                    {
                        icon.Redraw(detective.GetEquipment()[i].equipment, true);
                    }
                    else
                    {
                        icon.Redraw(null);
                    }
                }
                else
                {
                    icon.Redraw(null, false, true);
                }
            }
            dif = inventoryGrid.childCount - detective.GetItems().Count;
            if (dif > 0)
            {
                for (int i = 0; i < dif; i++)
                {
                    Destroy(inventoryGrid.GetChild(inventoryGrid.childCount - 1 - i).gameObject);
                }
            }
            else if (dif < 0)
            {
                for (int i = 0; i < -dif; i++)
                {
                    Instantiate(inventoryIcon, inventoryGrid);
                }
            }
            for (int i = 0; i < detective.GetItems().Count; i++)
            {
                InventoryIcon icon = inventoryGrid.GetChild(i).GetComponent <InventoryIcon>();
                icon.Redraw(detective.GetItems()[i]);
            }
        }