Beispiel #1
0
        public Grid(
            LazyCache <Vector2Int> size              = null,
            GridTotals totals                        = null,
            ObservableCollection <T> gridMembers     = null,
            Dictionary <Vector2Int, T> occupiedTiles = null,
            Dictionary <T, List <T> > neighbourDict  = null)
        {
            Size = size ?? new LazyCache <Vector2Int>(() => {
                var bounds = new GridBounds(OccupiedTiles.Keys);
                return(bounds.GetDelta());
            });

            Totals        = totals ?? new GridTotals();
            GridMembers   = gridMembers ?? new ObservableCollection <T>();
            OccupiedTiles = occupiedTiles ?? new Dictionary <Vector2Int, T>();
            NeighbourDict = neighbourDict ?? new Dictionary <T, List <T> >();
        }
Beispiel #2
0
        public static IEnumerable <T> GetNeighbours <T>(this Grid <T> grid, IEnumerable <Vector2Int> tilePositions)
            where T : class, IGridMember
        {
            // Get grid positions around block
            var bounds             = new GridBounds(tilePositions);
            var neighbourPositions = bounds.GetAdjacentPositions();

            var neighbours = new List <T>();

            foreach (var neighbourPosition in neighbourPositions)
            {
                if (grid.ContainsMember(neighbourPosition))
                {
                    var neighbour = grid.GetMember(neighbourPosition);
                    if (!neighbours.Contains(neighbour))
                    {
                        neighbours.Add(neighbour);
                        yield return(neighbour);
                    }
                }
            }
        }