unity - Board like strategy map - Game Development Stack Exchange

graceacupuncture - 24/01/2022 - STRATEGY - 920 Views

I was working on a very similar (but more complicated) project. The basic idea is to create a colormap and a 2D sprite and perform a per-province palette-swap in the sprite's fragment shader based on the province's RGB value.

Conceptually, you'd keep two textures, a colormap texture, and a lookup texture. The colormap could be whatever size you want, but the lookup texture has to be of size 4096*4096. The details are contained in the accepted answer to my earlier question on the topic.

This is a very graphically cheap way to do this, though it can be pretty computationally expensive to repeatedly update a large texture.

This also allows you the option of easily projecting your texture over a 3D terrain if you ever want to go that route (for example, if you ever want a map like the one in Risk 2, Europa Universalis, or Crusader Kings 2).

Another way to do it is to read through a colormap like the one in my linked question, and create 1 2D sprite per province. This approach was taken by the (now-defunct) Of Bears and Eagles project (which is coded in Java), but it is worth noting that a heavily-mutated private fork of the project is being run by Reddit user Kalelovil, and is pseudo-regularly updated here (the project on Reddit hasn't been very active, most of us who contribute do so over the project's Slack group). The project was recoded in C# once Kalelovil took over (in order to work with Unity), so if you want further details on how to write the map parser, I'd suggest seeking out Kalelovil on Reddit (he is active on Slack, so I imagine he is also active on Reddit, but I haven't checked).

I'd share my own code, but I use several classes and several files to generate my (now-obsolete) 2D maps, and honestly it would be extremely cumbersome to paste and format all that code (several hundred lines). This is pretty memory intensive, and it can be graphically intensive depending on the number of provinces you want to display, but it would be perfect for a game with only 20 or so provinces. You can use shaders to decrease granularity.

A third option would be to fork this Github project and use it to generate a 2D mesh for each province from a vector graphics file from path's. The linked file only handles the MoveTo and LineTo commands, but it can be easily modified to support Horizontal and Vertical commands. Other, more complex commands (Bezier curves and arcs) are going to be harder to implement, but are still within the realm of possibility.

Finally, as a last resort, if you don't mind paying large sums of money, the Unity Asset developer, Kronnect, has an entire string of (admittedly expensive, but extremely well-maintained and well-supported) assets that would definitely cover any and all map needs you might have. I personally own a copy of their World Political Map 2D Edition and their World Map Strategy Kit, and they both run like a charm. All the bottlenecks I have encountered (aside from the occasional bug which is usually fixed in a Beta within hours to a day of my report) have been in my code.