Hi! I am trying to use pools of ui prefab elements to avoid constant instantiation and destroy of objects. Everything works fine,
i am spawning elements to table which is under scrollview, i also modified NGUITools.AddChild method (rather made another one) that
doesn't create gameobject but uses one that is passed (spawned beforehand).
here is the modified method:
static public GameObject AddChild(this GameObject parent, GameObject prefab)
{
if (prefab != null && parent != null)
{
var t = prefab.transform;
t.parent = parent.transform;
t.localPosition = Vector3.zero;
t.localRotation = Quaternion.identity;
t.localScale = Vector3.one;
prefab.layer = parent.layer;
}
return prefab;
}
not much going on here.
here is the method i am using to spawn elements to table:
...
for (var i = 0; i < weaponConfigs.Length; i++)
{
var pooledWeaponItem = Game.Pools.GetPool(PoolType.UI).Spawn(Item.transform, Vector3.zero, Quaternion.identity);
var item = UIExtensions.AddChild(_table.gameObject, pooledWeaponItem.gameObject);
var controller = item.GetComponent<WeaponItem>();
....
}
and everything works fine but the problem is when element that was in the pool and need to be reused is spawned to table but is not visible (this happens
depending on how much elements are in the pool...it happens earlier if there is less elements in the pool)
I figured out when i disable and enable again sprite it appears visible and then when i disable and enable gameobject of the spawned item itself it appears
in the table and starts working.
i tried
_scroll.panel.SetDirty();
_scroll.panel.RebuildAllDrawCalls();
but it doesn't work, also i tried
different combinations of
NGUITools.SetActive for spawned element but it doesn't work...what seems to be the problem? Any ideas?
thanks!