using UnityEditor.EditorTools;
using UnityEngine;
namespace UnityEditor.Tilemaps
{
///
/// Tool for doing a rotate action with the Tile Palette
///
public abstract class RotateTool : TilemapEditorTool
{
///
/// Handles rotation in the given direction when the RotateTool is activated
///
/// Direction to rotate by
protected void Rotate(GridBrushBase.RotationDirection direction)
{
if (GridPaintingState.gridBrush == null)
return;
var grid = GridPaintingState.activeGrid;
if (grid == null)
grid = GridPaintingState.lastActiveGrid;
if (grid != null && grid.isActive)
{
GridPaintingState.gridBrush.Rotate(direction, grid.cellLayout);
grid.Repaint();
}
else if (GridPaintingState.scenePaintTarget != null)
{
var gridLayout = GridPaintingState.scenePaintTarget.GetComponentInParent();
if (gridLayout != null)
{
GridPaintingState.gridBrush.Rotate(direction, gridLayout.cellLayout);
}
}
}
///
/// Handles GUI for the RotateTool when the Tool is active
///
/// EditorWindow from which OnToolGUI is called.
public override void OnToolGUI(EditorWindow window)
{
ToolManager.RestorePreviousTool();
}
}
///
/// Tool for doing a rotate clockwise action with the Tile Palette
///
public sealed class RotateClockwiseTool : RotateTool
{
private static class Styles
{
public static string tooltipStringFormat = L10n.Tr("|Rotates the contents of the brush clockwise. ({0})");
public static string shortcutId = "Grid Painting/Rotate Clockwise";
public static GUIContent toolContent = EditorGUIUtility.IconContent("Packages/com.unity.2d.tilemap/Editor/Icons/Grid.RotateCW.png", GetTooltipText(tooltipStringFormat, shortcutId));
}
///
/// Tooltip String Format for the RotateClockwiseTool
///
protected override string tooltipStringFormat
{
get { return Styles.tooltipStringFormat; }
}
///
/// Shortcut Id for the RotateClockwiseTool
///
protected override string shortcutId
{
get { return Styles.shortcutId; }
}
///
/// Toolbar Icon for the RotateClockwiseTool
///
public override GUIContent toolbarIcon
{
get { return Styles.toolContent; }
}
///
/// Action when RotateClockwiseTool is activated
///
public override void OnActivated()
{
Rotate(GridBrushBase.RotationDirection.Clockwise);
}
}
///
/// Tool for doing a rotate counter clockwise action with the Tile Palette
///
public sealed class RotateCounterClockwiseTool : RotateTool
{
private static class Styles
{
public static string tooltipStringFormat = L10n.Tr("|Rotates the contents of the brush counter clockwise. ({0})");
public static string shortcutId = "Grid Painting/Rotate Anti-Clockwise";
public static GUIContent toolContent = EditorGUIUtility.IconContent("Packages/com.unity.2d.tilemap/Editor/Icons/Grid.RotateACW.png", GetTooltipText(tooltipStringFormat, shortcutId));
}
///
/// Tooltip String Format for the RotateCounterClockwiseTool
///
protected override string tooltipStringFormat
{
get { return Styles.tooltipStringFormat; }
}
///
/// Shortcut Id for the RotateCounterClockwiseTool
///
protected override string shortcutId
{
get { return Styles.shortcutId; }
}
///
/// Toolbar Icon for the RotateCounterClockwiseTool
///
public override GUIContent toolbarIcon
{
get { return Styles.toolContent; }
}
///
/// Action when RotateCounterClockwiseTool is activated
///
public override void OnActivated()
{
Rotate(GridBrushBase.RotationDirection.CounterClockwise);
}
}
}