Some context: I am currently generating a map in Editor mode by iterating through all of my scenes and copying the tiles from their tilemap into one super-map. But, I realized that - when it comes to displaying how much of the map the player has seen upon reloading - I will need to either give the supermap tiles knowledge of which scene they came from, or I will need to load every scene that the player has visited whenever they load up the game and capture their tilemap into a lesser supermap. To me, it seems that the logical choice is to keep my single-generation supermap, but give the tiles knowledge of what scene they come from; this will allow me to get per-tile information and update accordingly.
I was able to successfully create tiles with this knowledge using the code below. However, when I opened up my Tilemap, I saw that under Info > Tiles, instead of my two tile types I saw a bunch of None (TileBase) entries; one for each tile in my map, presumably. It seems to me that this is not the proper way to convert existing tiles to my new tile type with the added knowledge. How should I go about it instead?
public static void Add(this Tilemap tilemap, Tilemap source, Room thisRoom)
{
// Iterate through all positions within the bounds of the source tilemap
BoundsInt bounds = source.cellBounds;
foreach (Vector3Int position in bounds.allPositionsWithin)
{
TileBase tile = source.GetTile(position);
if (tile != null)
{
MapTile mapTile = new MapTile((Tile)tile, thisRoom);
// Set the tile in the destination tilemap
//Convert from relative position to world position
Vector2 worldPos = source.CellToWorld(position);
//Convert from world position to local position of the new map
tilemap.SetTile(tilemap.WorldToCell(worldPos), mapTile);
}
}
}
public MapTile(Tile tile, Room parentRoom)
{
sprite = tile.sprite;
transform = tile.transform;
flags = tile.flags;
color = tile.color;
colliderType = tile.colliderType;
gameObject = tile.gameObject;
name = tile.name;
gameObject = tile.gameObject;
this.parentRoom = parentRoom.gameObject.scene.name;
}