Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Shifty Geezer on July 19, 2016, 02:17:11 PM

Title: Move drag drop item via code?
Post by: Shifty Geezer on July 19, 2016, 02:17:11 PM
What's the correct way to return a drag/drop item to a scrollview via code? I have a list of players and when a player joins via network, return the corresponding character to the selection list. This works by modifying the OnDragDropRelease() method except the scrollview script isn't assigned so I can't scroll the selector.
Title: Re: Move drag drop item via code?
Post by: ArenMook on July 20, 2016, 03:23:15 AM
A drag & drop item is still just a UI element. You can reparent it under a different UI element and execute that element's parent UIGrid's Reposition() like the drag & drop script does.
Title: Re: Move drag drop item via code?
Post by: Shifty Geezer on July 20, 2016, 03:54:26 AM
Think that's what I'm doing, but the Scrollview isn't being assigned in the attached UIDragScrollView script.

  1. public void ReturnToRoster(){
  2.         IO_DragDropContainer container = sourceContainer;
  3.         if (container != currentContainer)      {
  4.                 if(container == sourceContainer){
  5.                         // Returned to roster. Change selected char to none?
  6.                         gameObject.name = "adventurer"+(((adventurerIndex+1) < 10) ? "0" : "")+(adventurerIndex+1);
  7.                         UpdateParty(container);        
  8.                 }
  9.         }else{
  10.                 mTrans.parent = mParent;                                // return to container                                         
  11.         }
  12.                
  13.         // Update the grid and table references
  14.         mParent = mTrans.parent;
  15.         mGrid = NGUITools.FindInParents<UIGrid>(mParent);
  16.         mTable = NGUITools.FindInParents<UITable>(mParent);
  17. //      mDragScrollView.scrollView = sourceScrollview;
  18.         // Re-enable the drag scroll view script
  19.         if (mDragScrollView != null)
  20.                 StartCoroutine(EnableDragScrollView());
  21.                
  22.         // Notify the widgets that the parent has changed
  23.         NGUITools.MarkParentAsChanged(gameObject);
  24.                
  25.         if (mTable != null) mTable.repositionNow = true;
  26.         if (mGrid != null) mGrid.repositionNow = true;
  27.                
  28.         // We're now done. Get new container
  29.         OnDragDropEnd();
  30.  
  31.  
  32.         void UpdateParty(IO_DragDropContainer container){
  33.                 // Common container actions for both roster and party
  34.                 mTrans.parent = (container.reparentTarget != null) ? container.reparentTarget : container.transform;
  35.                 Vector3 pos = mTrans.localPosition;
  36.                 pos.z = 0f;
  37.                 mTrans.localPosition = pos;
  38.                
  39.                 currentContainer = NGUITools.FindInParents<IO_DragDropContainer>(container.transform);
  40.                 if (currentContainer == partyContainer){
  41.                         // See if can add
  42. //                      partyMember = charSelectControl.NextFreePartySpace();
  43. //                      if(partyMember > 0){
  44.                                 charSelectControl.AddToParty(this);
  45.                                 // Set character size
  46. //                              charSelectControl.ChangeChar (sprite, partyMember);
  47. //                      }
  48.                 }else if(currentContainer == sourceContainer){
  49.                                 // Reset size when returning to roster
  50.                         print ("Remove from party member "+partyMember);
  51.                         charSelectControl.RemoveFromParty (partyMember);
  52.                         partyMember = 0;
  53.                         sprite.SetDimensions (charSelectControl.sourceSize, charSelectControl.sourceSize);
  54.                 }
  55.         }
  56.        
  57. }
  58.  
If I try setting DragScrollView.scrollView = sourceScrollview, it doesn't change when dropped into a new container. It's supposed to be set in OnEnable in UIDragScrollview but that's not getting called.
Title: Re: Move drag drop item via code?
Post by: ArenMook on July 20, 2016, 04:14:41 AM
Why are you calling OnDragDropEnd()?

If you're trying to do this while dragging the element, you should be doing it via UIDragDropItem.StopDragging().