void InstantiateOuterWalls(Board board, Position boardPosition)
        {
            // The outer walls are one unit left, right, up and down from the board.
            float halfWidth   = (board.GridStep.x * board.GridCount.x) * 0.5f;
            float halfHeight  = (board.GridStep.y * board.GridCount.y) * 0.5f;
            float halfStepX   = board.GridStep.x * 0.5f;
            float halfStepY   = board.GridStep.y * 0.5f;
            float leftEdgeX   = (-halfWidth) + halfStepX;
            float rightEdgeX  = halfWidth - halfStepX;
            float bottomEdgeY = (-halfHeight) + halfStepY;
            float topEdgeY    = halfHeight - halfStepY;

            // Shift outer wall outward one step
            leftEdgeX   -= board.GridStep.x;
            rightEdgeX  += board.GridStep.x;
            topEdgeY    += board.GridStep.y;
            bottomEdgeY -= board.GridStep.y;

            var boardReference = new BoardReference
            {
                TileSetId = board.TileSetId
            };

            OuterWallTileGroup.SetFilter(boardReference);
            var outerWallTileGroupEntities = OuterWallTileGroup.GetEntityArray();

            if (outerWallTileGroupEntities.Length > 0)
            {
                // copy data from ComponentGroup
                var tileEntities = new NativeArray <Entity>(outerWallTileGroupEntities.Length, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
                for (int i = 0; i < outerWallTileGroupEntities.Length; i++)
                {
                    tileEntities[i] = outerWallTileGroupEntities[i];
                }


                // Instantiate both vertical walls (one on each side).
                InstantiateVerticalOuterWall(leftEdgeX, bottomEdgeY, topEdgeY, board.GridStep.y, tileEntities, boardPosition);
                InstantiateVerticalOuterWall(rightEdgeX, bottomEdgeY, topEdgeY, board.GridStep.y, tileEntities, boardPosition);

                // Instantiate both horizontal walls, these are one in left and right from the outer walls.
                InstantiateHorizontalOuterWall(leftEdgeX + board.GridStep.x, rightEdgeX - board.GridStep.x, bottomEdgeY, board.GridStep.x, tileEntities, boardPosition);
                InstantiateHorizontalOuterWall(leftEdgeX + board.GridStep.x, rightEdgeX - board.GridStep.x, topEdgeY, board.GridStep.x, tileEntities, boardPosition);

                tileEntities.Dispose();
            }
        }
        void InstantiateTiles(Board board, NativeArray <TileType> tiles, int tilesStride, Position parent)
        {
            // The outer walls are one unit left, right, up and down from the board.
            float halfWidth  = (board.GridStep.x * board.GridCount.x) * 0.5f;
            float halfHeight = (board.GridStep.y * board.GridCount.y) * 0.5f;
            float halfStepX  = board.GridStep.x * 0.5f;
            float halfStepY  = board.GridStep.y * 0.5f;
            float leftEdgeX  = (-halfWidth) + halfStepX;
            float topEdgeY   = halfHeight - halfStepY;

            var boardReference = new BoardReference
            {
                TileSetId = board.TileSetId
            };

            FloorTileGroup.SetFilter(boardReference);
            var floorTileGroupEntities = FloorTileGroup.GetEntityArray();

            WallTileGroup.SetFilter(boardReference);
            var wallTileGroupEntities = WallTileGroup.GetEntityArray();

            // copy data from ComponentGroup
            var floorTileEntities = new NativeArray <Entity>(floorTileGroupEntities.Length, Allocator.Temp, NativeArrayOptions.UninitializedMemory);

            for (int i = 0; i < floorTileGroupEntities.Length; i++)
            {
                floorTileEntities[i] = floorTileGroupEntities[i];
            }

            var wallTileEntities = new NativeArray <Entity>(wallTileGroupEntities.Length, Allocator.Temp, NativeArrayOptions.UninitializedMemory);

            for (int i = 0; i < wallTileGroupEntities.Length; i++)
            {
                wallTileEntities[i] = wallTileGroupEntities[i];
            }

            // Go through all the tiles...
            for (int i = 0; i < board.GridCount.y; i++)
            {
                for (int j = 0; j < board.GridCount.x; j++)
                {
                    var x = leftEdgeX + (j * board.GridStep.x);
                    var y = topEdgeY + (-i * board.GridStep.y);

                    if (tiles[(i * tilesStride) + j] == TileType.Floor)
                    {
                        // ... and instantiate a floor tile for it.
                        if (floorTileEntities.Length > 0)
                        {
                            InstantiateFromArray(floorTileEntities, x, y, parent);
                        }
                    }
                    else
                    {
                        if (wallTileEntities.Length > 0)
                        {
                            InstantiateFromArray(wallTileEntities, x, y, parent);
                        }
                    }
                }
            }

            floorTileEntities.Dispose();
            wallTileEntities.Dispose();
        }