Author Topic: [Bug?] Draggable Object inside of containing Panel with DragEffect:None  (Read 6931 times)

raydenuni

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 18
    • View Profile
I created an empty scene, made a containing Panel and set it's clip to alpha and then added a button outside the Panel's hierarchy and made it a Draggable Object. This works. Then I made the button's drag effect none (from MomentumAndSpring) and that sort of works. The button has bounds, the bounds seem to depend on the button's current location and not the panel (not sure if that's a bug or I'm doing something wrong). Then I moved the button underneath the panel in the hierarchy and I could no longer drag it. Changing drag effect to MomentumAndSpring makes it work again, but the combination of None and being under the clipping panel in the hierarchy breaks the drag.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: [Bug?] Draggable Object inside of containing Panel with DragEffect:None
« Reply #1 on: January 16, 2014, 10:18:05 PM »
Why are you dragging something inside a scroll view using UIDraggableObject script? You should be using UIDragScrollview, or the DragDropItem logic instead. Look at the drag & drop example that comes with NGUI.

raydenuni

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 18
    • View Profile
Re: [Bug?] Draggable Object inside of containing Panel with DragEffect:None
« Reply #2 on: January 17, 2014, 01:01:56 PM »
Because it's neither a scroll view nor a drag and drop use case?

I have buttons that I want to drag to activate instead of clicking on them. They only move horizontally, and I only want them to drag so far.

raydenuni

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 18
    • View Profile
Re: [Bug?] Draggable Object inside of containing Panel with DragEffect:None
« Reply #3 on: January 17, 2014, 01:04:37 PM »
Essentially I have buttons I want to swipe to activate. Perhaps I'm over-complicating things and there's a better way to do that.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: [Bug?] Draggable Object inside of containing Panel with DragEffect:None
« Reply #4 on: January 17, 2014, 02:27:56 PM »
MomentumAndSpring effect moves the content by using SpringPanel script which notifies the scroll view by calling UIScrollView.UpdateScrollbars(false);

UIDragObject was never meant to move the contents of a scroll view, so it doesn't do this. That's why you are seeing a discrepancy. You can probably get it to work the way you expect by changing UIDragObject.Move function to the following:
  1.         void Move (Vector3 worldDelta)
  2.         {
  3.                 if (mPanel != null)
  4.                 {
  5.                         mTargetPos += worldDelta;
  6.                         target.position = mTargetPos;
  7.  
  8.                         Vector3 after = target.localPosition;
  9.                         after.x = Mathf.Round(after.x);
  10.                         after.y = Mathf.Round(after.y);
  11.                         target.localPosition = after;
  12.  
  13.                         UIScrollView ds = mPanel.GetComponent<UIScrollView>();
  14.                         if (ds != null) ds.UpdateScrollbars(true);
  15.                 }
  16.                 else target.position += worldDelta;
  17.         }

raydenuni

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 18
    • View Profile
Re: [Bug?] Draggable Object inside of containing Panel with DragEffect:None
« Reply #5 on: January 20, 2014, 02:57:14 PM »
I'm not using a scroll view. I don't know where you got that from.

I simply have a UIDragObject that I want to contain within a panel. I want to be able to drag it around, but have it bump up against the edges of a container. If I put it into a panel and turn on alpha clip it won't draw outside of the panel, but I want it to be prevented from moving outside of it.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: [Bug?] Draggable Object inside of containing Panel with DragEffect:None
« Reply #6 on: January 21, 2014, 02:29:04 AM »
Ah, well you were talking about a clipped panel, and a clipped panel is a scroll view, minus the actual script that adds the movement.

Here is a quick test I did:

1. New scene.
2. Added a sprite and gave it a collider.
3. Added a scroll view (you can then remove the Scroll View script itself if you want).
4. Moved the sprite within the scroll view.
5. Attached UIDragObject to the sprite, checked "Keep Visible", and set the "Content Rect" to be the sprite itself.

I can now drag the sprite around and it will snap back into view after I release it outside the scroll view's bounds. If I change the Drag Effect on UIDragObject to be "None", I can no longer drag it outside the bounds at all. It's restricted to the scroll view's bounds.

raydenuni

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 18
    • View Profile
Re: [Bug?] Draggable Object inside of containing Panel with DragEffect:None
« Reply #7 on: January 22, 2014, 07:58:56 PM »
I see. That does as you say. I guess I was expecting it to hard lock it to the container, not snap it back. Oh well.