Exemple #1
0
        /// <summary>
        /// Toggles the selected state of a unit. Actually it only toggles when <paramref name="append"/> is true, otherwise it will select the unit while deselecting all others.
        /// </summary>
        /// <param name="unit">The unit.</param>
        /// <param name="append">if set to <c>true</c> [append].</param>
        public void ToggleSelected(IUnitFacade unit, bool append)
        {
            //So this works differently depending on the append modifier. If append then the unit is toggled, if not the unit is not toggled but always selected while all others aren't.
            if (!append || _selected == _emptyGroup)
            {
                DeselectAll();

                unit.isSelected = true;
                _selected       = GroupingManager.CreateGrouping(unit);
                return;
            }

            unit.isSelected = !unit.isSelected;

            if (unit.isSelected)
            {
                _selected.Add(unit);
            }
            else
            {
                _selected.Remove(unit);
            }

            PostUnitsSelectedMessage(_selected);
        }
Exemple #2
0
        private void SpawnGrouping()
        {
            var units = InstantiateUnits(3, 3);

            var grouping = GroupingManager.CreateGrouping(units);

            grouping.MoveTo(target.position, false);
        }
        private void Start()
        {
            //Get the waypoint transforms
            var waypoints = this.GetComponentsInChildren <Transform>().Skip(1).ToArray();

            //Create the orange group. In this example we just create an empty grouping and add members to it
            var grpOrange = GroupingManager.CreateGrouping <IUnitFacade>();

            for (int i = 0; i < 20; i++)
            {
                var agent = Spawn(this.orangeMold, waypoints[0].position);
                grpOrange.Add(agent);
            }

            IFormation formation = new FormationGrid(1.5f);

            grpOrange.SetFormation(formation);

            for (int i = 1; i < 10; i++)
            {
                grpOrange.MoveTo(waypoints[i % waypoints.Length].position, true);
            }

            //Create the green group.
            var grpGreen = GroupingManager.CreateGroup <IUnitFacade>(9);

            for (int i = 0; i < 9; i++)
            {
                var agent = Spawn(this.greenMold, waypoints[3].position);
                grpGreen.Add(agent);
            }

            formation = new FormationEllipsoid(1.5f);
            grpGreen.SetFormation(formation);

            for (int i = 2; i > -10; i--)
            {
                var idx = Math.Abs((i + waypoints.Length) % waypoints.Length);
                grpGreen.MoveTo(waypoints[idx].position, true);
            }

            //Spawn a solo unit
            var solo = Spawn(this.blueMold, waypoints[4].position);

            for (int i = 0; i < 17; i++)
            {
                solo.MoveTo(waypoints[i % waypoints.Length].position, true);
            }
        }
Exemple #4
0
        /// <summary>
        /// Selects the specified units.
        /// </summary>
        /// <param name="append">if set to <c>true</c> the selection will append to the current selection.</param>
        /// <param name="units">The units.</param>
        public void Select(bool append, IEnumerable <IUnitFacade> units)
        {
            IEnumerable <IUnitFacade> newSelections;

            if (_selected.memberCount < 2)
            {
                //This is either w e have an empty group or we have just one in a group. In that case recreate all,
                //since single unit groups are typically of another type.
                newSelections = units;
                _selected     = GroupingManager.CreateGrouping(units);
            }
            else if (append)
            {
                newSelections = units.Except(_selected.All()).ToArray();
                _selected.Add(newSelections);
            }
            else
            {
                //If we select all the same units as before and maybe some more, we just add those additional ones
                //If the selection does not include all from before, we create a new grouping
                var deselected = _selected.All().Except(units);
                if (deselected.Any())
                {
                    DeselectAll();
                    newSelections = units;
                    _selected     = GroupingManager.CreateGrouping(units);
                }
                else
                {
                    newSelections = units.Except(_selected.All()).ToArray();
                    _selected.Add(newSelections);
                }
            }

            newSelections.Apply(u => u.isSelected = true);

            PostUnitsSelectedMessage(_selected);
        }