Author Topic: UISlider scaling issue  (Read 2167 times)

rain

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 4
  • Posts: 79
    • View Profile
UISlider scaling issue
« on: July 19, 2013, 11:59:46 AM »
Hi!

I have a Slider built from UISlider and different types of Sprites(see attachment for picture).
The left and right side(1 and 4) is made of simple sprites. Between them, the body of the slider is a tiled sprite which is tiled from the part numbered 3. The slider foreground is also a tiled sprite from the part numbered 2. A custom-made script manages the size of the middle part depending on a certain container size so the slider won't grow bigger than that.

My issue is: If I scale the middle part of the slider in runtime, making the clickable area smaller or bigger, the UISlider script won't keep up with the changes and its collider will be out of sync.

Any ideas to fix this?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UISlider scaling issue
« Reply #1 on: July 19, 2013, 06:57:44 PM »
NGUITools.AddWidgetCollider updates the collider. You need to manually update it using that function if you are resizing sprites underneath it.
« Last Edit: July 22, 2013, 04:44:48 AM by ArenMook »

rain

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 4
  • Posts: 79
    • View Profile
Re: UISlider scaling issue
« Reply #2 on: July 22, 2013, 04:43:08 AM »
Do you mean NGUITools.Addchild(go) where 'go' is the GameObject which has the UISlider script attached to it? Because it doesn't seem to update the colliders this way. Why would that update the mCol,mSize,mCenter fields in the UISlider script?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UISlider scaling issue
« Reply #3 on: July 22, 2013, 04:45:03 AM »
Typo -- I meant NGUITools.AddWidgetCollider

rain

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 4
  • Posts: 79
    • View Profile
Re: UISlider scaling issue
« Reply #4 on: July 22, 2013, 05:35:39 AM »
The collider size seems to be fine now, but the foreground sprite scales over the slider now, as seen on the screenshot. :(

Edit: Setting mSize and mCenter to Vector2.zero and also calling the Init function solved my problem.
Edit2: Although I think the UISlider should be aware of the changing collider size without additional hacks on my end.
« Last Edit: July 22, 2013, 09:24:08 AM by rain »