Author Topic: Way to duplicate widget  (Read 2784 times)

Keratos

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Way to duplicate widget
« 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"));

Boogscraft

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 1
    • View Profile
Re: Way to duplicate widget
« Reply #1 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.  

Keratos

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Way to duplicate widget
« Reply #2 on: July 28, 2014, 09:38:17 AM »
Yup, when example button is destroyed none of subgameobjects works.