Ejemplo n.º 1
0
        void DisplayHelpBox()
        {
            string sHelp =
                "\n" +
                " - <b>Drag:</b>\t Middle mouse button\n" +
                " - <b>Paint:</b>\t Left mouse button\n" +
                " - <b>Erase:</b>\t Shift + Left mouse button\n" +
                " - <b>Fill:</b>\t Double Click\n\n" +
                " - <b>Copy</b> tiles by dragging and holding right mouse button\n\n" +
                " - <b>Cut</b> copy while holding Shift key\n\n" +
                " - <b>Select</b> a tile or brush by right clicking over the tile.\n    If it's a brush, the brush will be selected first and second time the\n    tile painted by the brush will be selected cycling between them\n\n" +
                " - <b>Rotating and flipping:</b>\n" +
                "   * <b>Rotate</b> ±90º by using <b>comma ','</b> and <b>period '.'</b>\n" +
                "   * <b>Vertical Flip</b> by pressing X\n" +
                "   * <b>Horizontal Flip</b> by pressing Y\n" +
                "   * <i>Hold shift to only rotate or flip tile positions</i>\n" +
                "\n - <b>Use Ctrl-Z/Ctrl-Y</b> to Undo/Redo changes\n";
            GUIContent helpContent = new GUIContent(sHelp);

            Handles.BeginGUI();
            Rect rHelpBox = new Rect(new Vector2(2f, 64f), Styles.Instance.toolbarBoxStyle.CalcSize(helpContent));

            GUILayout.BeginArea(rHelpBox);
            HandlesEx.DrawRectWithOutline(new Rect(Vector2.zero, rHelpBox.size), s_toolbarBoxBgColor, s_toolbarBoxOutlineColor);
            GUILayout.Label(sHelp, Styles.Instance.toolbarBoxStyle);
            GUILayout.EndArea();
            Handles.EndGUI();
        }
Ejemplo n.º 2
0
        public void OnSceneGUI()
        {
            m_dblClick.Update();
            Tilemap tilemap = (Tilemap)target;

            if (tilemap == null || tilemap.Tileset == null)
            {
                return;
            }

            m_brushVisible = s_editMode == eEditMode.Paint;
            if (s_editMode == eEditMode.Paint)
            {
                DoPaintInspector();

                if (GetBrushMode() == eBrushMode.Fill && Event.current.type == EventType.Repaint)
                {
                    Color fillPreviewColor = new Color(1f, 1f, 1f, 0.2f);
                    Color emptyColor       = new Color(0f, 0f, 0f, 0f);
                    Rect  rTile            = new Rect(Vector2.zero, m_tilemap.CellSize);
                    foreach (Vector2 tilePos in m_fillPreview)
                    {
                        rTile.position = tilePos;
                        HandlesEx.DrawRectWithOutline(m_tilemap.transform, rTile, fillPreviewColor, emptyColor);
                    }
                }
            }
            else if (s_editMode == eEditMode.Map)
            {
                DoMapInspector();
            }
            BrushBehaviour.SetVisible(m_brushVisible);
        }
Ejemplo n.º 3
0
        void DoDrawGizmos()
        {
            Vector3 savedPos = transform.position;

            transform.position += (Vector3)(Vector2.Scale(Camera.current.transform.position, (Vector2.one - m_parallaxFactor))); //apply parallax
            Rect rBound = new Rect(MapBounds.min, MapBounds.size);

            HandlesEx.DrawRectWithOutline(transform, rBound, new Color(0, 0, 0, 0), new Color(1, 1, 1, 0.5f));

            if (ShowGrid)
            {
                Plane tilemapPlane     = new Plane(this.transform.forward, this.transform.position);
                float distCamToTilemap = 0f;
                Ray   rayCamToPlane    = new Ray(Camera.current.transform.position, Camera.current.transform.forward);
                tilemapPlane.Raycast(rayCamToPlane, out distCamToTilemap);
                if (HandleUtility.GetHandleSize(rayCamToPlane.GetPoint(distCamToTilemap)) <= 3f)
                {
                    // draw tile cells
                    Gizmos.color = EditorGlobalSettings.TilemapGridColor;

                    // Horizontal lines
                    for (float i = 1; i < GridWidth; i++)
                    {
                        Gizmos.DrawLine(
                            this.transform.TransformPoint(new Vector3(MapBounds.min.x + i * CellSize.x, MapBounds.min.y)),
                            this.transform.TransformPoint(new Vector3(MapBounds.min.x + i * CellSize.x, MapBounds.max.y))
                            );
                    }

                    // Vertical lines
                    for (float i = 1; i < GridHeight; i++)
                    {
                        Gizmos.DrawLine(
                            this.transform.TransformPoint(new Vector3(MapBounds.min.x, MapBounds.min.y + i * CellSize.y, 0)),
                            this.transform.TransformPoint(new Vector3(MapBounds.max.x, MapBounds.min.y + i * CellSize.y, 0))
                            );
                    }
                }
                Gizmos.color = Color.white;
            }

            //Draw Chunk Colliders
            var valueIter = m_dicChunkCache.Values.GetEnumerator();

            while (valueIter.MoveNext())
            {
                TilemapChunk chunk = valueIter.Current;
                if (chunk)
                {
                    string[] asChunkCoords = chunk.name.Split(new char[] { '_' }, System.StringSplitOptions.RemoveEmptyEntries);
                    int      chunkX        = int.Parse(asChunkCoords[0]);
                    int      chunkY        = int.Parse(asChunkCoords[1]);
                    rBound = new Rect(chunkX * k_chunkSize * CellSize.x, chunkY * k_chunkSize * CellSize.y, k_chunkSize * CellSize.x, k_chunkSize * CellSize.y);
                    HandlesEx.DrawRectWithOutline(transform, rBound, new Color(0, 0, 0, 0), new Color(1, 0, 0, 0.2f));
                    chunk.DrawColliders();
                }
            }
            //
            transform.position = savedPos; // restore position
        }
Ejemplo n.º 4
0
        public void DoGUI(Vector2 position, Vector2 buttonSize, Color bgColor, Color outlineColor)
        {
            Color savedColor = GUI.color;
            int   buttonNb   = m_buttonGuiContentList.Count;
            Rect  rToolBar   = new Rect(position.x, position.y, buttonNb * buttonSize.x, buttonSize.y);

            GUILayout.BeginArea(rToolBar);
            HandlesEx.DrawRectWithOutline(new Rect(Vector2.zero, rToolBar.size), bgColor, outlineColor);
            GUILayout.BeginHorizontal();

            if (m_isHighlighted.Length != m_buttonGuiContentList.Count)
            {
                System.Array.Resize(ref m_isHighlighted, m_buttonGuiContentList.Count);
            }

            int  buttonPadding = 4;
            Rect rToolBtn      = new Rect(buttonPadding, buttonPadding, rToolBar.size.y - 2 * buttonPadding, rToolBar.size.y - 2 * buttonPadding);

            for (int idx = 0; idx < m_buttonGuiContentList.Count; ++idx)
            {
                _DoToolbarButton(rToolBtn, idx);
                rToolBtn.x = rToolBtn.xMax + 2 * buttonPadding;
            }
            GUILayout.EndHorizontal();
            GUILayout.EndArea();
            GUI.color = savedColor;
        }
Ejemplo n.º 5
0
        void DoDrawGizmos()
        {
            Rect rBound = new Rect(MapBounds.min, MapBounds.size);

            HandlesEx.DrawRectWithOutline(transform, rBound, new Color(0, 0, 0, 0), new Color(1, 1, 1, 0.5f));

            if (ShowGrid)
            {
                Plane tilemapPlane     = new Plane(this.transform.forward, this.transform.position);
                float distCamToTilemap = 0f;
                Ray   rayCamToPlane    = new Ray(Camera.current.transform.position, Camera.current.transform.forward);
                tilemapPlane.Raycast(rayCamToPlane, out distCamToTilemap);
                if (HandleUtility.GetHandleSize(rayCamToPlane.GetPoint(distCamToTilemap)) <= 3f)
                {
                    // draw tile cells
                    Gizmos.color = new Color(1f, 1f, 1f, .2f);

                    // Horizontal lines
                    for (float i = 1; i < GridWidth; i++)
                    {
                        Gizmos.DrawLine(
                            this.transform.TransformPoint(new Vector3(MapBounds.min.x + i * CellSize.x, MapBounds.min.y)),
                            this.transform.TransformPoint(new Vector3(MapBounds.min.x + i * CellSize.x, MapBounds.max.y))
                            );
                    }

                    // Vertical lines
                    for (float i = 1; i < GridHeight; i++)
                    {
                        Gizmos.DrawLine(
                            this.transform.TransformPoint(new Vector3(MapBounds.min.x, MapBounds.min.y + i * CellSize.y, 0)),
                            this.transform.TransformPoint(new Vector3(MapBounds.max.x, MapBounds.min.y + i * CellSize.y, 0))
                            );
                    }
                }
            }

            //Draw Chunk Colliders
            for (int i = 0; i < transform.childCount; ++i)
            {
                TilemapChunk chunk = transform.GetChild(i).GetComponent <TilemapChunk>();
                if (chunk != null)
                {
                    string[] asChunkCoords = chunk.name.Split(new char[] { '_' }, System.StringSplitOptions.RemoveEmptyEntries);
                    int      chunkX        = int.Parse(asChunkCoords[0]);
                    int      chunkY        = int.Parse(asChunkCoords[1]);
                    rBound = new Rect(chunkX * k_chunkSize * CellSize.x, chunkY * k_chunkSize * CellSize.y, k_chunkSize * CellSize.x, k_chunkSize * CellSize.y);
                    HandlesEx.DrawRectWithOutline(transform, rBound, new Color(0, 0, 0, 0), new Color(1, 0, 0, 0.2f));
                    chunk.DrawColliders();
                }
            }
            //
        }
        void OnGUI()
        {
            if (!Texture)
            {
                Close();
            }

            Event e = Event.current;

            Color emptyColor = new Color();
            Color gridColor  = new Color(0f, 1f, 1f, 0.5f);

            m_scrollPos = GUILayout.BeginScrollView(m_scrollPos);
            {
                if (e.type == EventType.ScrollWheel)
                {
                    if (e.delta.y < 0f)
                    {
                        m_zoom++;
                    }
                    else
                    {
                        m_zoom--;
                    }
                    m_zoom = Mathf.Max(1, m_zoom);
                }
                if (e.type == EventType.MouseDrag)
                {
                    m_scrollPos -= e.delta;
                    Repaint();
                }
                GUILayoutUtility.GetRect(Texture.width * m_zoom, Texture.height * m_zoom);
                GUI.DrawTexture(new Rect(0, 0, Texture.width * m_zoom, Texture.height * m_zoom), Texture);
                Rect tileRect = new Rect(new Vector2(Extrude, Extrude), TileSize);
                for (; tileRect.yMax <= Texture.height; tileRect.y += TileSize.y + Padding)
                {
                    tileRect.x = Extrude;
                    for (; tileRect.xMax <= Texture.width; tileRect.x += TileSize.x + Padding)
                    {
                        Rect scaledRect = tileRect; scaledRect.position *= m_zoom; scaledRect.size *= m_zoom;
                        HandlesEx.DrawRectWithOutline(scaledRect, emptyColor, gridColor);
                    }
                }
            }
            GUILayout.EndScrollView();
        }
Ejemplo n.º 7
0
        private bool m_displayAutocompleteBtn = false; // fix gui warning when button appears
        public void Display(Vector2 visualTileSize)
        {
            GUI.changed |= m_hasChanged;
            m_hasChanged = false;
            Event e = Event.current;
            bool  isLeftMouseReleased = e.type == EventType.MouseUp && e.button == 0;

            if (isLeftMouseReleased)
            {
                m_hasFocus = m_tileSelectionRect.Contains(e.mousePosition);
            }

            bool  hasEmptyTiles        = false;
            int   size                 = m_width * m_height;
            Color cSelectedBorderColor = new Color(1f, 1f, 0f, 1f);

            if (!m_hasFocus)
            {
                cSelectedBorderColor *= .8f;
            }
            GUILayout.BeginHorizontal();
            {
                // Draw Autotile Combination Control
                GUI.backgroundColor = Tileset.BackgroundColor;
                GUILayoutUtility.GetRect(visualTileSize.x * m_width, visualTileSize.y * m_height + 1f);
                Rect rArea = GUILayoutUtility.GetLastRect();
                {
                    if (m_backgroundTexture)
                    {
                        GUI.DrawTexture(new Rect(rArea.position, Vector2.Scale(visualTileSize, new Vector2(m_width, m_height))), m_backgroundTexture);
                    }
                    GUI.backgroundColor = Color.white;
                    for (int tileIdx = 0; tileIdx < size; ++tileIdx)
                    {
                        int  gx          = tileIdx % m_width;
                        int  gy          = tileIdx / m_width;
                        Rect rVisualTile = new Rect(gx * visualTileSize.x, gy * visualTileSize.y, visualTileSize.x, visualTileSize.y);
                        rVisualTile.position += rArea.position;
                        uint tileData = m_getTileDataFunc(tileIdx);
                        hasEmptyTiles |= tileData == Tileset.k_TileData_Empty;
                        TilesetBrush brush = Tileset.FindBrush(Tileset.GetBrushIdFromTileData(tileData));
                        if (brush)
                        {
                            tileData = TilesetBrush.ApplyAndMergeTileFlags(brush.PreviewTileData(), tileData);
                        }
                        int tileId = (int)(tileData & Tileset.k_TileDataMask_TileId);
                        if (tileId != Tileset.k_TileId_Empty)
                        {
                            TilesetEditor.DoGUIDrawTileFromTileData(rVisualTile, tileData, Tileset);
                        }

                        Color bgColor = new Color(1f - Tileset.BackgroundColor.r, 1f - Tileset.BackgroundColor.g, 1f - Tileset.BackgroundColor.b, Tileset.BackgroundColor.a);
                        HandlesEx.DrawRectWithOutline(rVisualTile, m_selectedTileIdx == tileIdx ? new Color(0f, 0f, 0f, 0.1f) : new Color(), m_selectedTileIdx == tileIdx ? cSelectedBorderColor : bgColor);

                        if (isLeftMouseReleased && rVisualTile.Contains(e.mousePosition))
                        {
                            m_selectedTileIdx = tileIdx;
                            EditorWindow wnd = EditorWindow.focusedWindow;
                            TileSelectionWindow.Show(Tileset);
                            TileSelectionWindow.Instance.Ping();
                            wnd.Focus();
                            GUI.FocusControl("");
                        }
                    }
                }

                uint brushTileData = m_selectedTileIdx >= 0 ? m_getTileDataFunc(m_selectedTileIdx) : Tileset.k_TileData_Empty;
                brushTileData = DoTileDataPropertiesLayout(brushTileData, Tileset, AllowBrushSelection);
                if (m_selectedTileIdx >= 0)
                {
                    m_setTileDataFunc(m_selectedTileIdx, brushTileData);
                }
            }
            GUILayout.EndHorizontal();

            if (e.type == EventType.Repaint)
            {
                m_tileSelectionRect = GUILayoutUtility.GetLastRect();
            }

            m_displayAutocompleteBtn = e.type == EventType.Layout ? !hasEmptyTiles && m_tileIdOff != 0 : m_displayAutocompleteBtn;
            if (size > 1 && m_displayAutocompleteBtn && GUILayout.Button("Autocomplete relative to last change"))
            {
                Undo.RecordObject(m_target, "MultipleTileChanged");
                for (int tileIdx = 0; tileIdx < size; ++tileIdx)
                {
                    if (tileIdx != m_tileIdOffSkipIdx)
                    {
                        int brushTileId = (int)(m_getTileDataFunc(tileIdx) & Tileset.k_TileDataMask_TileId);
                        brushTileId += m_tileIdOff;
                        if (brushTileId < 0 || brushTileId >= m_tileset.Tiles.Count)
                        {
                            m_setTileDataFunc(tileIdx, Tileset.k_TileData_Empty);
                        }
                        else
                        {
                            uint tileData = m_getTileDataFunc(tileIdx);
                            tileData &= ~Tileset.k_TileDataMask_TileId;
                            tileData |= (uint)(brushTileId & Tileset.k_TileDataMask_TileId);
                            m_setTileDataFunc(tileIdx, tileData);
                        }
                    }
                }
                m_tileIdOff = 0;
                EditorUtility.SetDirty(m_target);
            }
            if (Tileset.TileSelection != null && Tileset.TileSelection.selectionData.Count == m_width * m_height && Tileset.TileSelection.rowLength == m_width)
            {
                if (GUILayout.Button("Autocomplete from selection"))
                {
                    Undo.RecordObject(m_target, "MultipleTileChanged");
                    for (int tileIdx = 0; tileIdx < size; ++tileIdx)
                    {
                        int selectionIdx = (tileIdx % m_width) + (m_height - 1 - tileIdx / m_width) * m_width;
                        int brushTileId  = (int)(Tileset.TileSelection.selectionData[selectionIdx] & Tileset.k_TileDataMask_TileId);
                        m_setTileDataFunc(tileIdx, (uint)(brushTileId & Tileset.k_TileDataMask_TileId));
                    }
                    m_tileIdOff = 0;
                    EditorUtility.SetDirty(m_target);
                }
            }

            if (ShowHelpBox)
            {
                EditorGUILayout.HelpBox(HelpBoxText, MessageType.Info);
            }
        }
Ejemplo n.º 8
0
        public void Display()
        {
            Event e = Event.current;

            m_dblClick.Update();

            // This way a gui exception is avoided
            if (e.type == EventType.Layout && m_selectBrushInInspector != null)
            {
                Selection.activeObject   = m_selectBrushInInspector;
                m_selectBrushInInspector = null;
            }

            if (m_lastTime == 0f)
            {
                m_lastTime = Time.realtimeSinceStartup;
            }
            m_timeDt   = Time.realtimeSinceStartup - m_lastTime;
            m_lastTime = Time.realtimeSinceStartup;

            if (Tileset == null)
            {
                EditorGUILayout.HelpBox("There is no tileset selected", MessageType.Info);
                return;
            }
            else if (Tileset.AtlasTexture == null)
            {
                EditorGUILayout.HelpBox("There is no atlas texture set", MessageType.Info);
                return;
            }
            else if (Tileset.Tiles.Count == 0)
            {
                EditorGUILayout.HelpBox("There are no tiles to show in the current tileset", MessageType.Info);
                return;
            }

            if (m_scrollStyle == null)
            {
                m_scrollStyle = new GUIStyle("ScrollView");
            }

            if (m_customBox == null)
            {
                m_customBox = new GUIStyle("Box");
            }

            float visualTilePadding       = 1;
            bool  isLeftMouseReleased     = e.type == EventType.MouseUp && e.button == 0;
            bool  isRightMouseReleased    = e.type == EventType.MouseUp && e.button == 1;
            bool  isInsideTileScrollArea  = e.isMouse && m_rTileScrollArea.Contains(e.mousePosition);
            bool  isInsideBrushScrollArea = e.isMouse && m_rBrushScrollArea.Contains(e.mousePosition);

            // TileViews
            if (m_tileViewList == null || m_tileViewList.list != Tileset.TileViews)
            {
                if (e.type != EventType.Layout)
                {
                    m_tileViewList = TilesetEditor.CreateTileViewReorderableList(Tileset);
                    m_tileViewList.onSelectCallback += (ReorderableList list) =>
                    {
                        m_viewMode = eViewMode.TileView;
                        RemoveTileSelection();
                    };
                    m_tileViewList.onRemoveCallback += (ReorderableList list) =>
                    {
                        RemoveTileSelection();
                    };
                }
            }
            else
            {
                GUI.color = Color.cyan;
                GUILayout.BeginVertical(m_customBox);
                m_tileViewList.index = Mathf.Clamp(m_tileViewList.index, -1, Tileset.TileViews.Count - 1);
                m_tileViewList.DoLayoutList();
                Rect rList = GUILayoutUtility.GetLastRect();
                if (e.isMouse && !rList.Contains(e.mousePosition))
                {
                    m_tileViewList.ReleaseKeyboardFocus();
                }
                GUILayout.EndVertical();
                GUI.color = Color.white;
            }
            TileView tileView = m_tileViewList != null && m_tileViewList.index >= 0 ? Tileset.TileViews[m_tileViewList.index] : null;

            if (m_viewMode == eViewMode.Tileset)
            {
                Tileset.TileRowLength = Mathf.Clamp(EditorGUILayout.IntField("TileRowLength", Tileset.TileRowLength), 1, Tileset.Width);
            }

            m_viewMode = (eViewMode)EditorGUILayout.EnumPopup("View Mode", m_viewMode);
            if (tileView == null)
            {
                m_viewMode = eViewMode.Tileset;
            }
            if (m_viewMode != m_prevViewMode)
            {
                m_prevViewMode = m_viewMode;
                RemoveTileSelection();
            }

            // Draw Background Color Selector
            Tileset.BackgroundColor = EditorGUILayout.ColorField("Background Color", Tileset.BackgroundColor);
            if (m_prevBgColor != Tileset.BackgroundColor || m_scrollStyle.normal.background == null)
            {
                m_prevBgColor = Tileset.BackgroundColor;
                if (m_scrollStyle.normal.background == null)
                {
                    m_scrollStyle.normal.background = new Texture2D(1, 1)
                    {
                        hideFlags = HideFlags.DontSave
                    }
                }
                ;
                m_scrollStyle.normal.background.SetPixel(0, 0, Tileset.BackgroundColor);
                m_scrollStyle.normal.background.Apply();
            }
            //---

            string sTileIdLabel = Tileset.SelectedTileId != Tileset.k_TileId_Empty? " (id:" + Tileset.SelectedTileId + ")" : "";

            EditorGUILayout.LabelField("Tile Palette" + sTileIdLabel, EditorStyles.boldLabel);

            // keeps values safe
            m_tileViewRowLength = Mathf.Max(1, m_tileViewRowLength);

            float tileAreaWidth  = m_tileViewRowLength * (Tileset.VisualTileSize.x + visualTilePadding) + 4f;
            float tileAreaHeight = (Tileset.VisualTileSize.y + visualTilePadding) * (1 + (m_visibleTileCount - 1) / m_tileViewRowLength) + 4f;

            m_tileViewRowLength = m_viewMode == eViewMode.TileView && tileView != null ? tileView.tileSelection.rowLength : Tileset.TileRowLength;

            m_tilesScrollPos = EditorGUILayout.BeginScrollView(m_tilesScrollPos, m_scrollStyle);
            {
                // Scroll Moving Drag
                if (e.type == EventType.MouseDrag && (e.button == 1 || e.button == 2))
                {
                    m_tilesScrollPos -= e.delta;
                }
                else
                {
                    DoAutoScroll();
                }

                if (e.isMouse)
                {
                    m_lastTileScrollMousePos = e.mousePosition;
                }
                if (Tileset.Tiles != null)
                {
                    GUILayoutUtility.GetRect(tileAreaWidth, tileAreaHeight);
                    m_visibleTileCount = 0;
                    List <uint> visibleTileList = new List <uint>();
                    int         tileViewWidth   = m_viewMode == eViewMode.Tileset ? Tileset.Width : tileView.tileSelection.rowLength;
                    int         tileViewHeight  = m_viewMode == eViewMode.Tileset ? Tileset.Height : ((tileView.tileSelection.selectionData.Count - 1) / tileView.tileSelection.rowLength) + 1;
                    int         totalCount      = ((((tileViewWidth - 1) / m_tileViewRowLength) + 1) * m_tileViewRowLength) * tileViewHeight;
                    for (int i = 0; i < totalCount; ++i)
                    {
                        int  tileId   = GetTileIdFromIdx(i, m_tileViewRowLength, tileViewWidth, tileViewHeight);
                        uint tileData = (uint)tileId;
                        if (m_viewMode == eViewMode.TileView && tileId != Tileset.k_TileId_Empty)
                        {
                            tileData = tileView.tileSelection.selectionData[tileId];
                            tileId   = (int)(tileData & Tileset.k_TileDataMask_TileId);
                        }
                        Tile tile = tileId != Tileset.k_TileId_Empty && tileId < Tileset.Tiles.Count ? Tileset.Tiles[tileId] : null;
                        visibleTileList.Add(tileData);

                        int  tx          = m_visibleTileCount % m_tileViewRowLength;
                        int  ty          = m_visibleTileCount / m_tileViewRowLength;
                        Rect rVisualTile = new Rect(2 + tx * (Tileset.VisualTileSize.x + visualTilePadding), 2 + ty * (Tileset.VisualTileSize.y + visualTilePadding), Tileset.VisualTileSize.x, Tileset.VisualTileSize.y);

                        // Optimization, skipping not visible tiles
                        Rect rLocalVisualTile = rVisualTile; rLocalVisualTile.position -= m_tilesScrollPos;
                        if (!rLocalVisualTile.Overlaps(m_rTileScrollSize))
                        {
                            ; // Do Nothing
                        }
                        else
                        //---
                        {
                            // Draw Tile
                            if (tile == null)
                            {
                                HandlesEx.DrawRectWithOutline(rVisualTile, new Color(0f, 0f, 0f, 0.2f), new Color(0f, 0f, 0f, 0.2f));
                            }
                            else
                            {
                                HandlesEx.DrawRectWithOutline(rVisualTile, new Color(0f, 0f, 0f, 0.1f), new Color(0f, 0f, 0f, 0.1f));
                                TilesetEditor.DoGUIDrawTileFromTileData(rVisualTile, tileData, Tileset);
                            }

                            Rect rTileRect = new Rect(2 + tx * (Tileset.VisualTileSize.x + visualTilePadding), 2 + ty * (Tileset.VisualTileSize.y + visualTilePadding), (Tileset.VisualTileSize.x + visualTilePadding), (Tileset.VisualTileSize.y + visualTilePadding));
                            if (rVisualTile.Contains(e.mousePosition))
                            {
                                if (e.type == EventType.MouseDrag && e.button == 0)
                                {
                                    m_pointedTileIdxRect = new KeyValuePair <int, Rect>(m_visibleTileCount, rTileRect);
                                }
                                else if (e.type == EventType.MouseDown && e.button == 0)
                                {
                                    m_startDragTileIdxRect = m_pointedTileIdxRect = m_endDragTileIdxRect = new KeyValuePair <int, Rect>(m_visibleTileCount, rTileRect);
                                }
                                else if (e.type == EventType.MouseUp && e.button == 0)
                                {
                                    m_endDragTileIdxRect = new KeyValuePair <int, Rect>(m_visibleTileCount, rTileRect);
                                    DoSetTileSelection();
                                }
                            }

                            if ((isLeftMouseReleased || isRightMouseReleased) && isInsideTileScrollArea && rVisualTile.Contains(e.mousePosition) &&
                                (m_startDragTileIdxRect.Key == m_endDragTileIdxRect.Key) && // and there is not dragging selection
                                m_rTileScrollSize.Contains(e.mousePosition - m_tilesScrollPos))   // and it's inside the scroll area
                            {
                                Tileset.SelectedTileId = tileId;

                                //Give focus to SceneView to get key events
                                FocusSceneView();

                                if (isRightMouseReleased)
                                {
                                    TilePropertiesWindow.Show(Tileset);
                                }
                            }
                            else if (tile != null && Tileset.SelectedTileId == tileId)
                            {
                                HandlesEx.DrawRectWithOutline(rTileRect, new Color(0f, 0f, 0f, 0.1f), new Color(1f, 1f, 0f, 1f));
                            }
                        }

                        ++m_visibleTileCount;
                    }
                    m_visibleTileList = visibleTileList;

                    // Draw selection rect
                    if (m_startDragTileIdxRect.Key != m_pointedTileIdxRect.Key /*&& m_startDragTileIdxRect.Key == m_endDragTileIdxRect.Key*/)
                    {
                        Rect rSelection = new Rect(m_startDragTileIdxRect.Value.center, m_pointedTileIdxRect.Value.center - m_startDragTileIdxRect.Value.center);
                        rSelection.Set(Mathf.Min(rSelection.xMin, rSelection.xMax), Mathf.Min(rSelection.yMin, rSelection.yMax), Mathf.Abs(rSelection.width), Mathf.Abs(rSelection.height));
                        rSelection.xMin -= m_startDragTileIdxRect.Value.width / 2;
                        rSelection.xMax += m_startDragTileIdxRect.Value.width / 2;
                        rSelection.yMin -= m_startDragTileIdxRect.Value.height / 2;
                        rSelection.yMax += m_startDragTileIdxRect.Value.height / 2;
                        HandlesEx.DrawRectWithOutline(rSelection, new Color(0f, 0f, 0f, 0.1f), new Color(1f, 1f, 1f, 1f));
                    }
                }
            }
            EditorGUILayout.EndScrollView();
            if (e.type == EventType.Repaint)
            {
                m_rTileScrollArea          = GUILayoutUtility.GetLastRect();
                m_rTileScrollSize          = m_rTileScrollArea;
                m_rTileScrollSize.position = Vector2.zero; // reset position to the Contains and Overlaps inside the tile scroll view without repositioning the position of local positions
                if (tileAreaWidth > m_rTileScrollSize.width)
                {
                    m_rTileScrollSize.height -= GUI.skin.verticalScrollbar.fixedWidth;
                }
                if (tileAreaHeight > m_rTileScrollSize.height)
                {
                    m_rTileScrollSize.width -= GUI.skin.verticalScrollbar.fixedWidth;
                }
            }

            EditorGUILayout.BeginHorizontal();
            string sBrushIdLabel = Tileset.SelectedBrushId > 0 ? " (id:" + Tileset.SelectedBrushId + ")" : "";

            EditorGUILayout.LabelField("Brush Palette" + sBrushIdLabel, EditorStyles.boldLabel);
            m_displayBrushReordList = EditorUtils.DoToggleButton("Display List", m_displayBrushReordList);
            EditorGUILayout.EndHorizontal();

            int tileRowLength = (int)(m_rTileScrollSize.width / (Tileset.VisualTileSize.x + visualTilePadding));

            if (tileRowLength <= 0)
            {
                tileRowLength = 1;
            }
            float fBrushesScrollMaxHeight = Screen.height / 4;
            //commented because m_rTileScrollSize.width.height was changed to Screen.height;  fBrushesScrollMaxHeight -= fBrushesScrollMaxHeight % 2; // sometimes because size of tile scroll affects size of brush scroll, the height is dancing between +-1, so this is always taking the pair value
            float fBrushesScrollHeight = Mathf.Min(fBrushesScrollMaxHeight, 4 + (Tileset.VisualTileSize.y + visualTilePadding) * (1 + (Tileset.Brushes.Count / tileRowLength)));

            EditorGUILayout.BeginVertical(GUILayout.MinHeight(fBrushesScrollHeight));
            if (m_displayBrushReordList)
            {
                DisplayBrushReorderableList();
            }
            else
            {
                bool isRefreshBrushes = false;
                m_brushesScrollPos = EditorGUILayout.BeginScrollView(m_brushesScrollPos, m_scrollStyle);
                {
                    Rect rScrollView = new Rect(0, 0, m_rTileScrollSize.width, 0);
                    tileRowLength = Mathf.Clamp((int)rScrollView.width / (int)(Tileset.VisualTileSize.x + visualTilePadding), 1, tileRowLength);
                    if (Tileset.Brushes != null)
                    {
                        GUILayout.Space((Tileset.VisualTileSize.y + visualTilePadding) * (1 + (Tileset.Brushes.Count - 1) / tileRowLength));
                        for (int i = 0; i < Tileset.Brushes.Count; ++i)
                        {
                            Tileset.BrushContainer brushCont = Tileset.Brushes[i];
                            if (brushCont.BrushAsset == null)
                            {
                                isRefreshBrushes = true;
                                continue;
                            }

                            int  tx          = i % tileRowLength;
                            int  ty          = i / tileRowLength;
                            Rect rVisualTile = new Rect(2 + tx * (Tileset.VisualTileSize.x + visualTilePadding), 2 + ty * (Tileset.VisualTileSize.y + visualTilePadding), Tileset.VisualTileSize.x, Tileset.VisualTileSize.y);
                            //Fix Missing Tileset reference
                            if (brushCont.BrushAsset.Tileset == null)
                            {
                                Debug.LogWarning("Fixed missing tileset reference in brush " + brushCont.BrushAsset.name + " Id(" + brushCont.Id + ")");
                                brushCont.BrushAsset.Tileset = Tileset;
                            }
                            uint tileData = Tileset.k_TileData_Empty;
                            if (brushCont.BrushAsset.IsAnimated())
                            {
                                tileData = brushCont.BrushAsset.GetAnimTileData();
                            }
                            else
                            {
                                tileData = brushCont.BrushAsset.PreviewTileData();
                            }
                            TilesetEditor.DoGUIDrawTileFromTileData(rVisualTile, tileData, Tileset, brushCont.BrushAsset.GetAnimUV());
                            if ((isLeftMouseReleased || isRightMouseReleased || m_dblClick.IsDblClick) && isInsideBrushScrollArea && rVisualTile.Contains(Event.current.mousePosition))
                            {
                                Tileset.SelectedBrushId = brushCont.Id;
                                RemoveTileSelection();
                                if (m_dblClick.IsDblClick)
                                {
                                    EditorGUIUtility.PingObject(brushCont.BrushAsset);
                                    m_selectBrushInInspector = brushCont.BrushAsset;
                                }
                                if (isRightMouseReleased)
                                {
                                    TilePropertiesWindow.Show(Tileset);
                                }
                            }
                            else if (Tileset.SelectedBrushId == brushCont.Id)
                            {
                                Rect rSelection = new Rect(2 + tx * (Tileset.VisualTileSize.x + visualTilePadding), 2 + ty * (Tileset.VisualTileSize.y + visualTilePadding), (Tileset.VisualTileSize.x + visualTilePadding), (Tileset.VisualTileSize.y + visualTilePadding));
                                HandlesEx.DrawRectWithOutline(rSelection, new Color(0f, 0f, 0f, 0.1f), new Color(1f, 1f, 0f, 1f));
                            }
                        }
                    }

                    if (isRefreshBrushes)
                    {
                        Tileset.RemoveNullBrushes();
                    }
                }
                EditorGUILayout.EndScrollView();
                if (e.type == EventType.Repaint)
                {
                    m_rBrushScrollArea = GUILayoutUtility.GetLastRect();
                }
            }
            EditorGUILayout.EndVertical();

            if (GUILayout.Button("Import all brushes found"))
            {
                TilesetEditor.AddAllBrushesFoundInTheProject(Tileset);
                EditorUtility.SetDirty(Tileset);
            }
        }
Ejemplo n.º 9
0
        public void Display()
        {
            AssetPreview.SetPreviewTextureCacheSize(256); //FIX clickeing issues when displaying multiple prefab previews (when a tile has a prefab attached
            Event e = Event.current;

            m_dblClick.Update();

            //FIX: when a tileset is changed, the layout change and during some frames, the BeginScrollView could return wrong values
            // This will make sure the scroll position is updated after mouse is over the control
            if (e.isMouse || e.type == EventType.ScrollWheel)
            {
                m_updateScrollPos = true;
            }

            // This way a gui exception is avoided
            if (e.type == EventType.Layout && m_selectBrushInInspector != null)
            {
                Selection.activeObject   = m_selectBrushInInspector;
                m_selectBrushInInspector = null;
            }

            if (m_lastTime == 0f)
            {
                m_lastTime = Time.realtimeSinceStartup;
            }
            m_timeDt   = Time.realtimeSinceStartup - m_lastTime;
            m_lastTime = Time.realtimeSinceStartup;

            if (Tileset == null)
            {
                EditorGUILayout.HelpBox("There is no tileset selected", MessageType.Info);
                return;
            }
            else if (Tileset.AtlasTexture == null)
            {
                EditorGUILayout.HelpBox("There is no atlas texture set", MessageType.Info);
                return;
            }
            else if (Tileset.Tiles.Count == 0)
            {
                EditorGUILayout.HelpBox("There are no tiles to show in the current tileset", MessageType.Info);
                return;
            }

            m_sharedData = GetSharedTilesetData(Tileset);

            float visualTilePadding       = 1;
            bool  isLeftMouseReleased     = e.type == EventType.MouseUp && e.button == 0;
            bool  isRightMouseReleased    = e.type == EventType.MouseUp && e.button == 1;
            bool  isInsideTileScrollArea  = e.isMouse && m_rTileScrollArea.Contains(e.mousePosition);
            bool  isInsideBrushScrollArea = e.isMouse && m_rBrushScrollArea.Contains(e.mousePosition);

            // Create TileView ReorderableList
            if (m_sharedData.tileViewList == null || m_sharedData.tileViewList.list != Tileset.TileViews)
            {
                m_sharedData.tileViewList = TilesetEditor.CreateTileViewReorderableList(Tileset);
                m_sharedData.tileViewList.onSelectCallback += (ReorderableList list) =>
                {
                    /* NOTE: this will select the tileview for the painting brush. Commented just in case.
                     * if(list.index >= 0)
                     * {
                     *  TileSelection tileSelection = Tileset.TileViews[list.index].tileSelection.Clone();
                     *  tileSelection.FlipVertical();
                     *  Tileset.TileSelection = tileSelection;
                     * }
                     * else*/
                    RemoveTileSelection();
                };
                m_sharedData.tileViewList.onRemoveCallback += (ReorderableList list) =>
                {
                    RemoveTileSelection();
                };
            }

            // Draw TileView ReorderableList
            {
                GUI.color = Color.cyan;
                GUILayout.BeginVertical(Styles.Instance.customBox);
                m_sharedData.tileViewList.index = Mathf.Clamp(m_sharedData.tileViewList.index, -1, Tileset.TileViews.Count - 1);
                m_sharedData.tileViewList.DoLayoutList();
                Rect rList = GUILayoutUtility.GetLastRect();
                if (e.isMouse && !rList.Contains(e.mousePosition))
                {
                    m_sharedData.tileViewList.ReleaseKeyboardFocus();
                }
                GUILayout.EndVertical();
                GUI.color = Color.white;
            }
            TileView tileView = m_sharedData.tileViewList != null && m_sharedData.tileViewList.index >= 0 ? Tileset.TileViews[m_sharedData.tileViewList.index] : null;

            if (tileView == null)
            {
                Tileset.TileRowLength = Mathf.Clamp(EditorGUILayout.IntField("TileRowLength", Tileset.TileRowLength), 1, Tileset.Width);
            }


            List <string> viewNameList = new List <string>()
            {
                "(All)"
            };

            viewNameList.AddRange(Tileset.TileViews.Select(x => x.name));
            string[] tileViewNames  = viewNameList.ToArray();
            int[]    tileViewValues = Enumerable.Range(-1, Tileset.TileViews.Count + 1).ToArray();
            EditorGUI.BeginChangeCheck();
            m_sharedData.tileViewList.index = EditorGUILayout.IntPopup("Tileset View", m_sharedData.tileViewList.index, tileViewNames, tileViewValues);
            if (EditorGUI.EndChangeCheck())
            {
                RemoveTileSelection();
            }

            // Draw Background Color Selector
            Tileset.BackgroundColor = EditorGUILayout.ColorField("Background Color", Tileset.BackgroundColor);
            if (m_prevBgColor != Tileset.BackgroundColor || Styles.Instance.scrollStyle.normal.background == null)
            {
                m_prevBgColor = Tileset.BackgroundColor;
                if (Styles.Instance.scrollStyle.normal.background == null)
                {
                    Styles.Instance.scrollStyle.normal.background = new Texture2D(1, 1)
                    {
                        hideFlags = HideFlags.DontSave
                    }
                }
                ;
                Styles.Instance.scrollStyle.normal.background.SetPixel(0, 0, Tileset.BackgroundColor);
                Styles.Instance.scrollStyle.normal.background.Apply();
            }
            //---

            // Draw Zoom Selector
            EditorGUILayout.BeginHorizontal();
            GUILayout.Label(EditorGUIUtility.FindTexture("ViewToolZoom"), GUILayout.Width(35f));
            float visualTileZoom = EditorGUILayout.Slider(Tileset.VisualTileSize.x / Tileset.TilePxSize.x, 0.25f, 4f);

            Tileset.VisualTileSize = visualTileZoom * Tileset.TilePxSize;
            if (GUILayout.Button("Reset", GUILayout.Width(50f)))
            {
                Tileset.VisualTileSize = new Vector2(32f * Tileset.TilePxSize.x / Tileset.TilePxSize.y, 32f);
            }
            EditorGUILayout.EndHorizontal();
            //---

            string sTileIdLabel = Tileset.SelectedTileId != Tileset.k_TileId_Empty? " (id:" + Tileset.SelectedTileId + ")" : "";

            EditorGUILayout.LabelField("Tile Palette" + sTileIdLabel, EditorStyles.boldLabel);

            // keeps values safe
            m_sharedData.tileViewRowLength = Mathf.Max(1, m_sharedData.tileViewRowLength);

            float tileAreaWidth  = m_sharedData.tileViewRowLength * (Tileset.VisualTileSize.x + visualTilePadding) + 4f;
            float tileAreaHeight = (Tileset.VisualTileSize.y + visualTilePadding) * (1 + (m_visibleTileCount - 1) / m_sharedData.tileViewRowLength) + 4f;

            m_sharedData.tileViewRowLength = tileView != null ? tileView.tileSelection.rowLength : Tileset.TileRowLength;

            //float minTileScrollHeight = (Tileset.VisualTileSize.y + visualTilePadding) * 6f;// NOTE: GUILayout.MinHeight is not working with BeginScrollView
            Vector2 tilesScrollPos = EditorGUILayout.BeginScrollView(m_sharedData.tilesScrollPos, Styles.Instance.scrollStyle /*, GUILayout.MinHeight(minTileScrollHeight)*/);

            if (m_updateScrollPos)
            {
                m_sharedData.tilesScrollPos = tilesScrollPos;
            }
            {
                // Scroll Moving Drag
                if (e.type == EventType.MouseDrag && (e.button == 1 || e.button == 2))
                {
                    m_sharedData.tilesScrollPos -= e.delta;
                }
                else
                {
                    DoAutoScroll();
                }

                if (e.isMouse)
                {
                    m_lastTileScrollMousePos = e.mousePosition;
                }
                if (Tileset.Tiles != null)
                {
                    GUILayoutUtility.GetRect(tileAreaWidth, tileAreaHeight);
                    m_visibleTileCount = 0;
                    List <uint> visibleTileList = new List <uint>();
                    int         tileViewWidth   = tileView != null ? tileView.tileSelection.rowLength : Tileset.Width;
                    int         tileViewHeight  = tileView != null ? ((tileView.tileSelection.selectionData.Count - 1) / tileView.tileSelection.rowLength) + 1 : Tileset.Height;
                    int         totalCount      = ((((tileViewWidth - 1) / m_sharedData.tileViewRowLength) + 1) * m_sharedData.tileViewRowLength) * tileViewHeight;
                    for (int i = 0; i < totalCount; ++i)
                    {
                        int  tileId   = GetTileIdFromIdx(i, m_sharedData.tileViewRowLength, tileViewWidth, tileViewHeight);
                        uint tileData = (uint)tileId;
                        if (tileView != null && tileId != Tileset.k_TileId_Empty)
                        {
                            tileData = tileView.tileSelection.selectionData[tileId];
                            tileId   = (int)(tileData & Tileset.k_TileDataMask_TileId);
                        }
                        Tile tile = Tileset.GetTile(tileId);
                        visibleTileList.Add(tileData);

                        int  tx          = m_visibleTileCount % m_sharedData.tileViewRowLength;
                        int  ty          = m_visibleTileCount / m_sharedData.tileViewRowLength;
                        Rect rVisualTile = new Rect(2 + tx * (Tileset.VisualTileSize.x + visualTilePadding), 2 + ty * (Tileset.VisualTileSize.y + visualTilePadding), Tileset.VisualTileSize.x, Tileset.VisualTileSize.y);

                        // Optimization, skipping not visible tiles
                        Rect rLocalVisualTile = rVisualTile; rLocalVisualTile.position -= m_sharedData.tilesScrollPos;
                        if (!rLocalVisualTile.Overlaps(m_rTileScrollSize))
                        {
                            ; // Do Nothing
                        }
                        else
                        //---
                        {
                            // Draw Tile
                            if (tile == null)
                            {
                                HandlesEx.DrawRectWithOutline(rVisualTile, new Color(0f, 0f, 0f, 0.2f), new Color(0f, 0f, 0f, 0.2f));
                            }
                            else
                            {
                                HandlesEx.DrawRectWithOutline(rVisualTile, new Color(0f, 0f, 0f, 0.1f), new Color(0f, 0f, 0f, 0.1f));
                                TilesetEditor.DoGUIDrawTileFromTileData(rVisualTile, tileData, Tileset);
                            }

                            Rect rTileRect = new Rect(2 + tx * (Tileset.VisualTileSize.x + visualTilePadding), 2 + ty * (Tileset.VisualTileSize.y + visualTilePadding), (Tileset.VisualTileSize.x + visualTilePadding), (Tileset.VisualTileSize.y + visualTilePadding));
                            if (rVisualTile.Contains(e.mousePosition))
                            {
                                if (e.type == EventType.MouseDrag && e.button == 0)
                                {
                                    m_sharedData.pointedTileIdxRect = new KeyValuePair <int, Rect>(m_visibleTileCount, rTileRect);
                                }
                                else if (e.type == EventType.MouseDown && e.button == 0)
                                {
                                    m_sharedData.startDragTileIdxRect = m_sharedData.pointedTileIdxRect = m_sharedData.endDragTileIdxRect = new KeyValuePair <int, Rect>(m_visibleTileCount, rTileRect);
                                }
                                else if (e.type == EventType.MouseUp && e.button == 0)
                                {
                                    m_sharedData.endDragTileIdxRect = new KeyValuePair <int, Rect>(m_visibleTileCount, rTileRect);
                                    DoSetTileSelection();
                                }
                            }

                            if ((isLeftMouseReleased || isRightMouseReleased) && isInsideTileScrollArea && rVisualTile.Contains(e.mousePosition) &&
                                (m_sharedData.startDragTileIdxRect.Key == m_sharedData.endDragTileIdxRect.Key) && // and there is not dragging selection
                                m_rTileScrollSize.Contains(e.mousePosition - m_sharedData.tilesScrollPos))   // and it's inside the scroll area
                            {
                                Tileset.SelectedTileId = tileId;

                                //Give focus to SceneView to get key events
                                FocusSceneView();

                                if (isRightMouseReleased)
                                {
                                    TilePropertiesWindow.Show(Tileset);
                                }
                            }
                            else if (tile != null && Tileset.SelectedTileId == tileId)
                            {
                                HandlesEx.DrawRectWithOutline(rTileRect, new Color(0f, 0f, 0f, 0.1f), new Color(1f, 1f, 0f, 1f));
                            }
                        }

                        ++m_visibleTileCount;
                    }
                    m_visibleTileList = visibleTileList;

                    // Draw selection rect
                    if (m_sharedData.startDragTileIdxRect.Key != m_sharedData.pointedTileIdxRect.Key /*&& m_startDragTileIdxRect.Key == m_endDragTileIdxRect.Key*/)
                    {
                        Rect rSelection = new Rect(m_sharedData.startDragTileIdxRect.Value.center, m_sharedData.pointedTileIdxRect.Value.center - m_sharedData.startDragTileIdxRect.Value.center);
                        rSelection.Set(Mathf.Min(rSelection.xMin, rSelection.xMax), Mathf.Min(rSelection.yMin, rSelection.yMax), Mathf.Abs(rSelection.width), Mathf.Abs(rSelection.height));
                        rSelection.xMin -= m_sharedData.startDragTileIdxRect.Value.width / 2;
                        rSelection.xMax += m_sharedData.startDragTileIdxRect.Value.width / 2;
                        rSelection.yMin -= m_sharedData.startDragTileIdxRect.Value.height / 2;
                        rSelection.yMax += m_sharedData.startDragTileIdxRect.Value.height / 2;
                        HandlesEx.DrawRectWithOutline(rSelection, new Color(0f, 0f, 0f, 0.1f), new Color(1f, 1f, 1f, 1f));
                    }
                }
            }
            EditorGUILayout.EndScrollView();
            if (e.type == EventType.Repaint)
            {
                m_rTileScrollArea          = GUILayoutUtility.GetLastRect();
                m_rTileScrollSize          = m_rTileScrollArea;
                m_rTileScrollSize.position = Vector2.zero; // reset position to the Contains and Overlaps inside the tile scroll view without repositioning the position of local positions
                if (tileAreaWidth > m_rTileScrollSize.width)
                {
                    m_rTileScrollSize.height -= GUI.skin.verticalScrollbar.fixedWidth;
                }
                if (tileAreaHeight > m_rTileScrollSize.height)
                {
                    m_rTileScrollSize.width -= GUI.skin.verticalScrollbar.fixedWidth;
                }
            }

            EditorGUILayout.BeginHorizontal();
            string sBrushIdLabel = Tileset.SelectedBrushId > 0 ? " (id:" + Tileset.SelectedBrushId + ")" : "";

            EditorGUILayout.LabelField("Brush Palette" + sBrushIdLabel, EditorStyles.boldLabel);
            m_displayBrushReordList = EditorUtils.DoToggleButton("Display List", m_displayBrushReordList);
            EditorGUILayout.EndHorizontal();
            Tileset.BrushTypeMask = EditorGUILayout.MaskField("Brush Mask", Tileset.BrushTypeMask, Tileset.GetBrushTypeArray());

            int tileRowLength = (int)(m_rTileScrollSize.width / (Tileset.VisualTileSize.x + visualTilePadding));

            if (tileRowLength <= 0)
            {
                tileRowLength = 1;
            }
            float fBrushesScrollMaxHeight = Screen.height / 4;
            //commented because m_rTileScrollSize.width.height was changed to Screen.height;  fBrushesScrollMaxHeight -= fBrushesScrollMaxHeight % 2; // sometimes because size of tile scroll affects size of brush scroll, the height is dancing between +-1, so this is always taking the pair value
            float fBrushesScrollHeight = Mathf.Min(fBrushesScrollMaxHeight, 4 + (Tileset.VisualTileSize.y + visualTilePadding) * (1 + (Tileset.Brushes.Count / tileRowLength)));

            EditorGUILayout.BeginVertical(GUILayout.MinHeight(fBrushesScrollHeight));
            if (m_displayBrushReordList)
            {
                DisplayBrushReorderableList();
            }
            else
            {
                bool    refreshBrushes   = false;
                Vector2 brushesScrollPos = EditorGUILayout.BeginScrollView(m_sharedData.brushesScrollPos, Styles.Instance.scrollStyle);
                if (m_updateScrollPos)
                {
                    m_sharedData.brushesScrollPos = brushesScrollPos;
                }
                {
                    Rect rScrollView = new Rect(0, 0, m_rTileScrollSize.width, 0);
                    tileRowLength = Mathf.Clamp((int)rScrollView.width / (int)(Tileset.VisualTileSize.x + visualTilePadding), 1, tileRowLength);
                    if (Tileset.Brushes != null)
                    {
                        GUILayout.Space((Tileset.VisualTileSize.y + visualTilePadding) * (1 + (Tileset.Brushes.Count - 1) / tileRowLength));
                        for (int i = 0, idx = 0; i < Tileset.Brushes.Count; ++i, ++idx)
                        {
                            Tileset.BrushContainer brushCont = Tileset.Brushes[i];
                            if (brushCont.BrushAsset == null || brushCont.BrushAsset.Tileset != Tileset)
                            {
                                refreshBrushes = true;
                                continue;
                            }
                            if (!brushCont.BrushAsset.ShowInPalette || !Tileset.IsBrushVisibleByTypeMask(brushCont.BrushAsset))
                            {
                                --idx;
                                continue;
                            }

                            int  tx          = idx % tileRowLength;
                            int  ty          = idx / tileRowLength;
                            Rect rVisualTile = new Rect(2 + tx * (Tileset.VisualTileSize.x + visualTilePadding), 2 + ty * (Tileset.VisualTileSize.y + visualTilePadding), Tileset.VisualTileSize.x, Tileset.VisualTileSize.y);
                            //Fix Missing Tileset reference
                            if (brushCont.BrushAsset.Tileset == null)
                            {
                                Debug.LogWarning("Fixed missing tileset reference in brush " + brushCont.BrushAsset.name + " Id(" + brushCont.Id + ")");
                                brushCont.BrushAsset.Tileset = Tileset;
                            }
                            uint tileData = Tileset.k_TileData_Empty;
                            if (brushCont.BrushAsset.IsAnimated())
                            {
                                tileData = brushCont.BrushAsset.GetAnimTileData();
                            }
                            else
                            {
                                tileData = brushCont.BrushAsset.PreviewTileData();
                            }
                            TilesetEditor.DoGUIDrawTileFromTileData(rVisualTile, tileData, Tileset, brushCont.BrushAsset.GetAnimUV());
                            if ((isLeftMouseReleased || isRightMouseReleased || m_dblClick.IsDblClick) && isInsideBrushScrollArea && rVisualTile.Contains(Event.current.mousePosition))
                            {
                                Tileset.SelectedBrushId = brushCont.Id;
                                RemoveTileSelection();
                                if (m_dblClick.IsDblClick)
                                {
                                    EditorGUIUtility.PingObject(brushCont.BrushAsset);
                                    m_selectBrushInInspector = brushCont.BrushAsset;
                                }
                                if (isRightMouseReleased)
                                {
                                    TilePropertiesWindow.Show(Tileset);
                                }
                            }
                            else if (Tileset.SelectedBrushId == brushCont.Id)
                            {
                                Rect rSelection = new Rect(2 + tx * (Tileset.VisualTileSize.x + visualTilePadding), 2 + ty * (Tileset.VisualTileSize.y + visualTilePadding), (Tileset.VisualTileSize.x + visualTilePadding), (Tileset.VisualTileSize.y + visualTilePadding));
                                HandlesEx.DrawRectWithOutline(rSelection, new Color(0f, 0f, 0f, 0.1f), new Color(1f, 1f, 0f, 1f));
                            }
                        }
                    }

                    if (refreshBrushes)
                    {
                        Tileset.RemoveInvalidBrushes();
                        Tileset.UpdateBrushTypeArray();
                    }
                }
                EditorGUILayout.EndScrollView();
                if (e.type == EventType.Repaint)
                {
                    m_rBrushScrollArea = GUILayoutUtility.GetLastRect();
                }
            }
            EditorGUILayout.EndVertical();

            if (GUILayout.Button("Import all brushes found in the project"))
            {
                TilesetEditor.AddAllBrushesFoundInTheProject(Tileset);
                EditorUtility.SetDirty(Tileset);
            }
        }
Ejemplo n.º 10
0
        bool DoToolBar()
        {
            bool       isMouseInsideToolbar = false;
            Tilemap    tilemap               = (Tilemap)target;
            GUIContent brushCoords           = new GUIContent("<b> Brush Pos: (" + m_mouseGridX + "," + m_mouseGridY + ")</b>");
            GUIContent selectedTileOrBrushId = null;

            if (tilemap.Tileset.SelectedTileId != Tileset.k_TileId_Empty)
            {
                selectedTileOrBrushId = new GUIContent("<b> Selected Tile Id: " + tilemap.Tileset.SelectedTileId.ToString() + "</b>");
            }
            else if (tilemap.Tileset.SelectedBrushId != Tileset.k_BrushId_Default)
            {
                selectedTileOrBrushId = new GUIContent("<b> Selected Brush Id: " + tilemap.Tileset.SelectedBrushId.ToString() + "</b>");
            }
            else
            {
                selectedTileOrBrushId = new GUIContent("<b> Empty tile selected</b>");
            }

            Rect rTools = new Rect(4f, 4f, Mathf.Max(Mathf.Max(Styles.Instance.toolbarBoxStyle.CalcSize(brushCoords).x, Styles.Instance.toolbarBoxStyle.CalcSize(selectedTileOrBrushId).x) + 4f, 180f), 54f);

            Handles.BeginGUI();
            GUILayout.BeginArea(rTools);
            HandlesEx.DrawRectWithOutline(new Rect(Vector2.zero, rTools.size), s_toolbarBoxBgColor, s_toolbarBoxOutlineColor);

            GUILayout.Space(2f);
            GUILayout.Label(brushCoords, Styles.Instance.toolbarBoxStyle);
            if (selectedTileOrBrushId != null)
            {
                GUILayout.Label(selectedTileOrBrushId, Styles.Instance.toolbarBoxStyle);
            }
            GUILayout.Label("<b> F1 - Display Help</b>", Styles.Instance.toolbarBoxStyle);
            GUILayout.Label("<b> F5 - Refresh Tilemap</b>", Styles.Instance.toolbarBoxStyle);
            GUILayout.EndArea();

            // Display ToolBar
            int  buttonNb = System.Enum.GetValues(typeof(ToolIcons.eToolIcon)).Length;
            Rect rToolBar = new Rect(rTools.xMax + 4f, rTools.y, buttonNb * 32f, 32f);

            isMouseInsideToolbar = rToolBar.Contains(Event.current.mousePosition);
            GUILayout.BeginArea(rToolBar);
            HandlesEx.DrawRectWithOutline(new Rect(Vector2.zero, rToolBar.size), s_toolbarBoxBgColor, s_toolbarBoxOutlineColor);
            GUILayout.BeginHorizontal();

            int  buttonPadding = 4;
            Rect rToolBtn      = new Rect(buttonPadding, buttonPadding, rToolBar.size.y - 2 * buttonPadding, rToolBar.size.y - 2 * buttonPadding);

            foreach (ToolIcons.eToolIcon toolIcon in System.Enum.GetValues(typeof(ToolIcons.eToolIcon)))
            {
                _DoToolbarButton(rToolBtn, toolIcon);
                rToolBtn.x = rToolBtn.xMax + 2 * buttonPadding;
            }
            GUI.color = Color.white;
            GUILayout.EndHorizontal();
            GUILayout.EndArea();
            //---

            Handles.EndGUI();

            if (m_displayHelpBox)
            {
                DisplayHelpBox();
            }
            if (Event.current.type == EventType.KeyDown)
            {
                if (Event.current.keyCode == KeyCode.F1)
                {
                    m_displayHelpBox = !m_displayHelpBox;
                }
                else if (Event.current.keyCode == KeyCode.F5)
                {
                    m_tilemap.Refresh(true, true, true, true);
                }
            }

            return(isMouseInsideToolbar);
        }
Ejemplo n.º 11
0
        private void DoPaintInspector()
        {
            Event e = Event.current;

            Tilemap tilemap = (Tilemap)target;

            if (DoToolBar() ||
                DragAndDrop.objectReferences.Length > 0 || // hide brush when user is dragging a prefab into the scene
                EditorWindow.mouseOverWindow != SceneView.currentDrawingSceneView)    // hide brush when it's not over the scene view
            {
                m_brushVisible = false;
                SceneView.RepaintAll();
                return;
            }

            int controlID = GUIUtility.GetControlID(FocusType.Passive);

            HandleUtility.AddDefaultControl(controlID);
            EventType currentEventType = Event.current.GetTypeForControl(controlID);
            bool      skip             = false;
            int       saveControl      = GUIUtility.hotControl;

            try
            {
                if (currentEventType == EventType.Layout)
                {
                    skip = true;
                }
                else if (currentEventType == EventType.ScrollWheel)
                {
                    skip = true;
                }

                if (tilemap.Tileset == null)
                {
                    return;
                }

                if (!skip)
                {
                    if (e.type == EventType.KeyDown)
                    {
                        if (e.keyCode == ShortcutKeys.k_FlipH)
                        {
                            BrushBehaviour.GetOrCreateBrush(tilemap).FlipH(!e.shift);
                            e.Use(); // Use key event
                        }
                        else if (e.keyCode == ShortcutKeys.k_FlipV)
                        {
                            BrushBehaviour.GetOrCreateBrush(tilemap).FlipV(!e.shift);
                            e.Use(); // Use key event
                        }
                        else if (e.keyCode == ShortcutKeys.k_Rot90)
                        {
                            BrushBehaviour.GetOrCreateBrush(tilemap).Rot90(!e.shift);
                            e.Use(); // Use key event
                        }
                        else if (e.keyCode == ShortcutKeys.k_Rot90Back)
                        {
                            BrushBehaviour.GetOrCreateBrush(tilemap).Rot90Back(!e.shift);
                            e.Use(); // Use key event
                        }
                    }

                    EditorGUIUtility.AddCursorRect(new Rect(0f, 0f, (float)Screen.width, (float)Screen.height), MouseCursor.Arrow);
                    GUIUtility.hotControl = controlID;
                    {
                        Plane   chunkPlane = new Plane(tilemap.transform.forward, tilemap.transform.position);
                        Vector2 mousePos   = Event.current.mousePosition; mousePos.y = Screen.height - mousePos.y;
                        Ray     ray        = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
                        float   dist;
                        if (chunkPlane.Raycast(ray, out dist))
                        {
                            Rect rTile = new Rect(0, 0, m_tilemap.CellSize.x, m_tilemap.CellSize.y);
                            rTile.position = tilemap.transform.InverseTransformPoint(ray.GetPoint(dist));

                            Vector2 tilePos = rTile.position;
                            if (tilePos.x < 0)
                            {
                                tilePos.x -= m_tilemap.CellSize.x;
                            }
                            if (tilePos.y < 0)
                            {
                                tilePos.y -= m_tilemap.CellSize.y;
                            }
                            tilePos.x     -= tilePos.x % m_tilemap.CellSize.x;
                            tilePos.y     -= tilePos.y % m_tilemap.CellSize.y;
                            rTile.position = tilePos;


                            Vector2 startPos            = new Vector2(Mathf.Min(m_startDragging.x, m_endDragging.x), Mathf.Min(m_startDragging.y, m_endDragging.y));
                            Vector2 endPos              = new Vector2(Mathf.Max(m_startDragging.x, m_endDragging.x), Mathf.Max(m_startDragging.y, m_endDragging.y));
                            Vector2 selectionSnappedPos = BrushUtil.GetSnappedPosition(startPos, m_tilemap.CellSize);
                            Vector2 selectionSize       = BrushUtil.GetSnappedPosition(endPos, m_tilemap.CellSize) - selectionSnappedPos + m_tilemap.CellSize;

                            BrushBehaviour brush = BrushBehaviour.GetOrCreateBrush(tilemap);
                            // Update brush transform
                            m_localPaintPos = (Vector2)tilemap.transform.InverseTransformPoint(ray.GetPoint(dist));
                            Vector2 brushSnappedPos = BrushUtil.GetSnappedPosition(brush.Offset + m_localPaintPos, m_tilemap.CellSize);
                            brush.transform.rotation   = tilemap.transform.rotation;
                            brush.transform.localScale = tilemap.transform.lossyScale;
                            brush.transform.position   = tilemap.transform.TransformPoint(new Vector3(brushSnappedPos.x, brushSnappedPos.y, -0.01f));
                            //---

                            int prevMouseGridX = m_mouseGridX;
                            int prevMouseGridY = m_mouseGridY;
                            if (e.isMouse)
                            {
                                m_mouseGridX = BrushUtil.GetGridX(m_localPaintPos, tilemap.CellSize);
                                m_mouseGridY = BrushUtil.GetGridY(m_localPaintPos, tilemap.CellSize);
                            }
                            bool isMouseGridChanged = prevMouseGridX != m_mouseGridX || prevMouseGridY != m_mouseGridY;
                            //Update Fill Preview
                            if (GetBrushMode() == eBrushMode.Fill && isMouseGridChanged)
                            {
                                m_fillPreview.Clear();
                                TilemapDrawingUtils.FloodFillPreview(tilemap, brush.Offset + m_localPaintPos, brush.BrushTilemap.GetTileData(0, 0), m_fillPreview);
                            }

                            if (
                                (EditorWindow.focusedWindow == EditorWindow.mouseOverWindow) && // fix painting tiles when closing another window popup over the SceneView like GameObject Selection window
                                (e.type == EventType.MouseDown || e.type == EventType.MouseDrag && isMouseGridChanged)
                                )
                            {
                                if (e.button == 0)
                                {
                                    if (m_dblClick.IsDblClick && brush.BrushTilemap.GridWidth == 1 && brush.BrushTilemap.GridHeight == 1)
                                    {
                                        // Restore previous tiledata modified by Paint, because before the double click, a single click is done before
                                        tilemap.SetTileData(brush.Offset + m_localPaintPos, m_floodFillRestoredTileData);
                                        brush.FloodFill(tilemap, brush.Offset + m_localPaintPos, brush.BrushTilemap.GetTileData(0, 0));
                                    }
                                    // Do a brush paint action
                                    else
                                    {
                                        switch (GetBrushMode())
                                        {
                                        case eBrushMode.Paint:
                                            m_floodFillRestoredTileData = tilemap.GetTileData(m_mouseGridX, m_mouseGridY);
                                            brush.Paint(tilemap, brush.Offset + m_localPaintPos);
                                            break;

                                        case eBrushMode.Erase:
                                            brush.Erase(tilemap, brush.Offset + m_localPaintPos);
                                            break;

                                        case eBrushMode.Fill:
                                            brush.FloodFill(tilemap, brush.Offset + m_localPaintPos, brush.BrushTilemap.GetTileData(0, 0));
                                            break;
                                        }
                                    }
                                }
                                else if (e.button == 1)
                                {
                                    if (e.type == EventType.MouseDown)
                                    {
                                        m_isDragging = true;
                                        brush.BrushTilemap.ClearMap();
                                        m_startDragging = m_endDragging = m_localPaintPos;
                                    }
                                    else
                                    {
                                        m_endDragging = m_localPaintPos;
                                    }
                                }
                            }
                            else if (e.type == EventType.MouseUp)
                            {
                                if (e.button == 1) // right mouse button
                                {
                                    m_isDragging = false;
                                    ResetBrushMode();
                                    // Copy one tile
                                    if (selectionSize.x <= m_tilemap.CellSize.x && selectionSize.y <= m_tilemap.CellSize.y)
                                    {
                                        uint tileData = tilemap.GetTileData(m_localPaintPos);
                                        if (tileData == Tileset.k_TileData_Empty)
                                        {
                                            tilemap.Tileset.SelectedTileId = Tileset.k_TileId_Empty;
                                            brush.BrushTilemap.SetTileData(0, 0, Tileset.k_TileData_Empty);
                                        }
                                        else
                                        {
                                            int brushId = Tileset.GetBrushIdFromTileData(tileData);
                                            int tileId  = Tileset.GetTileIdFromTileData(tileData);

                                            // Select the copied tile in the tileset, alternating between the brush and the tile drawn by the brush
                                            if (brushId > 0 && brushId != tilemap.Tileset.SelectedBrushId)
                                            {
                                                tilemap.Tileset.SelectedBrushId = brushId;
                                            }
                                            else
                                            {
                                                tilemap.Tileset.SelectedTileId = tileId;
                                                brush.BrushTilemap.SetTileData(0, 0, tileData & ~Tileset.k_TileDataMask_BrushId); // keep tile flags
                                            }
                                        }

                                        // Cut tile if key shift is pressed
                                        if (e.shift)
                                        {
                                            int startGridX = BrushUtil.GetGridX(startPos, m_tilemap.CellSize);
                                            int startGridY = BrushUtil.GetGridY(startPos, m_tilemap.CellSize);
                                            brush.CutRect(tilemap, startGridX, startGridY, startGridX, startGridY);
                                        }

                                        brush.BrushTilemap.UpdateMesh();
                                        brush.Offset = Vector2.zero;
                                    }
                                    // copy a rect of tiles
                                    else
                                    {
                                        int startGridX = BrushUtil.GetGridX(startPos, m_tilemap.CellSize);
                                        int startGridY = BrushUtil.GetGridY(startPos, m_tilemap.CellSize);
                                        int endGridX   = BrushUtil.GetGridX(endPos, m_tilemap.CellSize);
                                        int endGridY   = BrushUtil.GetGridY(endPos, m_tilemap.CellSize);

                                        // Cut tile if key shift is pressed
                                        if (e.shift)
                                        {
                                            brush.CutRect(tilemap, startGridX, startGridY, endGridX, endGridY);
                                        }
                                        else
                                        {
                                            brush.CopyRect(tilemap, startGridX, startGridY, endGridX, endGridY);
                                        }
                                        brush.Offset.x = m_endDragging.x > m_startDragging.x ? -(endGridX - startGridX) * tilemap.CellSize.x : 0f;
                                        brush.Offset.y = m_endDragging.y > m_startDragging.y ? -(endGridY - startGridY) * tilemap.CellSize.y : 0f;
                                    }
                                }
                            }

                            if (m_isDragging)
                            {
                                Rect rGizmo = new Rect(selectionSnappedPos, selectionSize);
                                HandlesEx.DrawRectWithOutline(tilemap.transform, rGizmo, new Color(), Color.white);
                            }
                            else // Draw brush border
                            {
                                Rect  rBound = new Rect(brush.BrushTilemap.MapBounds.min, brush.BrushTilemap.MapBounds.size);
                                Color fillColor;
                                switch (GetBrushMode())
                                {
                                case eBrushMode.Paint:
                                    fillColor = new Color(0, 0, 0, 0);
                                    break;

                                case eBrushMode.Erase:
                                    fillColor = new Color(1f, 0f, 0f, 0.1f);
                                    break;

                                case eBrushMode.Fill:
                                    fillColor = new Color(1f, 1f, 0f, 0.2f);
                                    break;

                                default:
                                    fillColor = new Color(0, 0, 0, 0);
                                    break;
                                }
                                HandlesEx.DrawRectWithOutline(brush.transform, rBound, fillColor, new Color(1, 1, 1, 0.2f));
                            }
                        }
                    }

                    if (currentEventType == EventType.MouseDrag && Event.current.button < 2) // 2 is for central mouse button
                    {
                        // avoid dragging the map
                        Event.current.Use();
                    }
                }
            }
            // Avoid loosing the hotControl because of a triggered exception
            catch (System.Exception ex)
            {
                Debug.LogException(ex);
            }

            SceneView.RepaintAll();
            GUIUtility.hotControl = saveControl;
        }
        private bool m_displayAutocompleteBtn = false; // fix gui warning when button appears
        public void Display(Object target, uint[] aTileData, int[] tileIdxMap, int gridWidth, int gridHeight, Vector2 visualTileSize, int[] symbolIdxMap)
        {
            GUI.changed = m_hasChanged;
            m_hasChanged = false;
            m_target = target;
            m_aBrushTileData = aTileData;
            Event e = Event.current;
            bool isRightMouseReleased = e.type == EventType.MouseUp && e.button == 0;
            if (isRightMouseReleased && !m_tileSelectionRect.Contains(e.mousePosition))
            {
                m_selectedTileIdx = -1;
            }

            GUILayout.BeginHorizontal();

            // Draw Autotile Combination Control
            GUI.backgroundColor = Tileset.BackgroundColor;
            GUILayout.BeginScrollView(Vector2.zero, (GUIStyle)"Button", GUILayout.Width(visualTileSize.x * gridWidth), GUILayout.Height(visualTileSize.y * gridHeight + 1f));
            GUI.backgroundColor = Color.white;
            for (int i = 0; i < gridWidth * gridHeight; ++i)
            {
                int gx = i % gridWidth;
                int gy = i / gridHeight;
                int tileIdx = tileIdxMap[i];
                Rect rVisualTile = new Rect(gx * visualTileSize.x, gy * visualTileSize.y, visualTileSize.x, visualTileSize.y);

                int tileId = (int)(m_aBrushTileData[tileIdx] & Tileset.k_TileDataMask_TileId);
                if (tileId != Tileset.k_TileId_Empty)
                {
                    //Rect tileUV = Tileset.Tiles[tileId].uv;
                    //GUI.DrawTextureWithTexCoords(rVisualTile, Tileset.AtlasTexture, tileUV, true);
                    TilesetEditor.DoGUIDrawTileFromTileData(rVisualTile, m_aBrushTileData[tileIdx], Tileset);
                }
                else if (symbolIdxMap != null)
                {
                    GUI.DrawTexture(rVisualTile, GetTileSymbolTexture((byte)symbolIdxMap[i]), ScaleMode.ScaleToFit, true);
                }

                Color bgColor = new Color(1f - Tileset.BackgroundColor.r, 1f - Tileset.BackgroundColor.g, 1f - Tileset.BackgroundColor.b, Tileset.BackgroundColor.a);
                HandlesEx.DrawRectWithOutline(rVisualTile, m_selectedTileIdx == tileIdx ? new Color(0f, 0f, 0f, 0.1f) : new Color(), m_selectedTileIdx == tileIdx ? new Color(1f, 1f, 0f, 1f) : bgColor);

                if (isRightMouseReleased && rVisualTile.Contains(e.mousePosition))
                {
                    m_selectedTileIdx = tileIdx;
                    EditorWindow wnd = EditorWindow.focusedWindow;
                    TileSelectionWindow.Show(Tileset);
                    TileSelectionWindow.Instance.Ping();
                    wnd.Focus();
                    GUI.FocusControl("");
                }
            }
            GUILayout.EndScrollView();

            uint brushTileData = m_selectedTileIdx >= 0 ? m_aBrushTileData[m_selectedTileIdx] : Tileset.k_TileData_Empty;
            brushTileData = DoTileDataPropertiesLayout(brushTileData, Tileset);
            if (m_selectedTileIdx >= 0)
            {
                m_aBrushTileData[m_selectedTileIdx] = brushTileData;
            }

            GUILayout.EndHorizontal();
            if (e.type == EventType.Repaint)
            {
                m_tileSelectionRect = GUILayoutUtility.GetLastRect();
            }

            bool hasEmptyTiles = ArrayUtility.Contains<uint>(m_aBrushTileData, Tileset.k_TileData_Empty);
            m_displayAutocompleteBtn = e.type == EventType.Layout ? !hasEmptyTiles && m_tileIdOff != 0 : m_displayAutocompleteBtn;
            if (m_displayAutocompleteBtn && GUILayout.Button("Autocomplete relative to last change"))
            {
                Undo.RecordObject(m_target, "MultipleTileChanged");
                for (int i = 0; i < tileIdxMap.Length; ++i)
                {
                    int tileIdx = tileIdxMap[i];
                    if (tileIdx != m_tileIdOffSkipIdx)
                    {
                        int brushTileId = (int)(m_aBrushTileData[tileIdx] & Tileset.k_TileDataMask_TileId);
                        brushTileId += m_tileIdOff;
                        if (brushTileId < 0 || brushTileId >= m_tileset.Tiles.Count)
                        {
                            m_aBrushTileData[tileIdx] = Tileset.k_TileData_Empty;
                        }
                        else
                        {
                            m_aBrushTileData[tileIdx] &= ~Tileset.k_TileDataMask_TileId;
                            m_aBrushTileData[tileIdx] |= (uint)(brushTileId & Tileset.k_TileDataMask_TileId);
                        }
                    }
                }
                m_tileIdOff = 0;
                EditorUtility.SetDirty(m_target);
            }

            if (ShowHelpBox)
            {
                EditorGUILayout.HelpBox("Select  a tile from the grid, then select a tile from Tile Selection Window to change the tile.", MessageType.Info);
            }
        }