Author Topic: [SOLVED]Transforming points from a Scrollview for relative positioning  (Read 4266 times)

Genhain

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 38
    • View Profile
So i have extended UIGrid to give me a bit more control of the visual look of the reparenting tween. The code below is called when the item is dropped into a UIDragDropContainer which points to this as its reparent target. The general idea is create a copy of the element hide the original set the copy to be at the highest level of depth (UIDragDropRoot), find out the originals position in world coordinates. then convert it to local of the parent of the original, and then tween the movement and a callback to cleanup. That is how i assumed you convert between local and world coordinates, because i have done something similar in other areas with success yet here it does not seem to be the case...is there edge cases with scrollviews i am wondering? or am i doing it wrong?

my hierarchy is as follows

DragDropRootPanel
widget
-collider
-ScrollView
  -widget
    -widget
      -ScrollView(with uigrid extension script attached)
        -card
        -card
        -card

it is an odd hierarchy i am aware but i required a vertical scroll and then a horizontal scroll within that and the extra widget is so the inner scrollview is slightly offcenter as the top level scrollview has UICenterOnChild on it.

  1. public override void CardDroppedIntoGrid(WCCard card)
  2. {
  3.         base.CardDroppedIntoGrid(card);
  4.         //create display copy
  5.         GameObject cardDisplayCopy = card.CreateDisplayCopy();
  6.  
  7.         card.GetComponent<UIWidget>().SetVisible(false);
  8.  
  9.         cardDisplayCopy.transform.position = card.transform.position;
  10.  
  11.         // Re-parent the item
  12.         if (UIDragDropRoot.root != null)
  13.                 cardDisplayCopy.transform.parent = UIDragDropRoot.root;
  14.  
  15.         NGUITools.MarkParentAsChanged(cardDisplayCopy);
  16.  
  17.         Vector3 lastElementInGridPos = GetChildList().Last().transform.position;
  18.  
  19.         Vector3 EndValue = transform.InverseTransformPoint(lastElementInGridPos);
  20.  
  21.         cardDisplayCopy.transform.DOLocalMove(EndValue,2,false)
  22.                 .OnComplete(()=>
  23.                 {
  24.                         card.GetComponent<UIWidget>().SetVisible(true);
  25.                         if(!Application.isPlaying)
  26.                                 GameObject.DestroyImmediate(cardDisplayCopy);
  27.                         else
  28.                                 GameObject.Destroy(cardDisplayCopy);
  29.                 }).SetEase(Ease.InCirc);
  30. }
  31.  
« Last Edit: November 04, 2014, 06:02:07 AM by Genhain »

Genhain

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 38
    • View Profile
Re: Transforming points from a Scrollview for relative positioning
« Reply #1 on: November 04, 2014, 06:01:45 AM »
Fixed it.

  1. int count = GetChildList().Count;
  2.  
  3. //Grids local position
  4. Vector3 lastElementInGridPos = transform.localPosition;
  5. lastElementInGridPos.x += (count*cellWidth);//add x equal to amount of elements * set cellwidth
  6. lastElementInGridPos.x -= (transform.localPosition.x+416);//adjust for scroll view offset
  7.  
  8. Vector3 EndValue = transform.TransformPoint(lastElementInGridPos);
  9.