Author Topic: Moving grid into UI Root makes entries enormous  (Read 6196 times)

harrisonpink

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile
Moving grid into UI Root makes entries enormous
« on: March 25, 2015, 01:45:21 AM »
I've been trying to get a scrollable list of trading cards working over in another thread (http://www.tasharen.com/forum/index.php?topic=12518.0). The list is generating successfully and being alphabetized successfully, but if add a UIPanel or I make the gameobject with the UIGrid component a child of the UI Root game object, when it generates the list, the entries are HUGE. Like, so large I thought they were just invisible at first, but scolling out far enough revealed they existed, but were HUUUUUUGE.

Any help would be appreciated.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Moving grid into UI Root makes entries enormous
« Reply #1 on: March 25, 2015, 12:08:35 PM »
Use NGUITools.AddChild instead of Instantiate.

harrisonpink

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile
Re: Moving grid into UI Root makes entries enormous
« Reply #2 on: March 25, 2015, 01:24:06 PM »
I currently am. My code is:

  1. UIGrid tempGrid = tempLibrary.GetComponent<UIGrid>();
  2.        
  3.         foreach (Card pickedCard in myCardCollection.cards)
  4.         {
  5.             GameObject go = NGUITools.AddChild(tempGrid.gameObject, tempEntry);
  6.            
  7.             UILabel tempEntryLabel = go.transform.FindChild("Card Label").GetComponent<UILabel>();
  8.            
  9.             go.transform.FindChild("Card Label").GetComponent<UILabel>().text = pickedCard.name;
  10.            
  11.             tempGrid.Reposition();
  12.         }

devomage

  • Sr. Member
  • ****
  • Thank You
  • -Given: 7
  • -Receive: 67
  • Posts: 250
    • View Profile
Re: Moving grid into UI Root makes entries enormous
« Reply #3 on: March 25, 2015, 02:40:16 PM »
create the panel and create the grid as a child.  these both should have a scale of (1, 1, 1)

also, make sure the scale of your prefab is (1, 1, 1).    try to fix the problem visually in play mode so you know what to code...

harrisonpink

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile
Re: Moving grid into UI Root makes entries enormous
« Reply #4 on: March 25, 2015, 07:27:15 PM »
Will try that.

I've tried to scale it down in Play mode, but as soon as I grab a corner handle and try to scale the panel, it flies off into space. It's very odd

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Moving grid into UI Root makes entries enormous
« Reply #5 on: March 27, 2015, 10:47:52 PM »
Also note that the grid's Reposition() should be called after all children have been instantiated, not every time you add a new child.

harrisonpink

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile
Re: Moving grid into UI Root makes entries enormous
« Reply #6 on: March 30, 2015, 11:38:23 PM »
I've changed my code to:

  1. UIGrid tempGrid = tempLibrary.GetComponent<UIGrid>();
  2.                
  3.                 foreach (Card pickedCard in myCardCollection.cards)
  4.                 {
  5.                         GameObject go = NGUITools.AddChild(tempGrid.gameObject, tempEntry);
  6.                        
  7.                         UILabel tempEntryLabel = go.transform.FindChild("Card Label").GetComponent<UILabel>();
  8.                        
  9.                         go.transform.FindChild("Card Label").GetComponent<UILabel>().text = pickedCard.name;
  10.                         go.name = pickedCard.name;
  11.                        
  12.                        
  13.                 }
  14.                
  15.                 tempGrid.Reposition();

and I've changed the hierarchy of game objects so the panel has a child game object with the UIGrid script on it. However, it's still generating the grid entries way too large. This only started happening once I started using a Panel for the scrollview.

Would it be worthwhile to zip up the project and upload it for someone to take a look at? I'm sort of at my limit of understanding how NGUI works here.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Moving grid into UI Root makes entries enormous
« Reply #7 on: April 01, 2015, 11:17:41 PM »
Assuming "tempEntry" is actually a prefab, not some object that's already in the scene, what you're doing is fine. NGUITools.AddChild forcefully resets the instantiated object's scale to (1, 1, 1), however it won't do anything for scales of objects leading up to it, or its children.

Check the scales of objects leading up to your instantiated items.