Tasharen Entertainment Forum
Support => NGUI 3 Support => Topic started by: capitalj on May 07, 2012, 07:33:33 PM
-
Hi,
I would like to scroll the contents of my scroll view (draggable panel version) using buttons (like a scroll left and scroll right button) instead of using scroll bars. What should the onclick of the buttons modify to do this?
-JJ
-
Look into the UIDraggablePanel.SetDragAmount function.
-
Yes, I saw that one but it looks more like it will just drag to a specified position.
1. is there a way to read the drag position so that I could just increment it and still use SetDragAmount? Or do I have to create my own var for that?
2. It sounds like the .Drag function would do exactly what I am looking for but it doesn't seem to actually have any effect. I've tried with both setting a Vector2(x,y) and using a Vector2.right
3. With either of these methods is there a way to animate the drag so that it moves the panel as if you used a finger swipe? (so that it doesn't just jump to the new position)
-JJ
-
You mentioned that you want to control it purely via buttons instead of the scroll bar, so I assume you don't need to read the drag amount value. Start with 0 in your script, and increment / decrement it with the buttons.
Drag function is your OnDrag event callback, it only works after the drag process started (after Press(true)).
You can interpolate the position using the SetDragAmount method I suggested. Just interpolate your value before passing it to the function.
-
I'm trying to the same thing, using SetDragAmount to some value between 0 and 1, and it is moving the clipped area around rather than the contents. I'm sure I must be missing something obvious, but am quite new to NGUI. Any ideas?
-
That's how dragging works -- clipped area is moved, while the contents stay in place. This way the buffers don't need to be rebuilt while dragging the UI, resulting in better performance. From the game's perspective it should work exactly as you expect with the window's contents moving properly.
-
I'm confused, if the clipped area moves and contents stay still, wouldn't the clipped area eventually be off screen? Is the camera supposed to follow the clipped area?
After playing around, I found that if I remove this 'if' condition inside SetDragAmount, it seems to work fine.
if (!updateScrollbars)
{
Vector3 pos = mTrans.localPosition;
if (scale.x != 0f) pos.x += cr.x - ox;
if (scale.y != 0f) pos.y += cr.y - oy;
mTrans.localPosition = pos;
Debug.Log ("Drag Position x: "+x +", y: "+y+", to : "+mTrans.localPosition);
}
-
Camera? What does camera have to do with it? Draggable panel script works with shader-based clipping. Camera-based clipping is an entirely different beast.
-
Krubba, your clipped area moves and the draggable panel's local position moves opposite to it.
-
clipped area and panel moving opposite to each other kind of makes sense to me i think, but if i look at the code in SetDragAmount, the only place the panel is moved is inside that "if" statement. I was passing in updateScrollbars = true (since i don't know why you wouldn't update scrollbars, so the if statement was skipped, and only the clipped area moves, not the panel itself.
Not sure why the panel wouldn't be moved if updateScrollbars is passed in as true....
-
Because if you have scroll bars, you should move the panel via those scroll bars. It's not a very elegant solution, but it's there to prevent fighting of different components. Scroll bars have higher authority, and handle things slightly differently.