Inventory.addItemToInventory C# (CSharp) Method

addItemToInventory() public method

public addItemToInventory ( int id, UInt64 itemUUID, int value ) : GameObject
id int
itemUUID UInt64
value int
return GameObject
    public GameObject addItemToInventory(int id, UInt64 itemUUID, int value)
    {
        for (int i = 0; i < SlotContainer.transform.childCount; i++)
        {
            if (SlotContainer.transform.GetChild(i).childCount == 0)
            {
                GameObject item = (GameObject)Instantiate(prefabItem);
                ItemOnObject itemOnObject = item.GetComponent<ItemOnObject>();
                itemOnObject.item = itemDatabase.getItemByID(id);
                itemOnObject.item.itemUUID = itemUUID;
                if (itemOnObject.item.itemValue <= itemOnObject.item.maxStack && value <= itemOnObject.item.maxStack)
                    itemOnObject.item.itemValue = value;
                else
                    itemOnObject.item.itemValue = 1;
                item.transform.SetParent(SlotContainer.transform.GetChild(i));
                item.GetComponent<RectTransform>().localPosition = Vector3.zero;
                item.transform.GetChild(0).GetComponent<Image>().sprite = itemOnObject.item.itemIcon;
                itemOnObject.item.indexItemInList = ItemsInInventory.Count - 1;
                if (inputManagerDatabase == null)
                    inputManagerDatabase = (InputManager)Resources.Load("InputManager");
                return item;
            }
        }

        stackableSettings();
        updateItemList();
        return null;
    }

Same methods

Inventory::addItemToInventory ( int itemId, UInt64 itemUUID, int value, int itemIndex ) : GameObject
Inventory::addItemToInventory ( int id, int value ) : GameObject
Inventory::addItemToInventory ( int id ) : void
Inventory::addItemToInventory ( int ignoreSlot, int itemID, int itemValue ) : void

Usage Example

コード例 #1
0
    public void clickInventoryItem(int slotnumber, Inventory toInventory)
    {
        // TRANSFER TO BUILDING INVENTORY
        if (gameManager.getBuildingCatalog().getBuildingLastClicked() != null)
        {
            if (gameManager.GetUI().getBuildingInventoryOpen() && this.getInventorySlot(slotnumber).currentAmountInSlot != 0)
            {
                if (gameManager.getBuildingCatalog().getBuildingLastClickedAttributes().getPlayerEnteredBuilding())
                {
                    int amountToRemove = toInventory.addItemToInventory(this.getInventorySlot(slotnumber).getItemInSlot(), this.getInventorySlot(slotnumber).getCurrentAmountInSlot());
                    removeAmountFromSpecificSlot(this.getInventorySlot(slotnumber), this.getInventorySlot(slotnumber).getCurrentAmountInSlot() - amountToRemove);
                    updateInventoryInterface();
                }
                else
                {
                    gameManager.getMessageLogText().addMessageToLog("The player needs to be inside the building in order to transfer items to building inventory");
                }
            }
        }

        // TRANSFER TO UNFINISHED BUILDING
        if (gameManager.getBuildingCatalog().getUnfinishedBuildingSelected() != null)
        {
            if (gameManager.GetUI().getUnfinishedBuildingOpen() && this.getInventorySlot(slotnumber).currentAmountInSlot != 0)
            {
                // TODO: if statement that prohbit player from transfering if to far away
                int amountToRemove = toInventory.addItemToInventory(this.getInventorySlot(slotnumber).getItemInSlot(), this.getInventorySlot(slotnumber).getCurrentAmountInSlot());
                removeAmountFromSpecificSlot(this.getInventorySlot(slotnumber), this.getInventorySlot(slotnumber).getCurrentAmountInSlot() - amountToRemove);
                updateInventoryInterface();
            }
        }

        // TRANSFER TO CITIZEN
        if (gameManager.getCitizenCatalog().getSelectedCitizen() != null)
        {
            if (gameManager.GetUI().getCitizenInventoryOpen() && this.getInventorySlot(slotnumber).currentAmountInSlot != 0)
            {
                // TODO: if statement that prohbit player from transfering if to far away
                int amountToRemove = toInventory.addItemToInventory(this.getInventorySlot(slotnumber).getItemInSlot(), this.getInventorySlot(slotnumber).getCurrentAmountInSlot());
                removeAmountFromSpecificSlot(this.getInventorySlot(slotnumber), this.getInventorySlot(slotnumber).getCurrentAmountInSlot() - amountToRemove);
                updateInventoryInterface();
            }
        }

        // TRANSFER TO TOOLBAR
        if (!gameManager.GetUI().getCitizenInventoryOpen() && !gameManager.GetUI().getUnfinishedBuildingOpen() && !gameManager.GetUI().getBuildingInventoryOpen() && this.getInventorySlot(slotnumber).currentAmountInSlot != 0)
        {
            //if(gameManager.getPlayerBehavior().getPerkattributes().getPerksByName(this.getInventorySlot(slotnumber).getItemInSlot()) != null){
            gameManager.getPlayerBehavior().getToolbelt().addToSlot(this.getInventorySlot(slotnumber));
            updateInventoryInterface();
            //} else {
            //Debug.Log("Dont have the perk associated with that item");
            //}
        }
        if (gameManager.GetUI().getInventoryOpen() && gameManager.GetUI().getEquipmentOpen() && this.getInventorySlot(slotnumber).currentAmountInSlot != 0)
        {
            gameManager.getPlayerBehavior().getToolbelt().addToSlot(this.getInventorySlot(slotnumber));
            updateInventoryInterface();
        }
    }
All Usage Examples Of Inventory::addItemToInventory