So I'm working on a hobby project using C# in Unity. For the purpose of this thread, the game is basically XCOM: its a tactical, turn based, square grid based game. The game is in 3D.
I have build a simple map editor, that allows me to place prefab 'tile' game objects, that contain a 'Tile' component. When a map is loaded, all the tiles are collected by a map manager script, initialized, and stored in a Dictionary<Vector2Int, Tile>, where the Vector2Int consists of the tile's x and y coordinate and the Tile is a reference to the tile component. Since I only use the x and y position, I cannot create caves or buildings with multiple floors (i.e. two tiles with the same x and y but different z coordinates), but this is I accept. As for the map size, I want to be able to use maps with up to some 1000 tiles.
Using this dictionary, I implemented pathfinding, and it allows me to easily look up / interact with any specific tiles (and their content). Also, the map can automatically have any shape (e.g.irregular edges, can contain holes, etc.), which is nice.
My question: is a dictionary a sensible way to store and access map (tile) data? Are there any drawbacks or potential problems I can run into later? Is there a compelling reason to use another structure such as a 2D array, where I will have to write custom 'TryGetValue' like methods, etc.?
Tell me what you think!