A game about forced loneliness, made by TACStudios
1using UnityEditor.EditorTools;
2using UnityEngine;
3
4namespace UnityEditor.Tilemaps
5{
6 /// <summary>
7 /// Tool for doing a rotate action with the Tile Palette
8 /// </summary>
9 public abstract class RotateTool : TilemapEditorTool
10 {
11 /// <summary>
12 /// Handles rotation in the given direction when the RotateTool is activated
13 /// </summary>
14 /// <param name="direction">Direction to rotate by</param>
15 protected void Rotate(GridBrushBase.RotationDirection direction)
16 {
17 if (GridPaintingState.gridBrush == null)
18 return;
19
20 var grid = GridPaintingState.activeGrid;
21 if (grid == null)
22 grid = GridPaintingState.lastActiveGrid;
23 if (grid != null && grid.isActive)
24 {
25 GridPaintingState.gridBrush.Rotate(direction, grid.cellLayout);
26 grid.Repaint();
27 }
28 else if (GridPaintingState.scenePaintTarget != null)
29 {
30 var gridLayout = GridPaintingState.scenePaintTarget.GetComponentInParent<GridLayout>();
31 if (gridLayout != null)
32 {
33 GridPaintingState.gridBrush.Rotate(direction, gridLayout.cellLayout);
34 }
35 }
36 }
37
38 /// <summary>
39 /// Handles GUI for the RotateTool when the Tool is active
40 /// </summary>
41 /// <param name="window">EditorWindow from which OnToolGUI is called.</param>
42 public override void OnToolGUI(EditorWindow window)
43 {
44 ToolManager.RestorePreviousTool();
45 }
46 }
47
48 /// <summary>
49 /// Tool for doing a rotate clockwise action with the Tile Palette
50 /// </summary>
51 public sealed class RotateClockwiseTool : RotateTool
52 {
53 private static class Styles
54 {
55 public static string tooltipStringFormat = L10n.Tr("|Rotates the contents of the brush clockwise. ({0})");
56 public static string shortcutId = GridPaintPaletteWindow.ShortcutIds.k_RotateClockwise;
57 public static GUIContent toolContent = EditorGUIUtility.IconContent("Packages/com.unity.2d.tilemap/Editor/Icons/Grid.RotateCW.png", GetTooltipText(tooltipStringFormat, shortcutId));
58 }
59
60 /// <summary>
61 /// Tooltip String Format for the RotateClockwiseTool
62 /// </summary>
63 protected override string tooltipStringFormat
64 {
65 get { return Styles.tooltipStringFormat; }
66 }
67
68 /// <summary>
69 /// Shortcut Id for the RotateClockwiseTool
70 /// </summary>
71 protected override string shortcutId
72 {
73 get { return Styles.shortcutId; }
74 }
75
76 /// <summary>
77 /// Toolbar Icon for the RotateClockwiseTool
78 /// </summary>
79 public override GUIContent toolbarIcon
80 {
81 get { return Styles.toolContent; }
82 }
83
84 /// <summary>
85 /// Action when RotateClockwiseTool is activated
86 /// </summary>
87 public override void OnActivated()
88 {
89 Rotate(GridBrushBase.RotationDirection.Clockwise);
90 }
91 }
92
93 /// <summary>
94 /// Tool for doing a rotate counter clockwise action with the Tile Palette
95 /// </summary>
96 public sealed class RotateCounterClockwiseTool : RotateTool
97 {
98 private static class Styles
99 {
100 public static string tooltipStringFormat = L10n.Tr("|Rotates the contents of the brush counter clockwise. ({0})");
101 public static string shortcutId = GridPaintPaletteWindow.ShortcutIds.k_RotateAntiClockwise;
102 public static GUIContent toolContent = EditorGUIUtility.IconContent("Packages/com.unity.2d.tilemap/Editor/Icons/Grid.RotateACW.png", GetTooltipText(tooltipStringFormat, shortcutId));
103 }
104
105 /// <summary>
106 /// Tooltip String Format for the RotateCounterClockwiseTool
107 /// </summary>
108 protected override string tooltipStringFormat
109 {
110 get { return Styles.tooltipStringFormat; }
111 }
112
113 /// <summary>
114 /// Shortcut Id for the RotateCounterClockwiseTool
115 /// </summary>
116 protected override string shortcutId
117 {
118 get { return Styles.shortcutId; }
119 }
120
121 /// <summary>
122 /// Toolbar Icon for the RotateCounterClockwiseTool
123 /// </summary>
124 public override GUIContent toolbarIcon
125 {
126 get { return Styles.toolContent; }
127 }
128
129 /// <summary>
130 /// Action when RotateCounterClockwiseTool is activated
131 /// </summary>
132 public override void OnActivated()
133 {
134 Rotate(GridBrushBase.RotationDirection.CounterClockwise);
135 }
136 }
137}