Search Unity

Copy Paste Sprite geometry and bones in code in editor mode

Discussion in '2D' started by SevenUnearth, Aug 5, 2019.

  1. SevenUnearth

    SevenUnearth

    Joined:
    Jun 26, 2013
    Posts:
    8
    Is it possible to copy sprite datas, meaning the geometry, the bones data and bones weight per vertices to another similar sprite in code? All sprites have the same size.

    The goal is to have different armor pieces on a character and not have to manually copy and paste via the sprite editor(Skinning editor) all the pieces.

    I know that doing this manually works but I want to make an EditorWindow to do this in batches, simply to save time on the long term.

    For the geometry, I tried to use the function OverrideGeometry but it seems like it could only works at runtime which is not what I want.

    For the bones, I don't even know where to start.

    Thank you for your answers.
     
  2. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    I haven't used the new animation tools but I'm sure it's all stored in the meta file for the sprite. You could probably write a script that copies meta data between files.
     
  3. SevenUnearth

    SevenUnearth

    Joined:
    Jun 26, 2013
    Posts:
    8
    Thank you for your reply, by looking at a meta file with notepad++, the informations that I need to copy are under the node spritesheet then under bones, vertices, edges and weight. But those informations are not available in code.
     

    Attached Files:

  4. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    You could write a script that reads the file as a string, and searches for the opening tag of those sections, and copies the data from one file to another. If you're not familiar with file IO and string parsing though, it may be a challenge and require some trial and error.

    If all else fails you could also copy it manually outside of Unity, which would let you copy it all at once and possibly save you some time as opposed to doing it in the sprite editor.
     
  5. SevenUnearth

    SevenUnearth

    Joined:
    Jun 26, 2013
    Posts:
    8
    Good idea, I was thinking about copying from outside unity with a python script or something similar but it would probably be easier to do it with the "read the file as string" way. Thank you kind sir!
     
    LiterallyJeff likes this.