コード例 #1
0
ファイル: Inventory.cs プロジェクト: JTB6154/320-Project-2
    /// <summary>
    /// Takes in a troop to be added to the inventory
    /// </summary>
    /// <param name="troop">The troop that is sent to the inventory</param>
    /// <returns>if the troop could be added to the inventory</returns>
    public bool AddTroop(TroopPlaceholder troop)
    {
        if (IsInventoryFull())
        {
            return(false);
        }

        // Find the next available slot in the inventory
        int newSlot = GetAvailableSlot();

        if (newSlot == -1)
        {
            return(false);
        }

        // Add it to Inventory Grid
        GameObject newInventoryItemGO = GameObject.Instantiate(inventoryGridUnit, buttonParent.transform);

        newInventoryItemGO.SetActive(true);
        buttons[newSlot] = newInventoryItemGO;
        InventoryUIUnit newInventoryUnit = newInventoryItemGO.GetComponent <InventoryUIUnit>();

        newInventoryUnit.index = newSlot;
        newInventoryUnit.troop = troop;
        newInventoryUnit.UpdateUI();

        InfoWindow.ClearStatic();


        inventory[newSlot] = troop;
        itemCount++;
        return(true);
    }