Hey! Im new at unity and I want to make a game like this:
Im seeing here simple graph of movement (means some tiles allows you go to neighbors, but doesnt allow to step on the water, out of the map). What is bothering me is - how to quickly construct such levels with almost automatic graph calculation, what is general approach?
I’ve thought about creation of multiples prefabs with Tile script and rules, but all the tutorials I’ve saw making regular grid, and quite often in the runtime.
“As map creator” I really just want to select a prefab and place it near to other prefab, and “magically” construct graph (where I even can break some nodes).
To formulate some questions in the end:
Can I snap to placed prefabs?
Can I scriptwise read properties of “near prefabs”. It’s basically kinda linked list, but what I mean, what is the best approach to achieve this, and bake offline graph?
Is it even better to make a tile based editor custom window?
The Wave Function Collapse Algorithm and its variations are good at creating a grid of features using a set of rules. I guess that you could interpret those as a graph as well. Robert Heaton explains the simplest variant of this algorithm in a blog post of his: The Wavefunction Collapse Algorithm explained very clearly
You can write yourself an editor extension that does this in the editor instead of at runtime. Depending on the implementation of your algorithm, it is a simple as defining a tile as an input as well as dimensions for the grid.
Do note that what you are trying to achieve is not easy and can take weeks and months of work to get to work properly. It sounds easy as a concept, but it escalates quickly, both in time and difficulty.
Take a look at Grid Snapping. Unity’s Grid component might also be worth a look.
There is no right answer to this question. It highly depends on your needs, so if you need to know the immediate neighbors of a tile, storing the references to those tiles with the tile isn’t the worst idea.
From my personal experience, this is a hassle because you are doing extra steps getting very little out of it. Your idea about placing a prefab and then triggering the generation is a lot mroe straightforward. You can even use Gizmos and other utilities to draw into your scene, no need to try to get this to work for an editor window.