Search Unity

TexturePacker for 2D

Discussion in '2D' started by Neo-Murakami, May 23, 2015.

  1. Neo-Murakami

    Neo-Murakami

    Joined:
    Apr 14, 2013
    Posts:
    2
    Howdy Guys,

    I've created an atlas through texture packer and have used the texturepacker importer script for Unity. I followed the tutorial at https://www.codeandweb.com/blog/2014/03/28/using-spritesheets-with-unity and it seems the script does its work and recognizes the individual textures in the Unity Editor.

    What I want to do is develop a way that will allow me to say either "SomeGameObject.GetSpriteFromAtlas(name)" or "Material.GetSpriteFromAtlas(name)". The issue I am facing is there doesnt seem to be a way to do this without me writing my own parser(whether its json, xml or any other format), create a 2dTexture from the atlas, THEN creating a sprite from the texture.

    The reason for my desire to create sprites dynamically this way is because if I am pooling game objects, I need a way to reassign a game object's sprite renderer to a different sprite based on a frame number.

    I dont necessarily have a problem with this since I've done something similar in Flash, but with all of the support for Unity and my inexperience with Unity ATM, I feel there should be a way to do this already.

    If there is someone that can help me out or point me in the right direction I'd appreciate it.
     
  2. ColossalPaul

    ColossalPaul

    Unity Technologies

    Joined:
    May 1, 2013
    Posts:
    174
    I'm not sure why this API is necessary. When you import a premade atlas (set to 'multi' in sprite property), or make one using our packing tool, you will already have Sprite assets created for each of the 'sprite' inside the image. You could then use those directly without asking for it from the atlas.

    Is that not what you want?