Author Topic: Trying to populate a draggable list by code yields to giant Content  (Read 2946 times)

laurentl

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 188
    • View Profile
    • McDROID
Out of an array I instantiate Draggable Content one by one and parent them under a grid. The grid is under the Draggable Panel.
When I do this process by hand the draggable content lines up properly and preserves its dimensions.
When I do it in Start however the elements are about 100x their size.
It seems I need to trigger some calculation by hand to resize these elements properly, I tried grid.Reposition and it doesn't change a thing.

What's the secret sauce ?

  1.         [System.Serializable]
  2.         public class Decal
  3.         {
  4.                 public string name;
  5.                 public Texture decal;
  6.                 public DraggableButton draggableButton;
  7.         }
  8.        
  9.         public List<Decal> decals;
  10.        
  11.         public DraggableButton buttonPrefab;
  12.         public UIGrid gridParent;
  13.        
  14.         void Start ()
  15.         {
  16.                 for (int i=0; i<decals.Count; i++) {
  17.                         Decal d = decals [i];
  18.                         GameObject dg = (GameObject)Instantiate (buttonPrefab.gameObject);
  19.                         dg.name = "item " + i.ToString ();
  20.                         dg.transform.parent = gridParent.transform;
  21.                         d.draggableButton = dg.GetComponent<DraggableButton> ();
  22.                         // init the butten
  23.                         d.draggableButton.SetDecal (d.decal);
  24.                         d.draggableButton.SetName (d.name);
  25.                         d.draggableButton.SetCallBack (gameObject, "ChooseDecal");
  26.                 }
  27.                 gridParent.Reposition ();
  28.         }


PS: amazing customer service !

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Trying to populate a draggable list by code yields to giant Content
« Reply #1 on: April 03, 2013, 02:57:08 PM »
Never use Instantiate. Use NGUITools.AddChild.

laurentl

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 188
    • View Profile
    • McDROID
Re: Trying to populate a draggable list by code yields to giant Content
« Reply #2 on: April 03, 2013, 03:32:37 PM »
Perfect! simplifies code.

And it seems I still need to
Reposition () the grip and Recenter the UICenterOnChild