Search Unity

Tilemap Window Shortcut (Quality of life fix)

Discussion in '2D' started by alpineboarder, Feb 23, 2019.

  1. alpineboarder

    alpineboarder

    Joined:
    Apr 11, 2013
    Posts:
    15
    I was going nuts trying to switch back and forth between tilemap editing and regular gameobject editing. Sadly, there's no shortcut (far as I know of) to toggle this mode on/off. In a perfect world, selecting the tilemap object itself would open this mode, and deselecting it would exit it?

    For now, I whipped up a hacky editor script to save me loads of time navigating to Window -> 2D -> Tile Palette, and then also having to find the tiny close button on the floating window to return to gameobject editing.

    (Sadly, the GridPaintPaletteWindow class is internal, so we can't access the OpenTilemapPalette() function, or use the GetWindow for that type to close it in a single keystroke.)

    Someday soon? :)

    Here's the editor script I'm using:
    Ctrl/Cmd + T to toggle open/focus Tile Palette editor
    Ctrl/Cmd + T again to close it and return to regular editing

    Just toss it into any Editor folder. Hope this helps someone else!

    EDIT: I just realized while tile editing you can switch to another regular tool (move, scale, etc) and it will go back to gameobject editing. Either way it's nice to be able to switch straight to tile editing!

    Code (CSharp):
    1. using UnityEditor;
    2.  
    3. public class OpenTilemapEditor
    4. {
    5.     [MenuItem("Window/2D/Toggle Tilemap Editor %t")]
    6.     static void ToggleTilemapEditor()
    7.     {
    8.         if(EditorWindow.focusedWindow.ToString().CompareTo(" (UnityEditor.GridPaintPaletteWindow)") == 0)
    9.         {
    10.             EditorWindow.focusedWindow.Close();
    11.         }
    12.         else
    13.         {
    14.             EditorApplication.ExecuteMenuItem("Window/2D/Tile Palette");
    15.         }
    16.     }
    17. }
    18.  
     
    Last edited: Feb 23, 2019