protected override void PickBrush(BoundsInt position, Vector3Int pickingStart)
        {
            if (grid == null || gridBrush == null)
            {
                return;
            }

            gridBrush.Pick(grid, brushTarget, position, pickingStart);

            if (!InGridEditMode())
            {
                TilemapEditorTool.SetActiveEditorTool(typeof(PaintTool));
            }

            m_ActivePick = new RectInt(position.min.x, position.min.y, position.size.x, position.size.y);
        }
Exemplo n.º 2
0
        private void HandleSelectTool()
        {
            Event evt = Event.current;

            if (evt.type == EventType.MouseDown && evt.button == 0 && !evt.alt && (TilemapEditorTool.IsActive(typeof(SelectTool)) || (TilemapEditorTool.IsActive(typeof(MoveTool)) && evt.control)))
            {
                if (TilemapEditorTool.IsActive(typeof(MoveTool)) && evt.control)
                {
                    TilemapEditorTool.SetActiveEditorTool(typeof(SelectTool));
                }

                m_PreviousMove = null;
                m_MarqueeStart = mouseGridPosition;
                m_MarqueeType  = MarqueeType.Select;

                s_LastActivePaintableGrid = this;
                GUIUtility.hotControl     = m_PermanentControlID;
                Event.current.Use();
            }
            if (evt.rawType == EventType.MouseUp && evt.button == 0 && !evt.alt && m_MarqueeStart.HasValue && isHotControl && TilemapEditorTool.IsActive(typeof(SelectTool)))
            {
                // Check if event only occurred in the PaintableGrid window as evt.type will filter for this
                if (evt.type == EventType.MouseUp && m_MarqueeType == MarqueeType.Select)
                {
                    RectInt rect = GridEditorUtility.GetMarqueeRect(m_MarqueeStart.Value, mouseGridPosition);
                    Select(new BoundsInt(new Vector3Int(rect.xMin, rect.yMin, zPosition), new Vector3Int(rect.size.x, rect.size.y, 1)));
                    Event.current.Use();
                }
                if (evt.control)
                {
                    TilemapEditorTool.SetActiveEditorTool(typeof(MoveTool));
                }
                m_MarqueeStart = null;
                m_MarqueeType  = MarqueeType.None;
                InspectorWindow.RepaintAllInspectors();
                GUIUtility.hotControl = 0;
            }
            if (evt.type == EventType.KeyDown && evt.keyCode == KeyCode.Escape && !m_MarqueeStart.HasValue && !m_PreviousMove.HasValue)
            {
                ClearGridSelection();
                Event.current.Use();
            }
        }
Exemplo n.º 3
0
        private void HandleBrushPaintAndErase()
        {
            Event evt = Event.current;

            if (!IsPaintingEvent(evt) && !IsErasingEvent(evt))
            {
                return;
            }

            switch (evt.type)
            {
            case EventType.MouseDown:
                RegisterUndo();
                GUIUtility.hotControl = m_PermanentControlID;
                executing             = true;
                m_TypeBeforeExecution = EditorTools.ToolManager.activeToolType;
                if (IsErasingEvent(evt))
                {
                    if (!TilemapEditorTool.IsActive(typeof(EraseTool)))
                    {
                        TilemapEditorTool.SetActiveEditorTool(typeof(EraseTool));
                    }
                    Erase(new Vector3Int(mouseGridPosition.x, mouseGridPosition.y, zPosition));
                }
                else
                {
                    if (!TilemapEditorTool.IsActive(typeof(PaintTool)))
                    {
                        TilemapEditorTool.SetActiveEditorTool(typeof(PaintTool));
                    }
                    Paint(new Vector3Int(mouseGridPosition.x, mouseGridPosition.y, zPosition));
                }
                Event.current.Use();
                GUI.changed = true;
                break;

            case EventType.MouseDrag:
                executing = true;
                if (isHotControl && mouseGridPositionChanged)
                {
                    List <Vector2Int> points = GridEditorUtility.GetPointsOnLine(m_PreviousMouseGridPosition, mouseGridPosition).ToList();
                    if (points[0] == mouseGridPosition)
                    {
                        points.Reverse();
                    }

                    if (!evt.shift && !TilemapEditorTool.IsActive(typeof(PaintTool)) && m_TypeBeforeExecution == typeof(PaintTool))
                    {
                        TilemapEditorTool.SetActiveEditorTool(typeof(PaintTool));
                    }
                    else if (evt.shift && TilemapEditorTool.IsActive(typeof(PaintTool)))
                    {
                        TilemapEditorTool.SetActiveEditorTool(typeof(EraseTool));
                    }

                    for (int i = 1; i < points.Count; i++)
                    {
                        if (IsErasingEvent(evt))
                        {
                            Erase(new Vector3Int(points[i].x, points[i].y, zPosition));
                        }
                        else
                        {
                            Paint(new Vector3Int(points[i].x, points[i].y, zPosition));
                        }
                    }
                    Event.current.Use();
                    GUI.changed = true;
                }
                break;

            case EventType.MouseUp:
                executing = false;
                if (isHotControl)
                {
                    if (!TilemapEditorTool.IsActive(typeof(PaintTool)) && m_TypeBeforeExecution == typeof(PaintTool))
                    {
                        TilemapEditorTool.SetActiveEditorTool(typeof(PaintTool));
                    }

                    Event.current.Use();
                    GUI.changed           = true;
                    GUIUtility.hotControl = 0;
                }
                break;
            }
        }
Exemplo n.º 4
0
        private void HandleBrushPicking()
        {
            Event evt = Event.current;

            if (evt.type == EventType.MouseDown && IsPickingEvent(evt) && !isHotControl)
            {
                m_TypeBeforeExecution = typeof(PaintTool);
                if (inEditMode && !TilemapEditorTool.IsActive(typeof(PickingTool)))
                {
                    m_TypeBeforeExecution = UnityEditor.EditorTools.ToolManager.activeToolType;
                    TilemapEditorTool.SetActiveEditorTool(typeof(PickingTool));
                }

                m_MarqueeStart            = mouseGridPosition;
                m_MarqueeType             = MarqueeType.Pick;
                s_LastActivePaintableGrid = this;
                Event.current.Use();
                GUI.changed           = true;
                GUIUtility.hotControl = m_PermanentControlID;
                OnBrushPickStarted();
            }
            if (evt.type == EventType.MouseDrag && isHotControl && m_MarqueeStart.HasValue && m_MarqueeType == MarqueeType.Pick && IsPickingEvent(evt))
            {
                RectInt rect = GridEditorUtility.GetMarqueeRect(m_MarqueeStart.Value, mouseGridPosition);
                OnBrushPickDragged(new BoundsInt(new Vector3Int(rect.xMin, rect.yMin, zPosition), new Vector3Int(rect.size.x, rect.size.y, 1)));
                Event.current.Use();
                GUI.changed = true;
            }
            if (evt.rawType == EventType.MouseUp && isHotControl && m_MarqueeStart.HasValue && m_MarqueeType == MarqueeType.Pick && IsPickingEvent(evt))
            {
                // Check if event only occurred in the PaintableGrid window as evt.type will filter for this
                if (evt.type == EventType.MouseUp && m_MarqueeType == MarqueeType.Pick)
                {
                    RectInt    rect  = GridEditorUtility.GetMarqueeRect(m_MarqueeStart.Value, mouseGridPosition);
                    Vector2Int pivot = GetMarqueePivot(m_MarqueeStart.Value, mouseGridPosition);
                    PickBrush(new BoundsInt(new Vector3Int(rect.xMin, rect.yMin, zPosition), new Vector3Int(rect.size.x, rect.size.y, 1)), new Vector3Int(pivot.x, pivot.y, 0));

                    if (inEditMode && UnityEditor.EditorTools.ToolManager.activeToolType != m_TypeBeforeExecution)
                    {
                        if (PickingIsDefaultTool() &&
                            (m_TypeBeforeExecution == typeof(EraseTool) ||
                             m_TypeBeforeExecution == typeof(MoveTool)))
                        {
                            // If Picking is default, change to a Paint Tool to facilitate editing if previous tool does not allow for painting
                            TilemapEditorTool.SetActiveEditorTool(typeof(PaintTool));
                        }
                        else
                        {
                            TilemapEditorTool.SetActiveEditorTool(m_TypeBeforeExecution);
                        }
                    }

                    GridPaletteBrushes.ActiveGridBrushAssetChanged();
                    s_LastActivePaintableGrid = this;
                    Event.current.Use();
                    GUI.changed = true;
                }
                else
                // Event occurred outside of PaintableGrid window, cancel the pick event
                {
                    OnBrushPickCancelled();
                }
                m_MarqueeType         = MarqueeType.None;
                m_MarqueeStart        = null;
                GUIUtility.hotControl = 0;
                InspectorWindow.RepaintAllInspectors();
            }
        }
Exemplo n.º 5
0
        private void HandleBrushPaintAndErase()
        {
            Event evt = Event.current;

            if (!IsPaintingEvent(evt) && !IsErasingEvent(evt))
            {
                return;
            }

            switch (evt.type)
            {
            case EventType.MouseDown:
                if (isNearestControl)
                {
                    RegisterUndo();
                    GUIUtility.hotControl = m_PermanentControlID;
                    executing             = true;
                    m_TypeBeforeExecution = EditorTools.ToolManager.activeToolType;
                    var position = new Vector3Int(mouseGridPosition.x, mouseGridPosition.y, zPosition);
                    if (IsErasingEvent(evt))
                    {
                        if (!TilemapEditorTool.IsActive(typeof(EraseTool)))
                        {
                            TilemapEditorTool.SetActiveEditorTool(typeof(EraseTool));
                        }
                        Erase(position);
                    }
                    else
                    {
                        if (!TilemapEditorTool.IsActive(typeof(PaintTool)))
                        {
                            TilemapEditorTool.SetActiveEditorTool(typeof(PaintTool));
                        }
                        Paint(position);
                    }
                    ResetPreviousMousePositionToCurrentPosition();
                    Event.current.Use();
                    GUI.changed = true;
                }
                break;

            case EventType.MouseDrag:
                executing = true;
                if (isHotControl && mouseGridPositionChanged)
                {
                    var points = GridEditorUtility.GetPointsOnLine(m_PreviousMouseGridPosition, mouseGridPosition);

                    if (!evt.shift && !TilemapEditorTool.IsActive(typeof(PaintTool)) && m_TypeBeforeExecution == typeof(PaintTool))
                    {
                        TilemapEditorTool.SetActiveEditorTool(typeof(PaintTool));
                    }
                    else if (evt.shift && TilemapEditorTool.IsActive(typeof(PaintTool)))
                    {
                        TilemapEditorTool.SetActiveEditorTool(typeof(EraseTool));
                    }

                    foreach (var point in points)
                    {
                        var position = new Vector3Int(point.x, point.y, zPosition);
                        if (IsErasingEvent(evt))
                        {
                            Erase(position);
                        }
                        else
                        {
                            Paint(position);
                        }
                    }
                    Event.current.Use();
                    GUI.changed = true;
                }
                break;

            case EventType.MouseUp:
                executing = false;
                if (isHotControl)
                {
                    if (!TilemapEditorTool.IsActive(typeof(PaintTool)) && m_TypeBeforeExecution == typeof(PaintTool))
                    {
                        TilemapEditorTool.SetActiveEditorTool(typeof(PaintTool));
                    }

                    Event.current.Use();
                    GUI.changed           = true;
                    GUIUtility.hotControl = 0;
                }
                break;
            }
        }