/// <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); }
public void SetHighlightedUnit(int troopIndex) { // Deselect if (highlightedIndex == troopIndex) { highlightedIndex = -1; for (int i = 0; i < buttons.Length; i++) { if (buttons[i] == null) { continue; } InventoryUIUnit uiUnit = buttons[i].GetComponent <InventoryUIUnit>(); uiUnit.isHighlighted = false; uiUnit.UpdateUI(); } } // select else { highlightedIndex = troopIndex; for (int i = 0; i < buttons.Length; i++) { if (buttons[i] == null) { continue; } InventoryUIUnit uiUnit = buttons[i].GetComponent <InventoryUIUnit>(); if (uiUnit.index != troopIndex) { uiUnit.isHighlighted = false; } else { uiUnit.isHighlighted = true; } uiUnit.UpdateUI(); } } }