Hello Guest

Author Topic: Adding sprite collection textures at runtime  (Read 3686 times)

bryanB

  • Newbie
  • *
  • Posts: 2
    • View Profile
Adding sprite collection textures at runtime
« 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!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Adding sprite collection textures at runtime
« Reply #1 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?

bryanB

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Adding sprite collection textures at runtime
« Reply #2 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;".

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Adding sprite collection textures at runtime
« Reply #3 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
          }
    }
}