/// <summary> /// The active faction must have at least one /// unit alive to make a selection. /// </summary> private bool CanSelect() { SelectableUnits.Clear(); // Used to add units without a turn to the end of the // selectable units list such that they appear last // in the menu. List <Unit> unitsWithoutTurn = new List <Unit>(); foreach (var unit in GameState.ActiveFaction.Units) { if (unit.Alive && unit != GameState.ActiveUnit) { if (unit.HasTurn) { SelectableUnits.Add(unit); } else { unitsWithoutTurn.Add(unit); } } } // Append units without a turn to the selectable units. SelectableUnits.AddRange(unitsWithoutTurn); return(SelectableUnits.Count > 0); }
bool IsSelectable() { GameObject unitParent = _hitGo.transform.parent.gameObject; bool isSelectableUnit = SelectableUnits.Contains(unitParent); bool isSelectableBuilding = SelectableBuildings.Contains(unitParent); if (isSelectableBuilding || isSelectableUnit) { return(true); } return(false); }
public void SelectUnitsInBox(Rect selectionRect) { if (UiRaycast.IsRaycastingToUi()) { return; } DeselectBuilding(); if (!Input.GetKey(KeyCode.LeftControl) && !_selectedBuilding) { DeselectAllUnits(); } SelectableUnits.RemoveAll(unit => unit == null); foreach (GameObject iUnit in SelectableUnits) { Vector3 unitVpos = Camera.main.WorldToViewportPoint(iUnit.transform.position); bool isUnitInRect = selectionRect.Contains(unitVpos, true); if (isUnitInRect) { SelectUnit(iUnit.GetComponent <Unit>()); UpdateSelectedUnits(); } } }
IEnumerator AiState() { yield return(new WaitForSeconds(5)); SelectableUnits.ForEach(u => u.GetComponent <Unit>().Select()); }
public void AddSelectableUnit(UnitController unit) { SelectableUnits.Add(unit.unitId, unit); }