Search Unity

Generating sprite animations by code

Discussion in '2D' started by MentalFish, Feb 13, 2014.

  1. MentalFish

    MentalFish

    Joined:
    Nov 2, 2005
    Posts:
    282
    The standard way of making sprite animations is to drag out the sprite definitions inside the sprite object and onto the Hierarchy view, in which Unity prompts us on where to store the .anim file. I am wondering if it is possible to automate this process by pre/post processing the sprites in an Editor script? We are talking several hundred sprite sheets with up to 10 different sequences within them.
     
  2. keely

    keely

    Joined:
    Sep 9, 2010
    Posts:
    967
    It is possible. Unfortunately the documentation is quite lacking atm.

    Some info here: http://forum.unity3d.com/threads/212615-Lack-of-scripting-functionality-for-creating-2D-animation-clips-by-code?p=1428914&viewfull=1#post1428914
     
  3. MentalFish

    MentalFish

    Joined:
    Nov 2, 2005
    Posts:
    282
    Thanks for the response. I was just reading and testing that bit of code, but I still have no way of retrieving each sprite "within" the texture. In essence, that solution posted there expects you to still have access to the individual single sprites pr frame: keyFrames.value = spriteForKey(i); where the spriteForKey just returns a reference to an individual sprite.

    It is several hundred sprite sheets, with their text file sprite definitions. So far I have managed to import and automate the creation of the multiple sprite definitions within one sprite sheet (including correctly placed pivots), but I have not found a way to "place them in the scene and create animation files" for them, by code.

    430+ sprite sheets, 7 - 23 sprites within each sheet, some with a straight 1-7 sequence, others with 1-3,4-9,... and so on. Doing it by hand would take a very long time, but I guess a few days full focus could get it done, hoping there are no hick-ups and no need to re-do them all due to an "update" or something else that might come up.

    So automatic-by-code is a no go?