2D Toolkit Forum

2D Toolkit => Support => Topic started by: bryanB on September 23, 2013, 07:12:23 am

Title: Adding sprite collection textures at runtime
Post by: bryanB on September 23, 2013, 07:12:23 am
I am currently adding texture during runtime and noticed that I need to play all the animations in order to access the correct collection and set the textures. Is there any other way to do this? I would like to eliminate playing every animation upon setting the correct textures.

Thanks in advance!
Title: Re: Adding sprite collection textures at runtime
Post by: unikronsoftware on September 23, 2013, 11:08:42 am
I don't understand why you'd need to play all animations to set the textures - what exactly are you trying to do here? How are you adding the texture and what does this texture contain?
Title: Re: Adding sprite collection textures at runtime
Post by: bryanB on September 23, 2013, 11:42:38 am
our objective is to optimize our asset bundles. We started by removing the textures of each animation material. basically these textures are the atlases of the animations I play.  To access the different collections per animation I play the animation then add the textures by "animSprite.Collection.materials.mainTexture = texture;".
Title: Re: Adding sprite collection textures at runtime
Post by: unikronsoftware on September 23, 2013, 12:02:37 pm
You can simply iterate through all the clips -

foreach (var clip in animSprite.Library.clips) {
    foreach (var frame in clip.frames) {
          if (frame.spriteCollection.materials[0]....) { // assign if null
          }
    }
}