설명 없음
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.

FlipTool.cs 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. using UnityEditor.EditorTools;
  2. using UnityEngine;
  3. namespace UnityEditor.Tilemaps
  4. {
  5. /// <summary>
  6. /// Tool for doing a flip action with the Tile Palette
  7. /// </summary>
  8. public abstract class FlipTool : TilemapEditorTool
  9. {
  10. /// <summary>
  11. /// Handles flipping in the given direction when the FlipTool is activated
  12. /// </summary>
  13. /// <param name="axis">Axis to flip by</param>
  14. protected void Flip(GridBrushBase.FlipAxis axis)
  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.Flip(axis, 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.Flip(axis, gridLayout.cellLayout);
  32. }
  33. }
  34. }
  35. /// <summary>
  36. /// Handles GUI for the FlipTool 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 flip X action with the Tile Palette
  46. /// </summary>
  47. public sealed class FlipXTool : FlipTool
  48. {
  49. private static class Styles
  50. {
  51. public static string tooltipStringFormat = L10n.Tr("|Flips the contents of the brush in the X Axis. ({0})");
  52. public static string shortcutId = "Grid Painting/Flip X";
  53. public static GUIContent toolContent = EditorGUIUtility.IconContent("Packages/com.unity.2d.tilemap/Editor/Icons/Grid.FlipX.png", GetTooltipText(tooltipStringFormat, shortcutId));
  54. }
  55. /// <summary>
  56. /// Tooltip String Format for the FlipXTool
  57. /// </summary>
  58. protected override string tooltipStringFormat
  59. {
  60. get { return Styles.tooltipStringFormat; }
  61. }
  62. /// <summary>
  63. /// Shortcut Id for the FlipXTool
  64. /// </summary>
  65. protected override string shortcutId
  66. {
  67. get { return Styles.shortcutId; }
  68. }
  69. /// <summary>
  70. /// Toolbar Icon for the FlipXTool
  71. /// </summary>
  72. public override GUIContent toolbarIcon
  73. {
  74. get { return Styles.toolContent; }
  75. }
  76. /// <summary>
  77. /// Action when FlipXTool is activated
  78. /// </summary>
  79. public override void OnActivated()
  80. {
  81. Flip(GridBrushBase.FlipAxis.X);
  82. }
  83. }
  84. /// <summary>
  85. /// Tool for doing a flip Y action with the Tile Palette
  86. /// </summary>
  87. public sealed class FlipYTool : FlipTool
  88. {
  89. private static class Styles
  90. {
  91. public static string tooltipStringFormat = L10n.Tr("|Flips the contents of the brush in the Y axis. ({0})");
  92. public static string shortcutId = "Grid Painting/Flip Y";
  93. public static GUIContent toolContent = EditorGUIUtility.IconContent("Packages/com.unity.2d.tilemap/Editor/Icons/Grid.FlipY.png", GetTooltipText(tooltipStringFormat, shortcutId));
  94. }
  95. /// <summary>
  96. /// Tooltip String Format for the FlipYTool
  97. /// </summary>
  98. protected override string tooltipStringFormat
  99. {
  100. get { return Styles.tooltipStringFormat; }
  101. }
  102. /// <summary>
  103. /// Shortcut Id for the FlipYTool
  104. /// </summary>
  105. protected override string shortcutId
  106. {
  107. get { return Styles.shortcutId; }
  108. }
  109. /// <summary>
  110. /// Toolbar Icon for the FlipYTool
  111. /// </summary>
  112. public override GUIContent toolbarIcon
  113. {
  114. get { return Styles.toolContent; }
  115. }
  116. /// <summary>
  117. /// Action when FlipYTool is activated
  118. /// </summary>
  119. public override void OnActivated()
  120. {
  121. Flip(GridBrushBase.FlipAxis.Y);
  122. }
  123. }
  124. }