Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: UndercoverDesigns on June 24, 2014, 01:30:47 PM

Title: Children of Panel with UIGrid Not lining up to the top
Post by: UndercoverDesigns 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:
(http://i.imgur.com/lSnMy2C.png)

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?
Title: Re: Children of Panel with UIGrid Not lining up to the top
Post by: ArenMook 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).
Title: Re: Children of Panel with UIGrid Not lining up to the top
Post by: UndercoverDesigns 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:

(http://i.imgur.com/GvQkdVA.png)

Gabe
Title: Re: Children of Panel with UIGrid Not lining up to the top
Post by: ArenMook on June 27, 2014, 02:09:44 PM
It's set on the scroll view component.
Title: Re: Children of Panel with UIGrid Not lining up to the top
Post by: UndercoverDesigns 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.
Title: Re: Children of Panel with UIGrid Not lining up to the top
Post by: ArenMook on July 08, 2014, 11:01:31 AM
Well, sure... Just move the grid game object.