Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: germancons on April 23, 2013, 05:57:41 PM

Title: Dynamically created item List in a panel is not being displayed.
Post by: germancons on April 23, 2013, 05:57:41 PM
Im creating an item List by creating GameObjects under a panel and then using UIGrid to position them using this code.



  1.        
  2.         public GameObject SliderItem; //This is a prefab with the slider item template
  3.         public GameObject Slider; //This is a draggable panel with an UIGrid component in it.
  4.  
  5. ....void PopulateItemList(){
  6.                         for (int c=0;c<GameManager.Instance.numberOfWeapons;c++) {
  7.                         GameObject go=(GameObject) Instantiate(SliderItem);
  8.                         WeaponItem wi=go.GetComponent<WeaponItem>();
  9.                         wi.SetData(c);
  10.                         go.transform.parent=Slider.transform;
  11.                         go.transform.localScale=new Vector3(1,1,1);
  12.                         //Send data to Slider
  13.                 }
  14.                 Slider.SendMessage("Reposition");
  15. }
  16.  


Item setting data code;


  1.         public void SetData(int pid){
  2.                 id=pid;
  3.                 name=GameManager.Instance.GetWeaponName(id);
  4.                 level=1;
  5.                 price=GameManager.Instance.GetWeaponPrice(id);
  6.                 itemLabel.text=name+" L"+level;
  7.                 itemIcon.spriteName=GameManager.Instance.GetWeaponIcon(id);
  8.         }
  9.  
   

It does create and position them currently, but they are not being shown in game, the panel is completely item in the game camera.

Sorry If this has been asked before I looked around
Title: Re: Dynamically created item List in a panel is not being displayed.
Post by: ArenMook on April 24, 2013, 12:35:24 AM
After changing the parent like that you need to tell the widgets that their parent has changed. There have been many such topics here.