- Home /
Create an asset bundle from Sprite Packer Texture
Hi everybody,
i put some sprite in a folder and tag them by script. After that i call the Packer to rebuild atlases. Thats working fine. Now i want to store the resulting atlas texture in an asset bundle but this is not possible. I can access the Texture2D of the atlas but this not readable so i can't copy it to a new Texture2D to store it. Also it is not possible to create a new asset from the texture because it is already an asset. Also i can't access the TextureImporter of the texture because the asset path is an empty string.
Does anybody know how i can access the texture of the sprite packer and put it in an asset bundle so i am able to reload it from web? Or does anybody know how to open the cache and extract the texture so i can store it in another folder?
Thanks for help
Answer by tmsduman · Jul 07, 2015 at 12:11 PM
If anybody is needing this later: i finally found a working solution. After i imported the sprites and repacked the sprite packer i do the following things: - Create a new Texture2D with the same height and width like the atlas texture you got with Packer.GetTexturesForAtlas(atlasName) - Set all Pixels of the new texture to be transparent - iterate to all imported sprites and get their UVs with SpriteUtility.GetSpriteUVs(sprite, true) and save the position rect of the sprite on the atlas and store it to SpriteMetaData - also make sprite readable and read all pixels of it and set them to the new texture at the previous gotten position - apply new texture and save it with File.WriteAllBytes and EncodeToPNG - refresh assetdatabase - get texture importer of the new texture and mark it as multiple sprite and set the SpriteMetaDatas array to spritesheet - finally set assetbundle name and reimport the asset
Hope this helps you. I anyone needs the code, contact me.
This sounds like quite a heavy workaround. It was said that Unity 5.2 had a fix for this (http://forum.unity3d.com/threads/working-multi-resolution-sprite-sheets.274683/page-2). I'm hoping a patch release with the fix will come a bit earlier, but would you $$anonymous$$d maybe posting your script/code? It sounds like a huge amount of work and would be really helpful for the time till 5.2 :)
Unity's patch release 5.1.2p1 seems to solve this issue!
Though getting a look in your solution would still be pretty great, as some third party plugins are not compatible to Unity's sprite packer, but it would still be awesome to use its functionality and then "exporting" the atlases to common image files, like you did. :)
Hello tmsduman, Would you be so kind to help me with your sample code, If that can help me with accessing the atlas from sprite packer. Thank you in advance.
Your answer
Follow this Question
Related Questions
Sprite in Asset Bundles returned a Texture2D 3 Answers
Managing your sprites in a project question. 0 Answers
Load Unity 4.3 Sprites with AssetBundles 5 Answers
Smooth Synchronized HD Video Playback 0 Answers
AssetBundle.Load() to Texture2D 2 Answers