No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RotateTool.cs 4.7KB

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