Extending the unity sprite editor with C#

On a few occasions, I have wanted to extend the unity sprite editor so I could include in some meta data for each frame. For example, lets say I wanted to attach ‘hotspots’ for a character’s eye position or add a hitbox for where a head is.

I know there are other ways to do this, up to and including creating a totally separate editor – but for what im working on now, it would be much easier if I could just add that functionality right in the sprite editor itself.

I cannot for the life of me find what classes to override or extend. In fact, I cant even find the code for the general box select code for each sprite in the editor API.

Anyone know?

Once you have sliced your spritesheet into small pieces as sprites, you can retrieve those images and work on it as well.

If I got it right, you can handle it like this:

void HandleSprites()
{
//path of your Texture2D image
var path = AssetDatabase.GetAssetPath(map.texture2D);
//get all sprites from this texture
var spriteArray = AssetDatabase.LoadAllAssetsAtPath(path);

//get one sprite and it's properties
var sprite = spriteArray[1] as Sprite;
var width = sprite.textureRect.width;
var height = sprite.textureRect.height;
}

I appreciate your attempt, but I think you missed my question.

I am asking how do you access and extend the sprite editor.

As I stated in my original question, I realize you can, (and I am currently) writing a totally new editor that allows me to load up existing sprites and add meta-data. However im having to re-invent the wheel a bunch here, and I would be ideal if I did not have to.

Hi. Have you found a way of doing it? I also feel the need to augment sprites with custom data. I currently rely on naming conventions ( → “Decal_Bg_Window_W02_0” ) and then parse the name and generate the metadata… but it is kinda ugly. It would be awesome if we could edit some sustom data for each selected sprite in the editor.

Did you ever found solution to this? I need to extend the sprite editor to set some extra data.

I would also be interested in knowing how to do this, or if it’s even possible. It seems like the 2D animation package by Unity does this for their rigging/skinning tools, etc.

You can extend the Sprite Editor functionality by creating your own modules (like SpriteEditor, Custom Outline, or Skinning Editor).
To do this, you must create a class that inherits from SpriteEditorModuleBase.

1 Like