using UnityEditor.EditorTools;
using UnityEngine;
namespace UnityEditor.Tilemaps
{
///
/// Tool for doing a flip action with the Tile Palette
///
public abstract class FlipTool : TilemapEditorTool
{
///
/// Handles flipping in the given direction when the FlipTool is activated
///
/// Axis to flip by
protected void Flip(GridBrushBase.FlipAxis axis)
{
if (GridPaintingState.gridBrush == null)
return;
var grid = GridPaintingState.activeGrid;
if (grid == null)
grid = GridPaintingState.lastActiveGrid;
if (grid != null && grid.isActive)
{
GridPaintingState.gridBrush.Flip(axis, grid.cellLayout);
grid.Repaint();
}
else if (GridPaintingState.scenePaintTarget != null)
{
var gridLayout = GridPaintingState.scenePaintTarget.GetComponentInParent();
if (gridLayout != null)
{
GridPaintingState.gridBrush.Flip(axis, gridLayout.cellLayout);
}
}
}
///
/// Handles GUI for the FlipTool when the Tool is active
///
/// EditorWindow from which OnToolGUI is called.
public override void OnToolGUI(EditorWindow window)
{
ToolManager.RestorePreviousTool();
}
}
///
/// Tool for doing a flip X action with the Tile Palette
///
public sealed class FlipXTool : FlipTool
{
private static class Styles
{
public static string tooltipStringFormat = L10n.Tr("|Flips the contents of the brush in the X Axis. ({0})");
public static string shortcutId = "Grid Painting/Flip X";
public static GUIContent toolContent = EditorGUIUtility.IconContent("Packages/com.unity.2d.tilemap/Editor/Icons/Grid.FlipX.png", GetTooltipText(tooltipStringFormat, shortcutId));
}
///
/// Tooltip String Format for the FlipXTool
///
protected override string tooltipStringFormat
{
get { return Styles.tooltipStringFormat; }
}
///
/// Shortcut Id for the FlipXTool
///
protected override string shortcutId
{
get { return Styles.shortcutId; }
}
///
/// Toolbar Icon for the FlipXTool
///
public override GUIContent toolbarIcon
{
get { return Styles.toolContent; }
}
///
/// Action when FlipXTool is activated
///
public override void OnActivated()
{
Flip(GridBrushBase.FlipAxis.X);
}
}
///
/// Tool for doing a flip Y action with the Tile Palette
///
public sealed class FlipYTool : FlipTool
{
private static class Styles
{
public static string tooltipStringFormat = L10n.Tr("|Flips the contents of the brush in the Y axis. ({0})");
public static string shortcutId = "Grid Painting/Flip Y";
public static GUIContent toolContent = EditorGUIUtility.IconContent("Packages/com.unity.2d.tilemap/Editor/Icons/Grid.FlipY.png", GetTooltipText(tooltipStringFormat, shortcutId));
}
///
/// Tooltip String Format for the FlipYTool
///
protected override string tooltipStringFormat
{
get { return Styles.tooltipStringFormat; }
}
///
/// Shortcut Id for the FlipYTool
///
protected override string shortcutId
{
get { return Styles.shortcutId; }
}
///
/// Toolbar Icon for the FlipYTool
///
public override GUIContent toolbarIcon
{
get { return Styles.toolContent; }
}
///
/// Action when FlipYTool is activated
///
public override void OnActivated()
{
Flip(GridBrushBase.FlipAxis.Y);
}
}
}