Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: justinISO on December 30, 2013, 11:45:35 AM

Title: UICenterOnChild on only one axis?
Post by: justinISO on December 30, 2013, 11:45:35 AM
I have tried (unsuccessfully) to modify the UICenterOnChild code so that it only centers based on say closest x value instead of closest distance.

I basically have one horizontal scroll view that has five children (left to right), each one of those children is a vertical scroll view that has four to five children (up and down).

I want to modify the CenterOnChild script so that as I am scrolling left to right, it only centers on those five children based on their x distance.

Any thoughts?

Thanks,
Justin
Title: Re: UICenterOnChild on only one axis?
Post by: ArenMook on December 30, 2013, 01:27:04 PM
You limit the axes on the scroll view (Movement field). UICenterOnChild will respect the scroll view's restriction.
Title: Re: UICenterOnChild on only one axis?
Post by: justinISO on December 30, 2013, 01:37:42 PM
I understand what you are saying but it doesn't really work for this application.

If you think of it like this:

1 - 2a - 3
      |
     2b
      |
     2c

Where 1,2a,3 are children in the horizontal scroll and 2a,2b,2c are in a vertical scroll.

I can scroll over to 2a just fine and scroll up to 2b just fine, but when I scroll up to 2c, the position of the vertical list containing 2a,2b,2c is further from the center than is 1 or 3 so the horizontal center on child scrolls over to one of those instead of staying on column 2 and allowing me to go to 2c.

Hope this makes a little sense?

Thanks,
Justin
Title: Re: UICenterOnChild on only one axis?
Post by: ArenMook on December 30, 2013, 01:41:13 PM
Make each of your children a UIWidget. This lets you specify an area for each, rather than have NGUI force-calculate it using the sum of game object's children.
Title: Re: UICenterOnChild on only one axis?
Post by: justinISO on December 30, 2013, 01:53:24 PM
Ok, I made the vertical scroll view that contains the 2a,2b,2c a widget and gave to the proper dimensions of the 3 panels combined. However, it still snaps to either 1 or 3 as soon as I scroll up to 2c.

~Justin
Title: Re: UICenterOnChild on only one axis?
Post by: ArenMook on December 31, 2013, 07:22:35 AM
I meant structuring it like so:

Scroll View
- Item 1 (widget)
- Item 2 (widget)
-- 2A
-- 2B
-- 2C
- Item 3 (widget)

This way Item 1, 2, and 3 all have the same width and height, thus keeping a fixed "cell" size.
Title: Re: UICenterOnChild on only one axis?
Post by: justinISO on December 31, 2013, 10:30:55 AM
Hey thank you so much for your help!

The answer was simpler than it should be (as is usually the case). I just parented the vertical scroll views to empty game objects that are at the center of the 1,2,3,etc and then the vertical scroll does not move those empty game objects so centering on the x works correctly!

Thanks again!

~Justin