Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: MetaMythril on May 27, 2012, 01:06:06 AM

Title: Scroll View Snap to Item and Drag Issue
Post by: MetaMythril on May 27, 2012, 01:06:06 AM
I've created a scroll list to scroll through about 3 full screen panels that make up a map with buttons attached to each panel for stage selection. I'm trying to figure out how to best "snap" to the closest item in the list.

I'm also having an issue when dragging the panels, the first and last panel are able to be dragged to half of the screen width.

(http://dl.dropbox.com/u/23549660/Unity3D/ngui.scroll.end.clip.png)

Any help would be greatly appreciated!
Title: Re: Scroll View Snap to Item and Drag Issue
Post by: ArenMook on May 27, 2012, 12:41:04 PM
When you release the mouse, figure out the distance to the center of each of your map pieces. Choose the closest one, and SpringPosition there.

I am not quite sure what you mean by the last part.
Title: Re: Scroll View Snap to Item and Drag Issue
Post by: MetaMythril on May 27, 2012, 12:48:25 PM
When you release the mouse, figure out the distance to the center of each of your map pieces. Choose the closest one, and SpringPosition there.

I am not quite sure what you mean by the last part.

I'm not quite sure how to use SpringPosition, do you have an example somewhere?

As for the last problem. What I'm saying is that the edge of the map should not go to the half point of the screen but for some reason it is. For example, in your Scroll View example, the edge of last and first items should meet the edge of the scroll view area when released, for some reason my map piece just stays anywhere between the edge and the half way point of the screen.
Title: Re: Scroll View Snap to Item and Drag Issue
Post by: ArenMook on May 27, 2012, 12:50:11 PM
  1. SpringPosition.Begin(gameObjectToMove, targetPosition, strength);

...where 'strength' is how fast you want it to move. 3 is slow and smooth, 8 is quick. 1000 is instant.
Title: Re: Scroll View Snap to Item and Drag Issue
Post by: ArenMook on May 27, 2012, 12:52:12 PM
Make sure "Restrict Within Panel" checkbox is checked on UIDraggablePanel.
Title: Re: Scroll View Snap to Item and Drag Issue
Post by: MetaMythril on May 27, 2012, 12:56:34 PM
Make sure "Restrict Within Panel" checkbox is checked on UIDraggablePanel.

That option is checked, which makes it odd why it's not stopping at the edge of the item.
Title: Re: Scroll View Snap to Item and Drag Issue
Post by: MetaMythril on May 27, 2012, 12:59:38 PM
  1. SpringPosition.Begin(gameObjectToMove, targetPosition, strength);

...where 'strength' is how fast you want it to move. 3 is slow and smooth, 8 is quick. 1000 is instant.

So basically I'll need to add a custom script attached to the panel to check the distance and apply the SpringPosition of the child objects in the UIGrid?

I really appreciate the help with this. :)
Title: Re: Scroll View Snap to Item and Drag Issue
Post by: ArenMook on May 27, 2012, 01:20:07 PM
Not to the panel but to whatever you're dragging. The same object that has UIDragPanel.
Title: Re: Scroll View Snap to Item and Drag Issue
Post by: MetaMythril on May 27, 2012, 02:21:18 PM
Not to the panel but to whatever you're dragging. The same object that has UIDragPanel.

I'm using UIDragPanelContents if that makes any difference.

Any ideas about the scrolling of my objects past the edge?
Title: Re: Scroll View Snap to Item and Drag Issue
Post by: ArenMook on May 27, 2012, 02:27:24 PM
The ability to scroll past the edge is in the dragging style specified on UIDraggablePanel. MomentumAndSpring is the default, which means you can go past the edge. Try others.

The springing back into place after you release the mouse button is what "Restrict Within Panel" does.
Title: Re: Scroll View Snap to Item and Drag Issue
Post by: MetaMythril on May 27, 2012, 11:49:13 PM
The ability to scroll past the edge is in the dragging style specified on UIDraggablePanel. MomentumAndSpring is the default, which means you can go past the edge. Try others.

The springing back into place after you release the mouse button is what "Restrict Within Panel" does.

That's the problem, it's not springing back to the edge (if you use MomentumAndSpring). It will let me pull it all the way off screen, then it will only spring the left side of the map to the middle of the screen instead of going all the way back to the left side.

I'm also using the "Restrict Within Panel" option, so I'm not sure what I'm missing.
Title: Re: Scroll View Snap to Item and Drag Issue
Post by: MetaMythril on May 28, 2012, 12:40:32 AM
Ok, I managed to fix the issue. It seems that when I set it to "Hard Clip" that I needed to set the size of the clipping area. For some reason it was rendering fine without defining this, but was causing issues with dragging. After I defined the clipping size it is working fine.

Now I just need to get the snapping done. Thanks again for the help, sorry to be a bit of a pain. My first day really sitting down to use this. Though I've been reading and watching plenty of material to get me started. So far I'm making amazing progress with my UI that took me a lot more time when I was using EZ GUI. :)
Title: Re: Scroll View Snap to Item and Drag Issue
Post by: MetaMythril on June 03, 2012, 03:58:20 PM
Not to the panel but to whatever you're dragging. The same object that has UIDragPanel.

Just not getting back to this after dealing with other issues. How do I determine that I have stopped dragging so that I can apply the snap? I don't see anything exposed that could be useful.
Title: Re: Scroll View Snap to Item and Drag Issue
Post by: ArenMook on June 03, 2012, 07:33:28 PM
You get OnPress(false) when you release the touch.
Title: Re: Scroll View Snap to Item and Drag Issue
Post by: MetaMythril on June 05, 2012, 11:25:19 PM
Thanks, though I'm still having problems. Seems like trying to move the drag panel with SpringPosition has issues with the clipping.

Would love to see something like magnet snapping for items in a scroll view as a standard feature. I'm still new to this system so it's a bit difficult to know what I can and can't do at the moment, so I'm probably approaching things from the wrong angle.

I know EZGUI had the snapping feature but obviously it probably doesn't translate well over to NGUI.

Any other help you could offer with this? I greatly appreciate the help.
Title: Re: Scroll View Snap to Item and Drag Issue
Post by: ArenMook on June 05, 2012, 11:40:51 PM
SpringPosition is not meant to be moving drag panels. You're looking for SpringPanel.
Title: Re: Scroll View Snap to Item and Drag Issue
Post by: MetaMythril on June 08, 2012, 11:49:19 AM
SpringPosition is not meant to be moving drag panels. You're looking for SpringPanel.

Thanks, starting to get it now.
Title: Re: Scroll View Snap to Item and Drag Issue
Post by: soulis6 on June 19, 2012, 01:39:08 PM
Not to the panel but to whatever you're dragging. The same object that has UIDragPanel.

Hello, i'm trying to get this same thing to work in our project, and this is where i'm running into trouble, figuring out what object(s) to use SpringPosition on.

I don't have any script called UIDragPanel in the newest version of NGUI, was that renamed? Is it UIDraggablePanel? If so, when trying to use SpringPosition on the panel with UIDraggablePanel on it, it moves the entire panel, clipping and all, which is not useful.

Are you supposed to use it on each of the child objects? If so the SpringPosition works fine on that one particular object, but then it doesn't get re-organized by the grid.

I would really appreciate any help with this, as I just can't seem to figure out how it's supposed to be set up.
Title: Re: Scroll View Snap to Item and Drag Issue
Post by: ArenMook on June 19, 2012, 01:47:51 PM
UIDragPanelContents is he script that should be attached to colliders, and UIDraggablePanel is the script that should be attached to the panel.
Title: Re: Scroll View Snap to Item and Drag Issue
Post by: soulis6 on June 19, 2012, 02:03:26 PM
Thanks for the quick response. I get the set-up of the scroll list, and the scroll list itself works perfectly, along with finding the closest one to the center of the screen and scaling that one up.

My question is regarding the SpringPosition, and what you're supposed to use that on in order to get the snapping scroll list.

thanks again for your time.
Title: Re: Scroll View Snap to Item and Drag Issue
Post by: ArenMook on June 19, 2012, 02:21:13 PM
It should be SpringPanel, not SpringPosition, and you should use it on the panel's game object.
Title: Re: Scroll View Snap to Item and Drag Issue
Post by: soulis6 on June 19, 2012, 05:06:29 PM
Ahhh that was my problem. Thank you very much! Works beautifully now!
Title: Re: Scroll View Snap to Item and Drag Issue
Post by: RocketPop Games on November 15, 2012, 04:29:56 PM
For the convenience of future Googlers / searchers... There is a component UICenterOnChild that you can put on the UIGrid that does all this for you now...