Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Extending the unity sprite editor with C#

Discussion in '2D' started by Geddem, May 15, 2016.

  1. Geddem

    Geddem

    Joined:
    Jun 26, 2013
    Posts:
    5
    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?
     
  2. Dunkelheit

    Dunkelheit

    Joined:
    Sep 3, 2013
    Posts:
    81
    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:

    Code (csharp):
    1.  
    2. void HandleSprites()
    3. {
    4. //path of your Texture2D image
    5. var path = AssetDatabase.GetAssetPath(map.texture2D);
    6. //get all sprites from this texture
    7. var spriteArray = AssetDatabase.LoadAllAssetsAtPath(path);
    8.  
    9. //get one sprite and it's properties
    10. var sprite = spriteArray[1] as Sprite;
    11. var width = sprite.textureRect.width;
    12. var height = sprite.textureRect.height;
    13. }
    14.  
     
  3. Geddem

    Geddem

    Joined:
    Jun 26, 2013
    Posts:
    5
    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.
     
  4. TiberiuMunteanu

    TiberiuMunteanu

    Joined:
    May 9, 2015
    Posts:
    18
    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 ( <Category>_<Type>_<Name>_<Shape>_<FrameIndex> -> "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.
     
  5. codetive

    codetive

    Joined:
    Apr 8, 2013
    Posts:
    1
    Did you ever found solution to this? I need to extend the sprite editor to set some extra data.
     
  6. LandePlage

    LandePlage

    Joined:
    May 21, 2016
    Posts:
    35
    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.
     
  7. MarekUnity

    MarekUnity

    Unity Technologies

    Joined:
    Jan 6, 2017
    Posts:
    216
    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.
     
    spiney199 likes this.