public IGrouping <IUnitFacade> CreateGrouping(IEnumerable members)
        {
            var units = members.ToUnitFacades();

            if (this.useLINQ)
            {
                //A somewhat cleaner solution, albeit due to the lack of covariance in .Net 3.5 we have to explicitly cast at the end.
                var groups = from u in units
                             group u by u.attributes into grps
                             select new OnePathForAllGroup(grps) as TransientGroup <IUnitFacade>;

                return(new Grouping <IUnitFacade>(groups));
            }
            else
            {
                var grpDict = new Dictionary <AttributeMask, OnePathForAllGroup>();

                var grouping = new Grouping <IUnitFacade>(1);
                foreach (var unit in units)
                {
                    OnePathForAllGroup grp;
                    if (!grpDict.TryGetValue(unit.attributes, out grp))
                    {
                        grp = new OnePathForAllGroup(1);
                        grpDict[unit.attributes] = grp;
                        grouping.Add(grp);
                    }

                    grp.Add(unit);
                }

                return(grouping);
            }
        }
Example #2
0
        private void SpawnGroupThree()
        {
            //You can of source also simply create the specific group type directly.
            //If you don't plan to change your strategy at runtime this is likely the best performing option
            var grpOrange = new OnePathForAllGroup(3);
            var grpGreen  = new OnePathForAllGroup(3);

            for (int i = 0; i < 3; i++)
            {
                var go = Instantiate(this.orangeMold, Vector3.zero, Quaternion.identity) as GameObject;
                grpOrange.Add(go.GetUnitFacade());

                go = Instantiate(this.greenMold, Vector3.zero, Quaternion.identity) as GameObject;
                grpGreen.Add(go.GetUnitFacade());
            }

            grpOrange.MoveTo(target.position, false);
            grpGreen.MoveTo(target.position, false);
        }