Tasharen Entertainment Forum

Support => Misc Archive => Topic started by: Keratos on July 23, 2014, 02:29:49 PM

Title: Way to duplicate widget
Post by: Keratos on July 23, 2014, 02:29:49 PM
Hi guys, I'm looking for a way to duplicate Example buttons in grid and modify them. It's quite easy to do with NGUITools.AddChild but after that i would also like to remove the example button from grid, which seems to be impossible using this way because it breakes all his clones. Thanks in advance for your help.

My currently not working way:

  1.                 int gameId = 0;
  2.                 foreach (Game game in PlayerInfo.currentGames.games) {
  3.                         GameObject nButton = NGUITools.AddChild (GameObject.Find ("ShopGrid"), GameObject.Find ("GameButtonExample"));
  4.                         nButton.name = "GameButton"+gameId;
  5.                         foreach (UIWidget t in nButton.GetComponentsInChildren<UIWidget>()) {
  6.                                 if (t.name != "Background")
  7.                                         t.alpha = 0;
  8.                         }
  9.                         gameId++;
  10.                 }
  11.                 Destroy(GameObject.Find ("GameButtonExample"));
Title: Re: Way to duplicate widget
Post by: Boogscraft on July 26, 2014, 05:01:40 PM
Have you tried defining the Example Button GameObject before the loop and using that to remove it?
  1. int gameId = 0;
  2. GameObject exampleButton = GameObject.Find ("GameButtonExample")
  3. foreach (Game game in PlayerInfo.currentGames.games) {
  4.       GameObject nButton = NGUITools.AddChild (GameObject.Find ("ShopGrid"), exampleButton );
  5.       nButton.name = "GameButton"+gameId;
  6.       foreach (UIWidget t in nButton.GetComponentsInChildren<UIWidget>()) {
  7.           if (t.name != "Background")
  8.              t.alpha = 0;
  9.       }
  10.       gameId++;
  11. }
  12. Destroy(exampleButton);
  13.  
Title: Re: Way to duplicate widget
Post by: Keratos on July 28, 2014, 09:38:17 AM
Yup, when example button is destroyed none of subgameobjects works.