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); }
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); } }
public void DestroyIfEmpty() { if (!GridMembers.Any()) { destroyCallback(); } }
IEnumerator IEnumerable.GetEnumerator() { return(GridMembers.GetEnumerator()); }
public IEnumerator <T> GetEnumerator() { return(GridMembers.GetEnumerator()); }