A game about forced loneliness, made by TACStudios
1using System; 2using UnityEditor.EditorTools; 3using UnityEngine; 4using UnityEngine.UIElements; 5 6namespace UnityEditor.Tilemaps 7{ 8 internal abstract class PaintableGrid : ScriptableObject 9 { 10 private const int k_MaxMouseCellDelta = 500; 11 12 public enum MarqueeType { None = 0, Pick, Box, Select } 13 protected int m_PermanentControlID; 14 15 public abstract void Repaint(); 16 protected abstract void RegisterUndo(); 17 protected abstract void Paint(Vector3Int position); 18 protected abstract void Erase(Vector3Int position); 19 protected abstract void BoxFill(BoundsInt position); 20 protected abstract void BoxErase(BoundsInt position); 21 protected abstract void FloodFill(Vector3Int position); 22 protected abstract void PickBrush(BoundsInt position, Vector3Int pickStart); 23 protected abstract void Select(BoundsInt position); 24 protected abstract void Move(BoundsInt from, BoundsInt to); 25 protected abstract void MoveStart(BoundsInt position); 26 protected abstract void MoveEnd(BoundsInt position); 27 28 protected abstract bool CustomTool(bool isToolHotControl, TilemapEditorTool tool, Vector3Int position); 29 30 protected abstract bool ValidateFloodFillPosition(Vector3Int position); 31 protected abstract Vector2Int ScreenToGrid(Vector2 screenPosition, float zPosition = 0.0f); 32 protected abstract bool PickingIsDefaultTool(); 33 protected abstract bool CanPickOutsideEditMode(); 34 protected abstract GridLayout.CellLayout CellLayout(); 35 protected abstract void ClearGridSelection(); 36 37 public abstract bool isActive { get; } 38 39 protected virtual void OnBrushPickStarted() {} 40 protected virtual void OnBrushPickDragged(BoundsInt position) {} 41 42 protected virtual void OnBrushPickCancelled() {} 43 44 protected virtual void OnEditStart() {} 45 protected virtual void OnEditEnd() {} 46 47 // UIToolkit does not set type to Ignore if mouse position is not in window 48 private bool IsMouseUpInWindow() { return Event.current.type == EventType.MouseUp; } 49 50 public abstract Rect rectPosition { get; } 51 52 public abstract VisualElement windowRoot { get; } 53 54 internal static PaintableGrid s_LastActivePaintableGrid; 55 56 private Vector2 m_MousePosition; 57 protected Vector2Int m_PreviousMouseGridPosition; 58 protected Vector2Int m_MouseGridPosition; 59 protected bool m_MouseGridPositionChanged; 60 private bool m_PositionChangeRepaintDone; 61 protected Vector2Int? m_PreviousMove; 62 protected Vector2Int? m_MarqueeStart; 63 protected MarqueeType m_MarqueeType = MarqueeType.None; 64 private bool m_IsExecuting; 65 protected Type m_TypeBeforeExecution; 66 private int m_ZPosition; 67 68 public Vector2 mousePosition { get { return m_MousePosition; } } 69 public Vector2Int mouseGridPosition { get { return m_MouseGridPosition; } } 70 public bool isPicking { get { return m_MarqueeType == MarqueeType.Pick; } } 71 public bool isBoxing { get { return m_MarqueeType == MarqueeType.Box; } } 72 public GridLayout.CellLayout cellLayout { get { return CellLayout(); } } 73 public int zPosition { get { return m_ZPosition; } set { m_ZPosition = value; } } 74 75 protected bool executing 76 { 77 get { return m_IsExecuting; } 78 set 79 { 80 var isExecuting = value && isHotControl; 81 if (isExecuting != m_IsExecuting) 82 { 83 if (isExecuting) 84 OnEditStart(); 85 else 86 OnEditEnd(); 87 } 88 m_IsExecuting = isExecuting; 89 } 90 } 91 92 protected bool isNearestControl { get { return HandleUtility.nearestControl == m_PermanentControlID; } } 93 protected bool isHotControl { get { return GUIUtility.hotControl == m_PermanentControlID; } } 94 protected bool mouseGridPositionChanged { get { return m_MouseGridPositionChanged; } } 95 protected bool inEditMode { get { return InGridEditMode(); } } 96 97 protected virtual void OnEnable() 98 { 99 m_PermanentControlID = GUIUtility.GetPermanentControlID(); 100 } 101 102 protected virtual void OnDisable() 103 { 104 } 105 106 public virtual void OnGUI() 107 { 108 var evt = Event.current; 109 110 if (CanPickOutsideEditMode() || inEditMode) 111 { 112 if (evt.type == EventType.Layout) 113 HandleUtility.AddDefaultControl(m_PermanentControlID); 114 115 HandleBrushPicking(); 116 } 117 118 if (inEditMode) 119 { 120 HandleBrushPaintAndErase(); 121 HandleSelectTool(); 122 HandleMoveTool(); 123 HandleEditModeChange(); 124 HandleFloodFill(); 125 HandleBoxTool(); 126 HandleCustomTool(); 127 } 128 else if (isHotControl && !IsPickingEvent(evt)) 129 { 130 // Release hot control if it still has it while not in picking or grid edit mode 131 GUIUtility.hotControl = 0; 132 } 133 134 if (mouseGridPositionChanged && !m_PositionChangeRepaintDone) 135 { 136 Repaint(); 137 m_PositionChangeRepaintDone = true; 138 } 139 } 140 141 protected void ResetPreviousMousePositionToCurrentPosition() 142 { 143 m_PreviousMouseGridPosition = m_MouseGridPosition; 144 } 145 146 protected void UpdateMouseGridPositionUIToolkit(Vector2 localMousePosition, bool isPointerMove = false) 147 { 148 m_MousePosition = localMousePosition; 149 150 var newGridPosition = ScreenToGrid(m_MousePosition, m_ZPosition); 151 if (newGridPosition != m_MouseGridPosition) 152 { 153 var delta = newGridPosition - m_MouseGridPosition; 154 // Case 1024422: Limit mouse cell delta changes for Grid/Tilemap input handling due to camera changes when switching modes/axis views 155 if (Mathf.Abs(delta.x) > k_MaxMouseCellDelta) 156 newGridPosition.x = m_MouseGridPosition.x + Math.Sign(delta.x) * k_MaxMouseCellDelta; 157 if (Mathf.Abs(delta.y) > k_MaxMouseCellDelta) 158 newGridPosition.y = m_MouseGridPosition.y + Math.Sign(delta.y) * k_MaxMouseCellDelta; 159 ResetPreviousMousePositionToCurrentPosition(); 160 m_MouseGridPosition = newGridPosition; 161 MouseGridPositionChanged(); 162 Repaint(); 163 } 164 else if (isPointerMove) 165 { 166 m_MouseGridPositionChanged = false; 167 } 168 } 169 170 protected void UpdateMouseGridPosition(bool forceUpdate = false) 171 { 172 if (Event.current.type == EventType.MouseDrag 173 || Event.current.type == EventType.MouseMove 174 // Case 1075857: Mouse Down when window is not in focus needs to update mouse grid position 175 || Event.current.type == EventType.MouseDown 176 || Event.current.type == EventType.DragUpdated 177 || forceUpdate) 178 { 179 m_MousePosition = Event.current.mousePosition; 180 var newGridPosition = ScreenToGrid(m_MousePosition, m_ZPosition); 181 if (newGridPosition != m_MouseGridPosition) 182 { 183 var delta = newGridPosition - m_MouseGridPosition; 184 // Case 1024422: Limit mouse cell delta changes for Grid/Tilemap input handling due to camera changes when switching modes/axis views 185 if (Mathf.Abs(delta.x) > k_MaxMouseCellDelta) 186 newGridPosition.x = m_MouseGridPosition.x + Math.Sign(delta.x) * k_MaxMouseCellDelta; 187 if (Mathf.Abs(delta.y) > k_MaxMouseCellDelta) 188 newGridPosition.y = m_MouseGridPosition.y + Math.Sign(delta.y) * k_MaxMouseCellDelta; 189 ResetPreviousMousePositionToCurrentPosition(); 190 m_MouseGridPosition = newGridPosition; 191 MouseGridPositionChanged(); 192 } 193 else if (!forceUpdate || Event.current.type == EventType.MouseMove) 194 { 195 m_MouseGridPositionChanged = false; 196 } 197 } 198 } 199 200 private void MouseGridPositionChanged() 201 { 202 m_MouseGridPositionChanged = true; 203 m_PositionChangeRepaintDone = false; 204 } 205 206 private void HandleEditModeChange() 207 { 208 // Handles changes in EditMode while tool is expected to be in the same mode 209 if (isPicking && !TilemapEditorTool.IsActive(typeof(PickingTool))) 210 { 211 m_MarqueeStart = null; 212 m_MarqueeType = MarqueeType.None; 213 if (isHotControl) 214 { 215 GUI.changed = true; 216 GUIUtility.hotControl = 0; 217 } 218 } 219 if (isBoxing && !TilemapEditorTool.IsActive(typeof(BoxTool))) 220 { 221 m_MarqueeStart = null; 222 m_MarqueeType = MarqueeType.None; 223 if (isHotControl) 224 { 225 GUI.changed = true; 226 GUIUtility.hotControl = 0; 227 } 228 } 229 if (!TilemapEditorTool.IsActive(typeof(SelectTool)) 230 && !TilemapEditorTool.IsActive(typeof(MoveTool)) 231 && !GridSelectionTool.IsActive()) 232 { 233 ClearGridSelection(); 234 } 235 } 236 237 private void HandleBrushPicking() 238 { 239 Event evt = Event.current; 240 241 if (isNearestControl && evt.type == EventType.MouseDown && IsPickingEvent(evt) && !isHotControl) 242 { 243 m_TypeBeforeExecution = typeof(PaintTool); 244 if (inEditMode && !TilemapEditorTool.IsActive(typeof(PickingTool))) 245 { 246 m_TypeBeforeExecution = ToolManager.activeToolType; 247 TilemapEditorTool.SetActiveEditorTool(typeof(PickingTool)); 248 } 249 250 m_MarqueeStart = mouseGridPosition; 251 m_MarqueeType = MarqueeType.Pick; 252 Event.current.Use(); 253 GUI.changed = true; 254 GUIUtility.hotControl = m_PermanentControlID; 255 OnBrushPickStarted(); 256 } 257 if (evt.type == EventType.MouseDrag && isHotControl && m_MarqueeStart.HasValue && m_MarqueeType == MarqueeType.Pick && IsPickingEvent(evt)) 258 { 259 RectInt rect = GridEditorUtility.GetMarqueeRect(m_MarqueeStart.Value, mouseGridPosition); 260 OnBrushPickDragged(new BoundsInt(new Vector3Int(rect.xMin, rect.yMin, zPosition), new Vector3Int(rect.size.x, rect.size.y, 1))); 261 Event.current.Use(); 262 GUI.changed = true; 263 } 264 if (evt.rawType == EventType.MouseUp && isHotControl && m_MarqueeStart.HasValue && m_MarqueeType == MarqueeType.Pick && IsPickingEvent(evt)) 265 { 266 // Check if event only occurred in the PaintableGrid window as evt.type will filter for this 267 if (IsMouseUpInWindow() && m_MarqueeType == MarqueeType.Pick) 268 { 269 RectInt rect = GridEditorUtility.GetMarqueeRect(m_MarqueeStart.Value, mouseGridPosition); 270 Vector2Int pivot = GetMarqueePivot(m_MarqueeStart.Value, mouseGridPosition); 271 PickBrush(new BoundsInt(new Vector3Int(rect.xMin, rect.yMin, zPosition), new Vector3Int(rect.size.x, rect.size.y, 1)), new Vector3Int(pivot.x, pivot.y, 0)); 272 273 if (inEditMode && ToolManager.activeToolType != m_TypeBeforeExecution) 274 { 275 if (PickingIsDefaultTool() 276 && (m_TypeBeforeExecution == typeof(EraseTool) 277 || m_TypeBeforeExecution == typeof(MoveTool))) 278 { 279 // If Picking is default, change to a Paint Tool to facilitate editing if previous tool does not allow for painting 280 TilemapEditorTool.SetActiveEditorTool(typeof(PaintTool)); 281 } 282 else 283 { 284 TilemapEditorTool.SetActiveEditorTool(m_TypeBeforeExecution); 285 } 286 } 287 288 GridPaintingState.ActiveGridBrushAssetChanged(); 289 Event.current.Use(); 290 GUI.changed = true; 291 } 292 else 293 // Event occurred outside of PaintableGrid window, cancel the pick event 294 { 295 OnBrushPickCancelled(); 296 } 297 m_MarqueeType = MarqueeType.None; 298 m_MarqueeStart = null; 299 GUIUtility.hotControl = 0; 300 InspectorWindow.RepaintAllInspectors(); 301 } 302 } 303 304 private bool IsPickingEvent(Event evt) 305 { 306 return ((evt.control && !TilemapEditorTool.IsActive(typeof(MoveTool))) 307 || TilemapEditorTool.IsActive(typeof(PickingTool)) 308 || !TilemapEditorTool.IsActive(typeof(SelectTool)) && PickingIsDefaultTool()) 309 && evt.button == 0 && !evt.alt; 310 } 311 312 private void HandleSelectTool() 313 { 314 Event evt = Event.current; 315 316 if (isNearestControl && evt.type == EventType.MouseDown && evt.button == 0 && !evt.alt && (TilemapEditorTool.IsActive(typeof(SelectTool)) || (TilemapEditorTool.IsActive(typeof(MoveTool)) && evt.control))) 317 { 318 if (TilemapEditorTool.IsActive(typeof(MoveTool)) && evt.control) 319 TilemapEditorTool.SetActiveEditorTool(typeof(SelectTool)); 320 321 m_PreviousMove = null; 322 m_MarqueeStart = mouseGridPosition; 323 m_MarqueeType = MarqueeType.Select; 324 325 GUIUtility.hotControl = m_PermanentControlID; 326 Event.current.Use(); 327 } 328 if (evt.rawType == EventType.MouseUp && evt.button == 0 && !evt.alt && m_MarqueeStart.HasValue && isHotControl && TilemapEditorTool.IsActive(typeof(SelectTool))) 329 { 330 // Check if event only occurred in the PaintableGrid window as evt.type will filter for this 331 if (IsMouseUpInWindow() && m_MarqueeType == MarqueeType.Select) 332 { 333 RectInt rect = GridEditorUtility.GetMarqueeRect(m_MarqueeStart.Value, mouseGridPosition); 334 Select(new BoundsInt(new Vector3Int(rect.xMin, rect.yMin, zPosition), new Vector3Int(rect.size.x, rect.size.y, 1))); 335 Event.current.Use(); 336 } 337 if (evt.control) 338 TilemapEditorTool.SetActiveEditorTool(typeof(MoveTool)); 339 m_MarqueeStart = null; 340 m_MarqueeType = MarqueeType.None; 341 InspectorWindow.RepaintAllInspectors(); 342 GUIUtility.hotControl = 0; 343 } 344 if (evt.type == EventType.KeyDown && evt.keyCode == KeyCode.Escape && !m_MarqueeStart.HasValue && !m_PreviousMove.HasValue) 345 { 346 ClearGridSelection(); 347 Event.current.Use(); 348 } 349 } 350 351 private void HandleMoveTool() 352 { 353 Event evt = Event.current; 354 355 if (isNearestControl && evt.type == EventType.MouseDown && evt.button == 0 && !evt.alt && TilemapEditorTool.IsActive(typeof(MoveTool))) 356 { 357 RegisterUndo(); 358 Vector3Int mouse3D = new Vector3Int(mouseGridPosition.x, mouseGridPosition.y, GridSelection.position.zMin); 359 if (GridSelection.active && GridSelection.position.Contains(mouse3D)) 360 { 361 GUIUtility.hotControl = m_PermanentControlID; 362 executing = true; 363 m_MarqueeStart = null; 364 m_MarqueeType = MarqueeType.None; 365 m_PreviousMove = mouseGridPosition; 366 MoveStart(GridSelection.position); 367 } 368 Event.current.Use(); 369 } 370 if (evt.type == EventType.MouseDrag && evt.button == 0 && TilemapEditorTool.IsActive(typeof(MoveTool)) && isHotControl) 371 { 372 if (m_MouseGridPositionChanged && m_PreviousMove.HasValue) 373 { 374 executing = true; 375 BoundsInt previousRect = GridSelection.position; 376 BoundsInt previousBounds = new BoundsInt(new Vector3Int(previousRect.xMin, previousRect.yMin, GridSelection.position.zMin), new Vector3Int(previousRect.size.x, previousRect.size.y, 1)); 377 378 Vector2Int direction = mouseGridPosition - m_PreviousMove.Value; 379 BoundsInt pos = GridSelection.position; 380 pos.position = new Vector3Int(pos.x + direction.x, pos.y + direction.y, pos.z); 381 GridSelection.position = pos; 382 Move(previousBounds, pos); 383 m_PreviousMove = mouseGridPosition; 384 Event.current.Use(); 385 } 386 } 387 if (IsMouseUpInWindow() && evt.button == 0 && m_PreviousMove.HasValue && TilemapEditorTool.IsActive(typeof(MoveTool)) && isHotControl) 388 { 389 m_PreviousMove = null; 390 MoveEnd(GridSelection.position); 391 executing = false; 392 GUIUtility.hotControl = 0; 393 Event.current.Use(); 394 } 395 } 396 397 private void HandleBrushPaintAndErase() 398 { 399 Event evt = Event.current; 400 if (!IsPaintingEvent(evt) && !IsErasingEvent(evt)) 401 return; 402 403 switch (evt.type) 404 { 405 case EventType.MouseDown: 406 if (isNearestControl) 407 { 408 RegisterUndo(); 409 GUIUtility.hotControl = m_PermanentControlID; 410 executing = true; 411 if (ToolManager.activeToolType != null && ToolManager.activeToolType.IsSubclassOf(typeof(TilemapEditorTool))) 412 m_TypeBeforeExecution = ToolManager.activeToolType; 413 var position = new Vector3Int(mouseGridPosition.x, mouseGridPosition.y, zPosition); 414 if (IsErasingEvent(evt)) 415 { 416 if (!TilemapEditorTool.IsActive(typeof(EraseTool))) 417 TilemapEditorTool.SetActiveEditorTool(typeof(EraseTool)); 418 Erase(position); 419 } 420 else 421 { 422 if (!TilemapEditorTool.IsActive(typeof(PaintTool))) 423 TilemapEditorTool.SetActiveEditorTool(typeof(PaintTool)); 424 Paint(position); 425 } 426 ResetPreviousMousePositionToCurrentPosition(); 427 Event.current.Use(); 428 GUI.changed = true; 429 } 430 break; 431 case EventType.MouseDrag: 432 executing = true; 433 if (isHotControl && mouseGridPositionChanged) 434 { 435 var points = GridEditorUtility.GetPointsOnLine(m_PreviousMouseGridPosition, mouseGridPosition); 436 437 if (!evt.shift && !TilemapEditorTool.IsActive(typeof(PaintTool)) && m_TypeBeforeExecution == typeof(PaintTool)) 438 TilemapEditorTool.SetActiveEditorTool(typeof(PaintTool)); 439 else if (evt.shift && TilemapEditorTool.IsActive(typeof(PaintTool))) 440 TilemapEditorTool.SetActiveEditorTool(typeof(EraseTool)); 441 442 foreach (var point in points) 443 { 444 var position = new Vector3Int(point.x, point.y, zPosition); 445 if (IsErasingEvent(evt)) 446 Erase(position); 447 else 448 Paint(position); 449 } 450 ResetPreviousMousePositionToCurrentPosition(); 451 Event.current.Use(); 452 GUI.changed = true; 453 } 454 break; 455 case EventType.MouseUp: 456 executing = false; 457 if (isHotControl) 458 { 459 if (!TilemapEditorTool.IsActive(typeof(PaintTool)) && m_TypeBeforeExecution == typeof(PaintTool)) 460 { 461 TilemapEditorTool.SetActiveEditorTool(typeof(PaintTool)); 462 } 463 464 Event.current.Use(); 465 GUI.changed = true; 466 GUIUtility.hotControl = 0; 467 } 468 break; 469 } 470 } 471 472 private bool IsPaintingEvent(Event evt) 473 { 474 return (evt.button == 0 && !evt.control && !evt.alt && TilemapEditorTool.IsActive(typeof(PaintTool))); 475 } 476 477 private bool IsErasingEvent(Event evt) 478 { 479 return (evt.button == 0 && !evt.control && !evt.alt 480 && ((evt.shift && !TilemapEditorTool.IsActive(typeof(BoxTool)) 481 && !TilemapEditorTool.IsActive(typeof(FillTool)) 482 && !TilemapEditorTool.IsActive(typeof(SelectTool)) 483 && !TilemapEditorTool.IsActive(typeof(MoveTool))) 484 || TilemapEditorTool.IsActive(typeof(EraseTool)))); 485 } 486 487 private void HandleFloodFill() 488 { 489 if (TilemapEditorTool.IsActive(typeof(FillTool)) && GridPaintingState.gridBrush != null && ValidateFloodFillPosition(new Vector3Int(mouseGridPosition.x, mouseGridPosition.y, 0))) 490 { 491 Event evt = Event.current; 492 if (isNearestControl && evt.type == EventType.MouseDown && evt.button == 0 && !evt.alt) 493 { 494 GUIUtility.hotControl = m_PermanentControlID; 495 GUI.changed = true; 496 executing = true; 497 Event.current.Use(); 498 } 499 if (IsMouseUpInWindow() && evt.button == 0 && isHotControl) 500 { 501 RegisterUndo(); 502 FloodFill(new Vector3Int(mouseGridPosition.x, mouseGridPosition.y, zPosition)); 503 executing = false; 504 GUI.changed = true; 505 Event.current.Use(); 506 GUIUtility.hotControl = 0; 507 } 508 } 509 } 510 511 private void HandleBoxTool() 512 { 513 Event evt = Event.current; 514 515 if (isNearestControl && evt.type == EventType.MouseDown && evt.button == 0 && !evt.alt && TilemapEditorTool.IsActive(typeof(BoxTool))) 516 { 517 m_MarqueeStart = mouseGridPosition; 518 m_MarqueeType = MarqueeType.Box; 519 Event.current.Use(); 520 GUI.changed = true; 521 executing = true; 522 GUIUtility.hotControl = m_PermanentControlID; 523 } 524 if (evt.type == EventType.MouseDrag && evt.button == 0 && TilemapEditorTool.IsActive(typeof(BoxTool))) 525 { 526 if (isHotControl && m_MarqueeStart.HasValue) 527 { 528 Event.current.Use(); 529 executing = true; 530 GUI.changed = true; 531 } 532 } 533 if (IsMouseUpInWindow() && evt.button == 0 && TilemapEditorTool.IsActive(typeof(BoxTool))) 534 { 535 if (isHotControl && m_MarqueeStart.HasValue) 536 { 537 RegisterUndo(); 538 RectInt rect = GridEditorUtility.GetMarqueeRect(m_MarqueeStart.Value, mouseGridPosition); 539 if (evt.shift) 540 BoxErase(new BoundsInt(rect.x, rect.y, zPosition, rect.size.x, rect.size.y, 1)); 541 else 542 BoxFill(new BoundsInt(rect.x, rect.y, zPosition, rect.size.x, rect.size.y, 1)); 543 Event.current.Use(); 544 executing = false; 545 GUI.changed = true; 546 GUIUtility.hotControl = 0; 547 } 548 m_MarqueeStart = null; 549 m_MarqueeType = MarqueeType.None; 550 } 551 } 552 553 private void HandleCustomTool() 554 { 555 Event evt = Event.current; 556 if (evt.type == EventType.Layout || evt.type == EventType.Repaint) 557 return; 558 559 if (!TilemapEditorTool.IsCustomTilemapEditorToolActive()) 560 return; 561 562 TilemapEditorTool activeTool = EditorToolManager.activeTool as TilemapEditorTool; 563 var executed = CustomTool(isHotControl, activeTool, new Vector3Int(mouseGridPosition.x, mouseGridPosition.y, zPosition)); 564 if (executed != executing) 565 { 566 GUIUtility.hotControl = executed ? m_PermanentControlID : 0; 567 executing = executed; 568 GUI.changed = true; 569 Event.current.Use(); 570 } 571 else if (executing) 572 { 573 GUI.changed = true; 574 Event.current.Use(); 575 } 576 } 577 578 protected Vector2Int GetMarqueePivot(Vector2Int start, Vector2Int end) 579 { 580 var pivot = new Vector2Int( 581 Math.Max(end.x - start.x, 0), 582 Math.Max(end.y - start.y, 0) 583 ); 584 return pivot; 585 } 586 587 public void ChangeZPosition(int change) 588 { 589 m_ZPosition += change; 590 MouseGridPositionChanged(); 591 Repaint(); 592 } 593 594 public void ResetZPosition() 595 { 596 if (m_ZPosition == 0) 597 return; 598 599 m_ZPosition = 0; 600 MouseGridPositionChanged(); 601 Repaint(); 602 } 603 604 public static bool InGridEditMode() 605 { 606 return ToolManager.activeToolType != null 607 && (ToolManager.activeToolType.IsSubclassOf(typeof(TilemapEditorTool))); 608 } 609 610 // TODO: Someday EditMode or its future incarnation will be public and we can get rid of this 611 // TODO: Temporarily use ActiveTool's type to determine brush tool 612 public static GridBrushBase.Tool EditTypeToBrushTool(Type activeToolType) 613 { 614 if (activeToolType == typeof(BoxTool)) 615 return GridBrushBase.Tool.Box; 616 if (activeToolType == typeof(EraseTool)) 617 return GridBrushBase.Tool.Erase; 618 if (activeToolType == typeof(FillTool)) 619 return GridBrushBase.Tool.FloodFill; 620 if (activeToolType == typeof(PaintTool)) 621 return GridBrushBase.Tool.Paint; 622 if (activeToolType == typeof(PickingTool)) 623 return GridBrushBase.Tool.Pick; 624 if (activeToolType == typeof(SelectTool)) 625 return GridBrushBase.Tool.Select; 626 if (activeToolType == typeof(MoveTool)) 627 return GridBrushBase.Tool.Move; 628 return GridBrushBase.Tool.Other; 629 } 630 } 631}