Search Unity

Inspector button to open Sprite Edtior for specific sprite

Discussion in '2D' started by Lo-renzo, Jan 19, 2020.

  1. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,511
    The custom Inspector for the default Tile asset has a button, "Sprite Editor", that opens the Sprite Editor for the specific sprite assigned to that tile. Upon click, it's ready to adjust its rect's borders, rename, move the pivot, etc, which is especially useful when Sprite Mode is Multiple for large spritesheets. I'd like to sprinkle this button on my own custom Inspectors because it can save 30 seconds of Project navigation each click.

    However, I cannot find any public API to replicate this, either to open the SpriteEditor or then navigate to a specific sprite within it. Has anyone done anything similar or would someone from the Unity team care to share how this button could be replicated?

    Capture - Copy.PNG
     
  2. Deleted User

    Deleted User

    Guest

    How is that? Accessing this button needs you to have a sprite selected in the project view, how do you want to do it differently?
     
  3. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    @APSchmidt

    I think he is talking about "Sprite Editor" button in Tile asset, not about similar button in Sprite asset.

    So it is a shortcut, if tile has a sprite asset clicking the button in Tile asset will open sprite editor, without need to click sprite, then select its asset, and then click the "Sprite Editor" button.
     
  4. Deleted User

    Deleted User

    Guest

    Yes it does and it works well. I don't see what the op wants to do. :)
     
  5. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    @APSchmidt
    "I don't see what the op wants to do."

    Because of this:
    "I'd like to sprinkle this button on my own custom Inspectors because it can save 30 seconds of Project navigation each click."

    @THE_MEDICI
    Anyway, quick googling result - at least you can get the window open:
    https://answers.unity.com/questions/1223832/how-can-i-open-the-sprite-editor-from-script.html

    This seems to work from that page:
    Code (CSharp):
    1. Type type = System.Type.GetType("UnityEditor.SpriteEditorWindow,UnityEditor");
    2. EditorWindow.GetWindow(type );
     
  6. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,511
    The default Editor behavior when clicking on a sprite within an Inspector is to navigate to the sprite asset within the Project view. For large spritesheets with many sprites, this folds-out the sprites within the spritesheet, selecting that sprite by name within the Project. However, there's no button to "sprite editor" this sprite in particular, which then requires you to scroll back up (again, large spritesheet) to the parent spritesheet asset, and only then can you click the Sprite Editor button. But the pain isn't over yet because it's then necessary to navigate back to the particular sprite within the SpriteEditor (which may or may not be difficult to find if the sheet is big enough), or scrolling back down the project view to the particular sprite to select it by name so the SpriteEditor pings it. This takes time, I have to do it constantly, and would like to change the default behavior for my Custom Inspectors. The Unity Tilemaps default Tile asset has a button that does exactly what I want: go from a sprite to the Sprite Editor instantaneously and auto-select the correct sprite within the SpriteEditor immediately.

    Now that I think of it, it would be pretty nice if Unity just put that button right here:
    Capture - Copy.PNG That would help out users of large Multiple mode spritesheets.

    Found this before, tried it, and it unfortunately doesn't work (reflection change/broken?), and furthermore wouldn't auto-navigate to the correct sprite. It would be better than nothing if it worked, but the additional touch of selecting the exact sprite within the SpriteEditor would be a significant QoL improvement.
     
    Last edited: Jan 19, 2020
  7. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    @THE_MEDICI

    "Found this before, tried it, and it unfortunately doesn't work (reflection change/broken?)"

    Well you only mentioned it now.

    Besides, the snippet in my reply at least opens the window... At least in 2018.4
     
  8. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,511
    In 2019.2.17 I'm finding that the snippet has a null-ref (the type is null). Other variations of the string ("UnityEditor.SpriteEditorWindow", "SpriteEditorWindow,UnityEditor", ""SpriteEditorWindow")) also null.
     
  9. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
  10. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,511
    If I ask EditorWindow.mouseOverWindow, "UnityEditor.U2D.Sprites.SpriteEditorWindow" is correct for 2019.2, but it only returns null when I try to grab the type itself :/