public void alignItemsInColumnsWithArray(int[] rows)
{ int height = -5;
int row = 0, rowHeight = 0, columnsOccupied = 0, rowColumns;
var enumerator = _children.GetEnumerator();
while (enumerator.MoveNext()) {
CCMenuItem item = (CCMenuItem)enumerator.Current;
NSUtils.Assert( row < rows.Length, "Too many menu items for the amount of rows/columns.");
rowColumns = rows[row];
NSUtils.Assert( rowColumns!=0, "Can't have zero columns on a row");
rowHeight = Mathf.RoundToInt(Mathf.Max(rowHeight, item.contentSize.y));
++columnsOccupied;
if(columnsOccupied >= rowColumns) {
height += rowHeight + 5;
columnsOccupied = 0;
rowHeight = 0;
++row;
}
}
NSUtils.Assert( columnsOccupied==0, "Too many rows/columns for available menu items." );
Vector2 winSize = CCDirector.sharedDirector.winSize;
row = 0; rowHeight = 0; rowColumns = 0;
float w=0, x=0, y = height / 2;
enumerator = _children.GetEnumerator();
while (enumerator.MoveNext()) {
CCMenuItem item = (CCMenuItem)enumerator.Current;
if(rowColumns == 0) {
rowColumns = rows[row];
w = winSize.x / (1 + rowColumns);
x = w;
}
Vector2 itemSize = item.contentSize;
rowHeight = Mathf.RoundToInt(Mathf.Max(rowHeight, itemSize.y));
item.position= new Vector2(x - winSize.x / 2,
y - itemSize.y / 2);
x += w;
++columnsOccupied;
if(columnsOccupied >= rowColumns) {
y -= rowHeight + 5;
columnsOccupied = 0;
rowColumns = 0;
rowHeight = 0;
++row;
}
}
}