Author Topic: Drag Drop Issue  (Read 2153 times)

dipu5683

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 27
    • View Profile
Drag Drop Issue
« on: May 12, 2014, 04:05:57 AM »
Hi
i am implementing the drag drop functionality for my cricket game where user can able to swap a player from playing 11 team to substitute player and vice-a-verse. I have implemented it as follow.

for playing 11
LeftContainer (uiwiget , drag drop container , drag scroll view,box collider) attached
  - Left Scroll View ( uipanel , uiscrollview )
     - Grid (uigrid )

On runtime i have added the player prefab (Drag Drop script , uidrag scroll viiew script attached) .

Similarly RightContainer for the substitute player .

Drag and drop is working in my project. But i am trying 2 following functionality.

1. when i select the 2nd position (XYZ) player from the LeftContainer and drag it , and drop it on to 3rd position (PQR) Right substitute player list , then it should swap , 3rd (PQR) player should appear at the 2nd postion of the LeftContainer & 2nd player should be adjusted at 3rd position of the Right Substitute player list container.

Presently it is adding it to the last of the list.

2. When i select a (xyz)object from leftcontainer , and drag it to some object (pqr) of rightcontainer , (pqr) object should give some give auto scale feature(visual feedback) to show that i am the destination object on which you can drop the object(xyz).

Can anybody help me out ?
thanks










dipu5683

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 27
    • View Profile
Re: Drag Drop Issue
« Reply #1 on: May 13, 2014, 01:47:19 AM »
Hi

I some how managed to implement the following

2. When i select a (xyz)object from leftcontainer , and drag it to some object (pqr) of rightcontainer , (pqr) object should give some give auto scale feature(visual feedback) to show that i am the destination object on which you can drop the object(xyz).


But i am still facing issue in implementing the following


1. when i select the 2nd position (XYZ) player node from the LeftContainer and drag it , and drop it on to 3rd position (PQR) node Right substitute player list , then it should swap , 3rd (PQR) player should appear at the 2nd postion of the LeftContainer & 2nd player should be adjusted at 3rd position of the Right Substitute player list container.

Presently it is adding it to the last of the list.
I want swaping should be done only between two position of the two containers.





dipu5683

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 27
    • View Profile
Re: Drag Drop Issue
« Reply #2 on: May 13, 2014, 02:59:17 AM »
And more issue i forgot to mention.

1. Moment i select an object and start dragging slowly then all other nodes of that grid or container reposition itself automatically.
   I don't want it.

2. When i drag (xyz) some object from left container , and drop it on (pqr) object on right container, then xyz adjusted in right container , & pqr object adjusted in left container BUT PQR object comes from the right side of the left container ( with clipping ) which is looking not connected visually . It should come normally from right to left without clipping . It should come normally as i dragged the object out side the left panel (visible) .

i am using the following code to swap back.

// Container found -- parent this object to the container
            target.transform.parent = (Container.reparentTarget != null) ?
               Container.reparentTarget : Container.transform;
            
            // Update the grid and table references
            NGUITools.FindInParents<UIGrid>(target.transform.parent);
            NGUITools.FindInParents<UITable>(target.transform.parent);
            
            UIDragScrollView dSV = NGUITools.FindInParents<UIDragScrollView>(target);
            if (dSV != null)
            {
               dSV.scrollView = NGUITools.FindInParents<UIScrollView>(target.transform);
            }
            
            // Notify the widgets that the parent has changed
            NGUITools.MarkParentAsChanged(target);
            
            Vector3 pos = target.transform.localPosition;
            pos.z = 0f;
            target.transform.localPosition = pos;

        m_playing11Grid.sorted = false;
        m_playing11Grid.Reposition();
        m_playing11ScrollView.UpdateScrollbars(true);

        m_substituteGrid.sorted = false;
        m_substituteGrid.Reposition();
        m_substituteScrollView.UpdateScrollbars(true);
« Last Edit: May 13, 2014, 06:09:14 AM by dipu5683 »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Drag Drop Issue
« Reply #3 on: May 13, 2014, 08:54:57 AM »
1. If you don't want the grid to adjust the position of its children, then you need to modify the drag & drop item logic to not Reposition() the grid. Line 178 of UIDragDropItem.

2. Item comes in wherever you dropped it by default, but where it goes depends on the grid's sorting parameter.

dipu5683

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 27
    • View Profile
Re: Drag Drop Issue
« Reply #4 on: May 13, 2014, 10:19:09 AM »
Currently grid sorting parameter is NONE and sorted = false , currently i want it to place the dragged object, on the object where i am dropping it (UICamera.hoveredObject);
« Last Edit: May 13, 2014, 10:43:38 AM by dipu5683 »