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; } }
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; } }