Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Codewalker on June 28, 2012, 11:51:30 AM

Title: Assign Atlas by name
Post by: Codewalker 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)
Title: Re: Assign Atlas by name
Post by: JRoch 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...
Title: Re: Assign Atlas by name
Post by: Codewalker 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.
Title: Re: Assign Atlas by name
Post by: ArenMook 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.
Title: Re: Assign Atlas by name
Post by: iossif 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
Title: Re: Assign Atlas by name
Post by: ArenMook 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.
Title: Re: Assign Atlas by name
Post by: iossif on September 18, 2012, 10:20:54 AM
aaaah! i was not deep enough. sigh, that is embarrassing.

thanks for clearing it up