1. I opened the Example 7.
2. Deleted all items except the first one.
3. Made a prefab out of the first item.
4. Attached this script to the grid:
using UnityEngine;
public class Test : MonoBehaviour
{
public GameObject prefab;
void Update ()
{
if (Input.GetKeyDown(KeyCode.C))
{
GameObject go = NGUITools.AddChild(gameObject, prefab);
go.BroadcastMessage("CreatePanel");
GetComponent<UIGrid>().Reposition();
GetComponentInParent<UIScrollView>().ResetPosition();
}
}
}
5. Referenced the prefab from #3 on the script as the "prefab".
6. Hit Play(), Press 'C' a few times. items get added, scroll view gets updated, scroll bar gets updated. Everything works as expected.