protected bool DoDrawPatternFields()
        {
            bool isDirty = false;

            EditField("randomizePattern");
            EditorGUILayout.LabelField("Pattern", EditorStyles.boldLabel);
            if (target.Owner)
            {
                STETilemap tilemap = GetTargetTilemap();
                Tileset    tileset = m_action.tileset.Value as Tileset;
                if (!tileset)
                {
                    if (tilemap && tilemap.Tileset)
                    {
                        tileset = tilemap.Tileset;
                    }
                    else
                    {
                        tileset = GuessTileset();
                    }
                    m_action.tileset.Value = tileset;
                }

                if (tileset)
                {
                    isDirty |= UpdateTileGridControl(tileset);
                    float   tileWidth      = Mathf.Min(32f, 160f / m_brushTileGridControl.Width); //160f is half of the size of the width of the action view panel
                    Vector2 visualTileSize = new Vector2(tileWidth, tileWidth * tileset.VisualTileSize.y / tileset.VisualTileSize.x);
                    m_brushTileGridControl.Display(visualTileSize);
                    if (GUILayout.Button("Use tile palette selection as pattern"))
                    {
                        if (tileset.TileSelection != null && tileset.TileSelection.selectionData.Count > 0)
                        {
                            TileSelection copySelection = tileset.TileSelection.Clone();
                            copySelection.FlipVertical();
                            m_action.tileSelection.selectionData = copySelection.selectionData.Select(x => (int)x).ToArray();
                            m_action.tileSelection.rowLength     = tileset.TileSelection.rowLength;
                        }
                        else
                        {
                            if (tileset.SelectedTileId != Tileset.k_TileId_Empty)
                            {
                                m_action.tileSelection.selectionData = new int[] { tileset.SelectedTileId }
                            }
                            ;
                            else if (tileset.SelectedBrushId != Tileset.k_BrushId_Default)
                            {
                                m_action.tileSelection.selectionData = new int[] { tileset.SelectedBrushId << 16 }
                            }
                            ;
                            else
                            {
                                m_action.tileSelection.selectionData = new int[] { -1 }
                            };
                            m_action.tileSelection.rowLength = 1;
                        }
                    }
                    if (GUILayout.Button("Use brush selection as pattern"))
                    {
                        uint[,] brushSelection = BrushBehaviour.Instance.GetBrushPattern();
                        int[] tileSelection = new int[brushSelection.Length];
                        for (int y = 0, idx = 0; y < brushSelection.GetLength(1); ++y)
                        {
                            for (int x = 0; x < brushSelection.GetLength(0); ++x, ++idx)
                            {
                                tileSelection[idx] = (int)brushSelection[x, brushSelection.GetLength(1) - y - 1];
                            }
                        }
                        m_action.tileSelection.selectionData = tileSelection;
                        m_action.tileSelection.rowLength     = brushSelection.GetLength(0);
                    }
                }
                else
                {
                    if (tilemap)
                    {
                        EditorGUILayout.HelpBox("You need to set a tileset for the tilemap", MessageType.Info);
                    }
                }
            }
            return(isDirty);
        }