Create rules
In the last step, we defined what data to store and created a custom data class. Next, we will assign Unity Tiles to our custom data objects and set the custom properties accordingly.
Adding the rules container
As mentioned earlier, assigning Tiles to data objects creates rules. For a better overview, these rules are collected
in another object called TilemapRules
, which is just a dynamic list of these rules.
Go ahead and create one by right clicking > Create > TilemapExtended > TilemapRulesContainer. Looking at this object in the inspector, reveals an empty list so let us create the first rule by adding an element.
Each rule consists of two elements:
- A list of tiles
- A field for the
CellData
object (or those inheriting fromCellData
) you wish to assign to these tiles
In case you haven't created an instance of MyCellData
, go ahead and create one now.
Adding a rule
First, we are going to create a rule for all of our grass Tiles, which will share the same data between each other.
Let's rename the MyCellData
object we created to "GrassData" and drag it into the CellData
field of our first rule.
Next, we are going to expand the rules tiles list by three entries and add the grass Unity Tiles. Those Tile assets
were created when populating the tile palette with sprites.
That's it in terms of rules - the only thing left to do is to actually modify our GrassData
with the values we want.
Notice the pathfinding properties, which we discussed earlier:
Later on, all Unity Tilemaps will be scanned and whenever any of those grass tiles is found, a new instance of the
GrassData
object will be stored in the CellDataStore
.
If during scanning, tiles are found for which there is no rule defined, TilemapExtended will log a warning with the tile name to the console to let you know in case you forgot assigning some tiles!
Having created rules for all other tiles, each with their own Unity Tile assignments and individual MyCellData
instances,
MyRulesContainer is now finished and looks like this: