Author Topic: UIScrollView  (Read 187767 times)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIScrollView
« Reply #15 on: January 17, 2014, 12:35:20 AM »
I think this will already be fixed in the next release. Bump it if not.

CBYum

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 17
    • View Profile
Re: UIScrollView
« Reply #16 on: January 20, 2014, 07:20:00 AM »
I'm using a ScrollView to scroll a Grid that uses CenterOnChild to lock each element (is a vertical list of numbers). I'm trying to default it to point to different entries when it's shown but am struggling. I need to place it at element N in the grid. The only way to move it at all seemed to be with CenterOn but this doesn't seem to have an option to snap to an entry and so it slides even if I set a stupidly high strength. It also requires that I have the transform of the target entry but I only know the index at the moment (and Grid doesn't keep a list).

What way should I be using to achieve this?

Thanks

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIScrollView
« Reply #17 on: January 20, 2014, 07:36:56 AM »
UICenterOnClick is a useful script to look at. It will use UICenterOnChild if present, or simply SpringPanel to the target position if not. I'd recommend using that as a starting point.

AbsurdInteractive

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
Re: UIScrollView
« Reply #18 on: January 24, 2014, 08:00:10 PM »
We've setup a Vertical ScrollView as mentioned, but our paging doesn't really seem to work. We have two grids of 12 UIButtons each parented under the ScrollView.

The layout is like this:

Container
|-- ScrollView
     |-- Grid
          |-- UIButtons x 12
     |-- Grid
          |-- UIButtons x 12

If you swipe upwards really fast it will pop to the next "page" grid, but if you click and drag upwards the paging will not happen and the scrollview will stop in-between the 2 pages, which is undesirable. Is there a way to make sure that no matter whether the player wipes or drags that the scrollview will pop to the closets page?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIScrollView
« Reply #19 on: January 25, 2014, 02:42:29 AM »
Yes, by using UICenterOnChild. Place it on the same object as your Scroll View. It will use the children's positions to determine what's closer (in your case -- Grid objects). So I suggest you make sure that the positions are centered. I wouldn't use UIGrid in your case as it's always top-left based instead.

AbsurdInteractive

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
Re: UIScrollView
« Reply #20 on: January 25, 2014, 06:29:17 PM »
We were using UIGrid so that out level buttons were nicely placed in nice and neat 3x4 fashion for each page.

Is there a way to make the UIGrid not top-left based? If not is there an alternative to keeping UIButtons nicely grid like, but with center based?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIScrollView
« Reply #21 on: January 25, 2014, 06:42:08 PM »
I'm going to change the UIGrid to make it possible to change the pivot in a future update. Right now it's always top-left. You can edit it to support other methods if you like, or just create a simple positioning script yourself to do that. transform.childCount gives you the number of children. Knowing that you want certain number of columns, iterating through the children via transform.GetChild(i) and changing its localPosition is a trivial matter. Afterwards, offset the grid object's position by number of columns * 0.5 * cell width.

NGUIJeffS

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 19
    • View Profile
Re: UIScrollView
« Reply #22 on: February 01, 2014, 05:08:10 PM »
Hello, I've looked through the docs for an answer to this question but have found nothing or I've overlook it. My question is, Is there a way to restrict the mouse "grabbing"/dragging of scroll items to only occur within the visible portion of a scroll window?

That is, I have a simple scroll window as shown in the latest 3.0.7 tutorial with 12 items in the scroll window, but only 2 items are seen (are showing) in the visible area of the window at any given time. It's an Hz scroll window. Everything works fine (HZ scrolls nicely) with the exception that if I place the mouse just outside of the scroll windows visible area I'm able to drag items not shown in the window into the window. Is that right? I would expect that only the items visible in the window would react to the mouse grab and drag. Am I doing something wrong? Is there a setting I'm missing that would limit mouse drag to only occur for items in the window? or is this just the way it works? Hope I'm making sense.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIScrollView
« Reply #23 on: February 01, 2014, 07:01:36 PM »
NGUI events are always clipped by the scroll view's region if the UICamera is set to "UI" mode. If it's set to "World", then they aren't.

NGUIJeffS

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 19
    • View Profile
Re: UIScrollView
« Reply #24 on: February 01, 2014, 07:13:17 PM »
Yes, My UICamera (script) Event Type was set to World. I changed it to UI and all works well and it makes sense. Excellent! After building and rebuilding my scroll windows several times I thought it had to be something simple. Thanks so much!

monogon

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: UIScrollView
« Reply #25 on: February 26, 2014, 03:53:25 PM »
Hey ArenMook,
I'm trying to utilize UIScrollview to build a little button press game.
The first button in the scrollview is supposed to be the current button that the player has to press.
When he hits the right button, I want this sprite to "dequeue" from scrollview (as if dragged out of scrollView manually) and the other sprites to move up to the current position within UIGrid (smoothly). Then I want a new button to be created at the end of the scrollview grid. For dragging the sprite out of the scrollview and vanishing I thought of an invisible second panel with a box collider.
I followed your tutorial, UIGrid with Scrollview and dragging is working fine but now I need to know how to access the 'dequeuing'/dragging out of scrollview from script.
Do you think there is a way to use UIScrollview this way? Or am I on the wrong track!

Btw awesome tool. I bought your plugin last week and am very pleased so far!

Thanks in advance!

Regards! monogon

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIScrollView
« Reply #26 on: February 26, 2014, 03:55:10 PM »
Have you seen the Drag & Drop example that comes with NGUI? It does just that.

monogon

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: UIScrollView
« Reply #27 on: February 26, 2014, 08:28:58 PM »
Thank you!

I know created a class inherited from UIDragDropItem that serves its purpose.

On start I create an array of 10 int values which I then fill with random values between 1 and 5. Now I have a script in my scrollView that grabs this array and instantiates icons for every value in the array as a child of the Grid-Object in the scrollview. '1' results in an instance of iconButton1, '2' in an instance of iconButton2 and so on.

The instantiation works fine and the icons are sorted within the grid (each button has a offset of 75px). However, the instances are created with a z-value of 5400 and a uniform scale of 360 each, although the prefab has the position (0,0,0) and the scale (1,1,1). Do you know what goes wrong during the instantiation process?

I now adjusted the values manually after instantiation but I'm very curious to find the reason for this bug.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIScrollView
« Reply #28 on: February 27, 2014, 06:48:27 PM »
You need to use NGUITools.AddChild(parent, prefab) to instantiate objects. It sets the parent, scale, and layer properly all in one function.

RelayOne

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: UIScrollView
« Reply #29 on: March 05, 2014, 11:24:36 AM »
I just upgrade NGUI, and am in the process of upgrading UIDraggablePanel to UIScrollView. My UIDraggablePanel components were reporting missing scripts. I tried to create new UIScrollView using "Add Component", but it was missing from the menu.

I renamed the .cs file from UIDraggablePanel.cs to UIScrollView.cs, and all of a sudden everything worked.

I also had to rename UICheckbox.cs to UIToggle.cs, and that also made everything work.

I'm running Unity 4.3.1f on a Macbook Air with Mavericks. I'm also using Editor Settings -> version control -> Mode -> Visible Meta Files.