private void PlaceObjectOfTypeAt(string id, TileLoc loc) { ConnectedTileObject cto = connectedGenericTileMap.GetConnectedTileAt(loc); bool shouldPlace = true; if (cto != null) { Debug.Log("Removing underlying tile of type " + id + " at " + loc + "."); connectedGenericTileMap.RemoveConnectedTileAt(cto.tileLoc); if (cto.GetObjectType() == pathObjectTypeToBuild) { // Do not place new path. shouldPlace = false; } } if (shouldPlace) { Debug.Log("Placing a new tile of type " + id + " at " + loc + "."); connectedGenericTileMap.CreateConnectedTileObject(loc, pathObjectTypeToBuild); } // Update the surrounding tiles UpdateNeigboursOf(loc); }
public ConnectedTileObject CreateConnectedTileObject(TileLoc loc, int objectType = -1) { GameObject tile = GameMap.Instance.CreateTileAt(loc, transform); ConnectedTileObject cto = tile.AddComponent <ConnectedTileObject>(); ConnectedTiles[loc] = cto; cto.objectType = objectType; cto.tileLoc = loc; cto.UpdateConnection(); return(cto); }
private void UpdateNeigboursOf(TileLoc tileLoc) { // Update neighbours foreach (TileLoc pos in ConnectedTileUtils.Cardinal) { ConnectedTileObject c = GameMap.Instance.connectedGenericTileMap.GetConnectedTileAt(pos.RelativeTo(tileLoc)); if (c != null) { Debug.Log("Updating " + tileLoc + "..."); c.UpdateConnection(); } } }