Hey everyone, I just wanted to share a minor mod I made to the UI Grid that would enable the grid to function like the notification window of a Zynga game - namely populating from the bottom up. Basically I added a bool for inverting the direction, then within the reposition code, i use the bool to determine a -1 or 1 direction to add to (1 mean inverted, -1 is the original)
So here goes:
public class UIGrid : MonoBehaviour
{
.
.
.
public bool invertDirection = false;
.
.
.
/// <summary>
/// Recalculate the position of all elements within the grid, sorting them alphabetically if necessary.
/// </summary>
public void Reposition ()
{
if (!mStarted)
{
repositionNow = true;
return;
}
Transform myTrans = transform;
int x = 0;
int y = 0;
int direction = invertDirection ? 1 : -1;
if (sorted)
{
List
<Transform
> list
= new List
<Transform
>();
for (int i = 0; i < myTrans.childCount; ++i)
{
Transform t = myTrans.GetChild(i);
if (t) list.Add(t);
}
list.Sort(SortByName);
for (int i = 0, imax = list.Count; i < imax; ++i)
{
Transform t = list[i];
if (!t.gameObject.active && hideInactive) continue;
float depth = t.localPosition.z;
t.localPosition = (arrangement == Arrangement.Horizontal) ?
new Vector3
(cellWidth
* x, direction
* cellHeight
* y, depth
) : new Vector3
(cellWidth
* y, direction
* cellHeight
* x, depth
);
if (++x >= maxPerLine && maxPerLine > 0)
{
x = 0;
++y;
}
}
}
else
{
for (int i = 0; i < myTrans.childCount; ++i)
{
Transform t = myTrans.GetChild(i);
if (!t.gameObject.active && hideInactive) continue;
float depth = t.localPosition.z;
t.localPosition = (arrangement == Arrangement.Horizontal) ?
new Vector3
(cellWidth
* x, direction
* cellHeight
* y, depth
) : new Vector3
(cellWidth
* y, direction
* cellHeight
* x, depth
);
if (++x >= maxPerLine && maxPerLine > 0)
{
x = 0;
++y;
}
}
}
UIDraggablePanel drag = NGUITools.FindInParents<UIDraggablePanel>(gameObject);
if (drag != null) drag.UpdateScrollbars(true);
}
}