Author Topic: Children of Panel with UIGrid Not lining up to the top  (Read 2936 times)

UndercoverDesigns

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 7
    • View Profile
Children of Panel with UIGrid Not lining up to the top
« on: June 24, 2014, 01:30:47 PM »
I have a UIPanel with an attached UIGrid script.  I can add children to the panel exactly as I would expect, except that the first item adds about halfway down the panel:


My code:
  1.  public void OnAddPlayer()
  2.     {
  3.         Debug.Log("Add Player");        
  4.  
  5.         if (Players.Count < 6)
  6.         {
  7.             GameObject PlayerObject = NGUITools.AddChild(ButtonHost as GameObject, ListItemPrefab);
  8.             PlayerObject.name = "Player" + Players.Count;
  9.             PlayerObject.transform.FindChild("PlayerName").GetComponent<UILabel>().text = PlayerObject.name;
  10.  
  11.             UISprite PlayerButtonSprite = PlayerObject.GetComponent<UISprite>();
  12.  
  13.             PlayerButtonSprite.leftAnchor.target = ButtonHost.transform;
  14.             PlayerButtonSprite.leftAnchor.absolute = 10;
  15.  
  16.             PlayerButtonSprite.rightAnchor.target = ButtonHost.transform;
  17.             PlayerButtonSprite.rightAnchor.absolute = -10;
  18.  
  19.             PlayerButtonSprite.ResetAnchors();
  20.             PlayerButtonSprite.UpdateAnchors();
  21.  
  22.             Player ThisPlayer = PlayerObject.GetComponent<Player>();            
  23.             Players.Add(ThisPlayer);
  24.                        
  25.             ButtonHost.GetComponent<UIGrid>().Reposition();
  26.         }
  27.     }

I would expect the player buttons to start showing up at the top of the UIPanel, which is anchored just under the "Players" label.  How do I make this be the case?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Children of Panel with UIGrid Not lining up to the top
« Reply #1 on: June 25, 2014, 06:14:37 AM »
The items will show up at the panel's origin point, which depends on where the transform gizmo is relative to the clipping. Center is the default location, and it looks to be where your items appear.

Call ResetPosition() on the panel (assuming you set the panel's content origin to be top).

UndercoverDesigns

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: Children of Panel with UIGrid Not lining up to the top
« Reply #2 on: June 27, 2014, 01:31:34 PM »
I'm not sure how to set the origin point, though your explanation makes sense.

I don't see any sort of Origin property in the UIPanel component:



Gabe

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Children of Panel with UIGrid Not lining up to the top
« Reply #3 on: June 27, 2014, 02:09:44 PM »
It's set on the scroll view component.

UndercoverDesigns

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: Children of Panel with UIGrid Not lining up to the top
« Reply #4 on: July 07, 2014, 02:02:30 PM »
Is there no way to line items up to the top of a UIGrid without a UIScroll View?  My grid will never contain enough items to scroll.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Children of Panel with UIGrid Not lining up to the top
« Reply #5 on: July 08, 2014, 11:01:31 AM »
Well, sure... Just move the grid game object.