Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: sndwav on June 03, 2013, 07:46:00 AM

Title: a slow-down when creating a grid with many children
Post by: sndwav on June 03, 2013, 07:46:00 AM
Hello,
I'm creating UIGrids programmatically with many children inside (around 60),
but I'm experiencing a slow-down during the creation of these large grids on mobile devices (iPhone4, iPad2),
which becomes apparent if there are any animations running while I create these grids.

Here is a simplified version of the code I use to create a grid and its children:

  1. GameObject containerGO = NGUITools.AddChild(gameObject);
  2. containerGO.name = "containerGrid";
  3. grid = containerGO.AddComponent<UIGrid>();
  4. grid.sorted = true;
  5.  
  6. for (int i = 0; i < numOfSpritesToSetup; i++) {
  7.         string spriteName = "someSpriteName";
  8.         UISprite ui = NGUITools.AddSprite(containerGO, spritesAtlas, spriteName);
  9.         ui.gameObject.name = sortedObjectName;   // "child0001", "child0002"...
  10.         ui.transform.localScale = size;
  11.         ui.transform.localPosition = pos;
  12. }

The above code is in a script which is attached to several Game Objects (UIPanels, no clipping).
Here is my hierarchy (after the code execution):

- Main Panel
-- Panel1
--- ContainerGrid
----- Child0001
----- Child0002...
----- Child0060
-- Panel2
--- ContainerGrid
----- Child0001
----- Child0002...
----- Child0060
-- Panel3
--- ContainerGrid
----- Child0001
----- Child0002...
----- Child0060


So I was wondering if this is the optimal way to programmatically create a grid filled with many children?
Is there a way to minimize the slow-down during the creation or grids? (I avoided using any GetComponents).

Thanks!
Title: Re: a slow-down when creating a grid with many children
Post by: ArenMook on June 03, 2013, 09:45:08 AM
Since you are adding children yourself, they are already going to be sorted in the order that you add them in, so sorting should not be necessary. Sorting is mainly for re-arranging stuff created at edit time.