Author Topic: Assign Atlas by name  (Read 9373 times)

Codewalker

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 21
    • View Profile
Assign Atlas by name
« on: June 28, 2012, 11:51:30 AM »
I have a UISprite and want to assign an atlas by using the name (i.e. a string). Does NGUI has a useful function for this? (I could not find one in the documentation)

JRoch

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 140
    • View Profile
Re: Assign Atlas by name
« Reply #1 on: June 28, 2012, 06:14:17 PM »
Not sure the question you're asking is meaningful.  Are you saying that you have programatically created a UISprite at runtime and are trying to shove it into an atlas at runtime?  That's not how atlases work...

Codewalker

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 21
    • View Profile
Re: Assign Atlas by name
« Reply #2 on: June 29, 2012, 03:22:28 AM »
No, I have a UISprite (regurlarly designed and placed in the Unity Editor) that should get a (not randomly chosen but) different texture. However, these textures may be part of several atlasses. So I have not only to change the sprite name (a string that I set via script), but also the atlas. And it seems, I can't set an atlas just by it's name. Hope, this makes it clearer.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Assign Atlas by name
« Reply #3 on: June 29, 2012, 03:24:15 AM »
That's because the atlas is a reference. You need to choose it from some list you keep locally, or place it in the Resources folder and Resources.Load it.

iossif

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: Assign Atlas by name
« Reply #4 on: September 18, 2012, 09:58:39 AM »
but how can i assign the atlas to the sprite? i have the same problem with a UILabel and i do not see a way to do something like uilable.atlas = myatlas.
i have everything ready to load from ressources but i do not see the command to assign it in code.

here is what i do:

Label = new GameObject();
Label.AddComponent<UILabel>();
Label.GetComponent<UILabel>().text = text;

when i start the project i see a gameobejct with an uilabel attached but it has no atlas => it does not show the text
« Last Edit: September 18, 2012, 10:11:44 AM by iossif »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Assign Atlas by name
« Reply #5 on: September 18, 2012, 10:16:05 AM »
UILabel.font.atlas -- for labels the atlas is on the font, not on the label. Sprites have the atlas on UISprite.atlas. Since you're using a label, you need to specify its font before you use it.

iossif

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: Assign Atlas by name
« Reply #6 on: September 18, 2012, 10:20:54 AM »
aaaah! i was not deep enough. sigh, that is embarrassing.

thanks for clearing it up