Esempio n. 1
0
        public virtual T Remove(Vector2Int key)
        {
            Size.Invalidate();

            var gridMember = GetMember(key);

            // Remove controller reference
            if (ReferenceEquals(gridMember, Controller))
            {
                Controller = default;
            }

            var tilePositions = GridUtils.GetOccupiedTilesByAnchor(gridMember);

            GridMembers.Remove(gridMember);
            gridMember.RemoveGridTotals(Totals);

            // Remove neighbour references
            foreach (var neighbour in NeighbourDict[gridMember])
            {
                NeighbourDict[neighbour].Remove(gridMember);
            }

            NeighbourDict.Remove(gridMember);

            foreach (var occupiedTile in tilePositions)
            {
                OccupiedTiles.Remove(occupiedTile);
            }

            return(gridMember);
        }
Esempio n. 2
0
        public virtual void Add(T gridMember)
        {
            Size.Invalidate();

            // Assign controller reference
            if (gridMember.GetIsController() && Controller == null)
            {
                Controller = gridMember;
            }

            GridMembers.Add(gridMember);
            gridMember.AddGridTotals(Totals);

            // Get grid positions of blueprint block
            var tilePositions = GridUtils.GetOccupiedTilesByAnchor(gridMember);

            EnsureNeighbourKeyIsCreated(gridMember);

            // Add neighbour references
            foreach (var neighbour in this.GetNeighbours(tilePositions))
            {
                NeighbourDict[neighbour].Add(gridMember);
                NeighbourDict[gridMember].Add(neighbour);
            }

            foreach (var tilePosition in tilePositions)
            {
                OccupiedTiles.Add(tilePosition, gridMember);
            }
        }
Esempio n. 3
0
 public void DestroyIfEmpty()
 {
     if (!GridMembers.Any())
     {
         destroyCallback();
     }
 }
Esempio n. 4
0
 IEnumerator IEnumerable.GetEnumerator()
 {
     return(GridMembers.GetEnumerator());
 }
Esempio n. 5
0
 public IEnumerator <T> GetEnumerator()
 {
     return(GridMembers.GetEnumerator());
 }