Support => NGUI 3 Support => Topic started by: Fbary on July 05, 2012, 04:43:11 AM
Title: change Sprite in UISlicedSprite
Post by: Fbary on July 05, 2012, 04:43:11 AM
Before posting I searched in the forum, but I dind't find an answer to my question, so I'm asking it here =P
A have a button prefab. I instantiate that prefab, and its background has a UISLicedSprite script on it. I use a manager to instantiate that, and to assign the right atlas to use. So I reach the gameobject ->
Now, after that, I've to assign the right current sprite wich is in the atlas.spritelist. I tried like this:
Button.transform.GetChild(0).GetComponent<UISlicedSprite>().sprite= myaltas.spritelist[i]//(this is in a for loop)
But all the button instantiated have all the same sprite (spritelist[0] i think). How can i change that sprite after instantiation? UISlicedsprite.sprite can change the sprite, or can only be read?
Title: Re: change Sprite in UISlicedSprite
Post by: ArenMook on July 05, 2012, 07:33:50 AM
You change the sprite via the "spriteName" field.
Title: Re: change Sprite in UISlicedSprite
Post by: Fbary on July 06, 2012, 05:22:25 AM
I can assign the current sprite in use just using the string name? mh mh... I've to change a couple of things..
Thank you =)
Title: Re: change Sprite in UISlicedSprite
Post by: Fbary on July 06, 2012, 06:05:49 AM
A little more question..
atlas.spritelist[0] isnt' my first sprite. How can i know the order it considers to create this list? I need to move in that list using the index, but i need to know the order it creates.
When i select a sprite to use clicking on "Sprite" in the ispector, they are all in alphabetic order. Evidently it's not the real order in the list. O.o
Title: Re: change Sprite in UISlicedSprite
Post by: ArenMook on July 06, 2012, 08:26:11 AM
I'm not sure why you need the indices. You have a list of sprites, why does it matter what order they are in internally? If you want to run through the list and match the sprite names, you can do that easily.
Title: Re: change Sprite in UISlicedSprite
Post by: Fbary on July 06, 2012, 10:46:15 AM
Ok, here's my situation:
I have a for loop, I use it to create a selected number of buttons (wich are prefabs instantiated). I set al the parameters in them, and, last thing, I have to set the background's sprite for each one (always inside the loop). So i want to assign to every button created a sprite inside the spritelist of the Atlas in use.
Example:
I know my first 5 buttons must have the first 5 sprites in the altas. So i want to assign button's background -> atlas.spritelist. But it seems to not work. I need to know the order, because i can't assign the sprite using the string's name, it would be too heavy.
Why can't I use the index in the atlas.spritelist[index] as a normal list? Wich order does it use to create the atlas? alphabetic order, First-In order, or just random one? I used: