Hello Guest

Author Topic: about UI prefab  (Read 4211 times)

lofl

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 12
    • View Profile
about UI prefab
« 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!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: about UI prefab
« Reply #1 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?

lofl

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: about UI prefab
« Reply #2 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.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: about UI prefab
« Reply #3 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.

lofl

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: about UI prefab
« Reply #4 on: July 08, 2013, 09:01:41 pm »
Thanks for your advice.

I'll try it.