How can I open the Sprite Editor from script?

I wanted to make a tool that groups several related functions for our game together, to make things more accessible for artists, and one of these is editing the slicing of a sprite.

Normally you can open windows which appear in the menus from script, but the Sprite Editor is only available from a button in the inspector after you select a sprite or spritesheet asset.

Given a particular sprite or spritesheet asset, how can I make a button in an Editor script which opens the sprite editor window for that sprite?

Hi @DinostabOMG! Unfortunately there is no public API for doing this. If you don’t mind using reflection and being subject to a little volatility, you can do something like this:

using System.Linq;
using UnityEditor;
using UnityEngine;

void OnOpenSpriteEditor(Sprite sprite)
{
    Selection.activeObject = sprite;
    EditorWindow.GetWindow(typeof(EditorWindow).Assembly.GetTypes().Where(t => t.Name == "SpriteEditorWindow").FirstOrDefault());
}