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:
GameObject containerGO = NGUITools.AddChild(gameObject);
containerGO.name = "containerGrid";
grid = containerGO.AddComponent<UIGrid>();
grid.sorted = true;
for (int i = 0; i < numOfSpritesToSetup; i++) {
string spriteName = "someSpriteName";
UISprite ui = NGUITools.AddSprite(containerGO, spritesAtlas, spriteName);
ui.gameObject.name = sortedObjectName; // "child0001", "child0002"...
ui.transform.localScale = size;
ui.transform.localPosition = pos;
}
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...
----- Child0060So 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!