Exemplo n.º 1
0
    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));
    }
Exemplo n.º 2
0
    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);
    }
Exemplo n.º 3
0
    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));
    }
Exemplo n.º 4
0
        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);
                    }
                }
            }
        }
Exemplo n.º 5
0
    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);
    }
Exemplo n.º 6
0
 public bool HasVision(Unit player)
 {
     return(VisibleUnits.ContainsKey(player));
 }