void UpdateHeatSourceList () {
// To make this completely dynamic, it should probably loop through any existing
// children and remove them. We'll save that for later
cellCount = 0;
foreach (HeatSource _hs in HeatSource.mList) {
if (_hs.CompareTag("Player")) continue; // we don't want the player included in the list
// Use .AddChild instead of manually adding, parenting, etc
GameObject go = NGUITools.AddChild(_grid.gameObject,heatSourcePrefab);
go.name = _hs.name;
cellCount++;
mTargets.Add(go);
}
// Recalculate the grid since we just added a bunch of objects
_grid.Reposition();
// Calculate the new height of our scrollview and clamp it to a maximum
float newHeight = Mathf.Clamp((cellCount * prefabHeight),0f,maxPanelHeight);
Debug.Log("New Height: " + newHeight.ToString("F0") + " for " + cellCount.ToString() + " targets");
// Now first we reset the clipOffset
// See calculation below
float yOffset = (newHeight - prefabHeight) * 0.5f;
scrollPanelView
.clipOffset = new Vector2
(0,
-yOffset
);
// Now we reset the baseClipRegion to the new height
scrollPanelView
.baseClipRegion = new Vector4
(0,
0,panelWidth,newHeight
);
}