123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- using UnityEditor.EditorTools;
- using UnityEngine;
-
- namespace UnityEditor.Tilemaps
- {
- /// <summary>
- /// Tool for doing a flip action with the Tile Palette
- /// </summary>
- public abstract class FlipTool : TilemapEditorTool
- {
- /// <summary>
- /// Handles flipping in the given direction when the FlipTool is activated
- /// </summary>
- /// <param name="axis">Axis to flip by</param>
- 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<GridLayout>();
- if (gridLayout != null)
- {
- GridPaintingState.gridBrush.Flip(axis, gridLayout.cellLayout);
- }
- }
- }
-
- /// <summary>
- /// Handles GUI for the FlipTool when the Tool is active
- /// </summary>
- /// <param name="window">EditorWindow from which OnToolGUI is called.</param>
- public override void OnToolGUI(EditorWindow window)
- {
- ToolManager.RestorePreviousTool();
- }
- }
-
- /// <summary>
- /// Tool for doing a flip X action with the Tile Palette
- /// </summary>
- 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 = GridPaintPaletteWindow.ShortcutIds.k_FlipX;
- public static GUIContent toolContent = EditorGUIUtility.IconContent("Packages/com.unity.2d.tilemap/Editor/Icons/Grid.FlipX.png", GetTooltipText(tooltipStringFormat, shortcutId));
- }
-
- /// <summary>
- /// Tooltip String Format for the FlipXTool
- /// </summary>
- protected override string tooltipStringFormat
- {
- get { return Styles.tooltipStringFormat; }
- }
-
- /// <summary>
- /// Shortcut Id for the FlipXTool
- /// </summary>
- protected override string shortcutId
- {
- get { return Styles.shortcutId; }
- }
-
- /// <summary>
- /// Toolbar Icon for the FlipXTool
- /// </summary>
- public override GUIContent toolbarIcon
- {
- get { return Styles.toolContent; }
- }
-
- /// <summary>
- /// Action when FlipXTool is activated
- /// </summary>
- public override void OnActivated()
- {
- Flip(GridBrushBase.FlipAxis.X);
- }
- }
-
- /// <summary>
- /// Tool for doing a flip Y action with the Tile Palette
- /// </summary>
- 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 = GridPaintPaletteWindow.ShortcutIds.k_FlipY;
- public static GUIContent toolContent = EditorGUIUtility.IconContent("Packages/com.unity.2d.tilemap/Editor/Icons/Grid.FlipY.png", GetTooltipText(tooltipStringFormat, shortcutId));
- }
-
- /// <summary>
- /// Tooltip String Format for the FlipYTool
- /// </summary>
- protected override string tooltipStringFormat
- {
- get { return Styles.tooltipStringFormat; }
- }
-
- /// <summary>
- /// Shortcut Id for the FlipYTool
- /// </summary>
- protected override string shortcutId
- {
- get { return Styles.shortcutId; }
- }
-
- /// <summary>
- /// Toolbar Icon for the FlipYTool
- /// </summary>
- public override GUIContent toolbarIcon
- {
- get { return Styles.toolContent; }
- }
-
- /// <summary>
- /// Action when FlipYTool is activated
- /// </summary>
- public override void OnActivated()
- {
- Flip(GridBrushBase.FlipAxis.Y);
- }
- }
- }
|