My Smart Tile system

I’ve got a week of sprite work ahead of me before I really want to start time-testing and seeing just how bad a move this was but until then I thought I’d share something I put together a couple days ago.

The short story is I created a Smart Tile system, seen below.

It works as intended and I’m happy with it. Here’s a snippet of the XML file it outputs:

<AEAtlas>
      <name>_0</name>
      <state>
        <short>0</short>
        <short>0</short>
        <short>0</short>
        <short>0</short>
        <short>0</short>
        <short>0</short>
        <short>0</short>
        <short>0</short>
      </state>
    </AEAtlas>
    <AEAtlas>
      <name>_1</name>
      <state>
        <short>2</short>
        <short>2</short>
        <short>2</short>
        <short>2</short>
        <short>2</short>
        <short>2</short>
        <short>2</short>
        <short>2</short>
      </state>
    </AEAtlas>

Each short basically dictates whether the tile can connect from that direction. Again, quite happy with it. What I’m less than happy about and what I’m looking for feedback on is the code I’ve written to cycle through all these shorts. It creates a list of AEAtlas (basically tiles and whether or not the tiles edges and corners connect to neighbours), cycles through them eliminating them as candidates until it finishes, left with the correct tile UV.

        public static string GetAtlas(int tileType, Tile[] neighbours)
        {
            //Create a copy of the tiles and their states (<short>s)
            List<AEAtlas> tempAtlas = new List<AEAtlas>( atlas );

            //Go through all the states
            for ( int i = 0; i < 8; i++ )
            {
                //Go through each atlas
                foreach ( AEAtlas a in atlas )
                {
                    //If the atlas' short is 'cannot connect'...
                    if ( a.state[i] == 2 )
                    {
                        //if the neighbour's tile type is equal to the tile being assessed.
                        //basically if the neighbour says it can't connect and the adjacent tile is of the same type..
                        //it should connect, but the neighbour's state says it doesn't, so remove it
                        if ( neighbours[i].TileType == tileType )
                        {
                            tempAtlas.Remove( a );
                            continue;
                        }
                    }
                }
            }

            //once all adjacent tiles that can't connect and are of the same type are removed, return the first atlas' name
            //this'll be something like _0, _1, _2 etc, which is the auto generated part of the tile name in the sprite texture
            return tempAtlas[0].name;
        }

Basically my concern is this: If I’ve some 49 or 98 different “atlas”, that’s a hell of a lotta work eliminating all of those list elements, and I guess I’m just looking for permission to give up and revert my changes.

Before I had this system I just had a bunch of if statements that said if if !IsNullOrFalse(neighbour[0] && !IsNullOrFalse(neighbour[1])) { return "_15"; } I thought it was ugly, wanted to improve it but what I’ve made seems awfully inefficient.

I’m a bit confused what this is actually about. Did you create your own smart tile system? Because Unity already has RuleTiles. I’ve never really used Unity’s Tilemap but as far as I can tell, Unity’s Tilemap system can already handle those cases.