private void ShowRangeOnHover() { TroopPlaceholder temp = inventory.GetHighlightedUnit(); if (temp != null) { Vector3 mousePos = cam.ScreenToWorldPoint(Input.mousePosition); RaycastHit2D hit = Physics2D.Raycast(new Vector2(mousePos.x, mousePos.y), Vector2.zero, 0, TowerLayers); if (hit) { Vector3 center = hit.collider.gameObject.transform.position - new Vector3(0, 0.1f, 0); Debug.Log(center); ringObject.GetComponent <Renderer>().enabled = true; ringObject.transform.localScale = new Vector3(temp.Range * 2, temp.Range * 2, 0); ringObject.transform.position = center; Debug.Log(temp.Range); } else { ringObject.GetComponent <Renderer>().enabled = false; } } else { ringObject.GetComponent <Renderer>().enabled = false; } }
/// <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); }
// Will try to purchase a unit from the shop at the index given public void BuyTower(int index) { if (GameStats.Instance.GetCursorState() == CursorState.BuyingTower) { return; } if (currentShop[index] == TowerType.None) { return;// false; } if (!unitAssignment.IsInventoryFull()) { if (GameStats.Instance.PurchaseItemOfType(currentShop[index])) { // * add it to the inventory * TroopPlaceholder newTroop = new TroopPlaceholder(GameStats.Instance.TroopBaseData[currentShop[index]]); unitAssignment.AddTroop(newTroop); currentShop[index] = TowerType.None; uiManager.towerButtons[index].SetActive(false); //return true; } } }
public TroopPlaceholder GetHighlightedUnit() { if (highlightedIndex != -1) { TroopPlaceholder toReturn = inventory[highlightedIndex]; return(toReturn); } return(null); }
public void AssignUnit(TroopPlaceholder troop) { if (isUnitAssigned) { return; } isUnitAssigned = true; this.troop = troop; selfRenderer.sprite = troop.BattlefieldSprite; }
/// <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 (itemCount + 1 > maxInventorySize) { return(false); } inventory[itemCount] = troop; itemCount++; return(true); }
void Start() { emptyInvItem = new TroopPlaceholder(EmptyInvItem); highlightedIndex = -1; buttons = buttonParent.GetComponentsInChildren <Button>(); //maxInventorySize = buttons.Length; for (int i = 0; i < buttons.Length; i++) { inventory.Add(emptyInvItem); } }
public void UpdateInfo(TroopPlaceholder troop) { gameObject.SetActive(true); portrait.sprite = troop.InventorySprite; nameText.text = troop.TroopName; descriptionText.text = troop.Description; tierText.text = troop.tier.ToString(); rangeValueText.text = troop.Range.ToString(); damageValueText.text = troop.Damage.ToString(); asValueText.text = troop.AttackSpeed.ToString(); }
/// <summary> /// Removes and returns a troop at the given index /// </summary> /// <returns>the troop at the given index</returns> public TroopPlaceholder RemoveAtIndex(int index) { TroopPlaceholder toReturn = inventory[index]; inventory[index] = null; GameObject.Destroy(buttons[index]); buttons[index] = null; // Just clear the highlighted unit, just to be safe SetHighlightedUnit(-1); itemCount--; return(toReturn); }
public TroopPlaceholder RemoveUnit() { if (!isUnitAssigned) { return(null); } isUnitAssigned = false; TroopPlaceholder temp = troop; troop = null; selfRenderer.sprite = emptyTower; return(temp); }
/// <summary> /// pops the highlighted troop out /// </summary> /// <returns>the troop highlighted, if no troop is highlighted returns null</returns> public TroopPlaceholder PopHighlightedTroop() { if (highlightedIndex != -1) { TroopPlaceholder temp = inventory[highlightedIndex]; inventory.RemoveAt(highlightedIndex); inventory.Add(emptyInvItem); itemCount -= 1; outputLabel.text = ""; highlightedIndex = -1; return(temp); } return(null); }
public void CombineTroops() { if (highlightedIndex == -1) { return; } TroopPlaceholder temp = PopHighlightedTroop(); if (temp.tier < temp.MaxTier) { List <int> sameTypeIndex = new List <int>(); for (int i = 0; i < inventory.Length; i++) { if (inventory[i] == null) { continue; } if (inventory[i].data.TowerType == temp.data.TowerType && inventory[i].tier == temp.tier) { sameTypeIndex.Add(i); } } if (sameTypeIndex.Count > 1) { for (int i = 0; i < 2; i++) { RemoveAtIndex(sameTypeIndex[i]); } temp.TierUp(); } } AddTroop(temp); }
//public Color highlightedColor; public void SetTroop(TroopPlaceholder troop) { this.troop = troop; }
public static void UpdateInfoStatic(TroopPlaceholder troop) { instance.UpdateInfo(troop); }