2D Toolkit Forum

2D Toolkit => Support => Topic started by: lofl on July 05, 2013, 11:48:27 pm

Title: about UI prefab
Post by: lofl on July 05, 2013, 11:48:27 pm
How can I get tk2dSlicedSprite in UI prefab(e.g. BasicButton, TextInput)?

And  I'd appreciate if you would teach me how to fit collider at runtime.

Thank you!
Title: Re: about UI prefab
Post by: unikronsoftware on July 06, 2013, 11:53:10 am
The basicbutton already uses a sliced sprite. Textinput consists of more than just a sliced sprite... You can get to it by using GameObject.GetComponentsInChildren or something like that. Or store a link to it.

What are you trying to do fitting the collider at runtime?
Title: Re: about UI prefab
Post by: lofl on July 07, 2013, 07:16:54 am
I try to create UI at runtime.

So I am going to change dimensions, font and collision.
Title: Re: about UI prefab
Post by: unikronsoftware on July 07, 2013, 10:44:42 am
Ok. So for the default one, you will need access to the sliced sprite, font, etc. I suggest making a behaviour and attaching it to the root object if you want to do this, to make it easier and reduce guesswork.

About dimensions, that is easy enough to change on the sliced sprite. After you change dimensions, you'll need to change collision box size as well - you can do that the way it does it in the editor, or calculate it yourself using the sliced sprite dimensions and CurrentSprite.TexelSize - this will be considerably faster than calculating by bounds.
Title: Re: about UI prefab
Post by: lofl on July 08, 2013, 09:01:41 pm
Thanks for your advice.

I'll try it.