Author Topic: Dragging only a Copy from one ScrollView to another.  (Read 3854 times)

wallabie

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 200
    • View Profile
Dragging only a Copy from one ScrollView to another.
« on: April 25, 2014, 10:37:53 AM »
1. user drags an item from A to B.
2. Do not drag A, only drag a copy of A to B.  Meaning that A is not moved at all.  Only a copy of A is dragged to B.

Separate from the question above but I thought I put this request in before I forget it.

Request:
I'm using PressAndHold to drag the items.  Can this be exposed so that we can set our own interval.  I am finding that 0.2f works well in my case.

      else if (restriction == Restriction.PressAndHold)
         {
            if (mPressTime + 0.2f > RealTime.time) return;
         }

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Dragging only a Copy from one ScrollView to another.
« Reply #1 on: April 25, 2014, 10:53:50 AM »
That's what "Clone on drag" option does. It makes a copy of the item and makes you drag this copy.

wallabie

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 200
    • View Profile
Re: Dragging only a Copy from one ScrollView to another.
« Reply #2 on: April 25, 2014, 11:29:00 AM »
Hey, that was easy.  I tested in the example and it does what it advertised.  Only thing is that when I insert in in the other scrollView, nothing is inserted.

wallabie

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 200
    • View Profile
Re: Dragging only a Copy from one ScrollView to another.
« Reply #3 on: April 25, 2014, 11:53:04 AM »
More extensive testing of the "Clone on Drag" on a 4 X 4 ScrollView is showing that when the item is being dragged, the positions of the other items do not stay the same, they do a dance and switch around.  The expected behaviour is that everything on in the ScrollView would be static, the only thing that moves is the copy that is being dragged. 

I made a prefab to show this problem.  Here is a link:
https://dl.dropboxusercontent.com/u/48378123/UI%20Root%20%282D%29.prefab

This can be dropped into the example 11 - Drag & Drop scene.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Dragging only a Copy from one ScrollView to another.
« Reply #4 on: April 26, 2014, 01:35:19 PM »
Your grid is set to "Vertical" sorting, yet it's a horizontal placement grid...

The "nothing happens on drop" is because you are the one that needs to change the logic for what happens when you drop a cloned item. Look inside UIDragDropItem's OnDragDropRelease function. It has a check: if the item is cloned, simply destroy it. Override this function in your custom Drag & Drop item script and do what you need it to.

You will also get the same effect if you simply comment out the "if (!cloneOnDrag)" section, but then you will run into an issue where you can drop the item into the scroll view you started it with, effectively duplicating items.

This is where custom logic needs to filter this kind of behaviour -- which is the valid scroll view to be dropped into and which isn't?