public Unit PrevTarget() { var index = VisibleUnits.IndexOf(ActiveUnit.ActiveTarget); var _targetType = ActiveUnit.ActiveTarget.targetType; if (index > 0) { for (int i = index - 1; i >= 0; i--) { var _Target = VisibleUnits [i]; if (_Target.targetType == _targetType) { return(_Target); } } for (int i = VisibleUnits.Count() - 1; i > index; i--) { var _Target = VisibleUnits [i]; if (_Target.targetType == _targetType) { return(_Target); } } } return(getClosestTarget(_targetType)); }
public Unit getClosestTarget(TargetType _targetType) { for (int i = 0; i < VisibleUnits.Count(); i++) { var _Target = VisibleUnits [i]; if (_Target.targetType == _targetType) { return(_Target); } } return(null); }
public Unit NextTarget() { var index = VisibleUnits.IndexOf(ActiveUnit.ActiveTarget); var _targetType = ActiveUnit.ActiveTarget.targetType; if (index < VisibleUnits.Count() - 1) { for (int i = index + 1; i < VisibleUnits.Count(); i++) { var _Target = VisibleUnits [i]; if (_Target.targetType == _targetType) { return(_Target); } } } return(getClosestTarget(_targetType)); }
protected void UpdateVision(float deltaTime, Unit[] targetedUnits) { foreach (var opponent in targetedUnits) { bool visible = false; foreach (var unit in AliveUnits) { if (unit.PerceptionBubbleRadius > 0) { if (unit.IsVisible(opponent)) { visible = true; if (!VisibleUnits.ContainsKey(opponent)) { OnTeamEnterVision(opponent); unit.OnUnitEnterVision(opponent); VisibleUnits.Add(opponent, unit); } } } } if (visible == false) { if (VisibleUnits.ContainsKey(opponent)) { var visibleBy = VisibleUnits[opponent]; VisibleUnits.Remove(opponent); OnTeamLeaveVision(opponent); visibleBy.OnUnitLeaveVision(opponent); } } } }
public Fleet CreateFleet(List <Unit> _Units, string _Owner, string _Name) { var obj = new GameObject(); var _fleet = obj.AddComponent <Fleet> (); _fleet.Owner = _Owner; _fleet.Name = _Name; _fleet.gameObject.name = "[Fleet] " + _Name; foreach (var unit in _Units) { var newUnit = Instantiate(unit); newUnit.gameObject.SetActive(false); newUnit.gameObject.transform.SetParent(_fleet.transform); newUnit.state = new UnitState(newUnit, _Owner); _fleet.Units.Add(newUnit); AllUnits.Add(newUnit); VisibleUnits.Add(newUnit); } _fleet.SortBySize(); return(_fleet); }
public bool HasVision(Unit player) { return(VisibleUnits.ContainsKey(player)); }