Skip to content

Instantly share code, notes, and snippets.

@unity3dcollege
Created May 11, 2017 21:07
Show Gist options
  • Save unity3dcollege/506d10212a57f506195ad93f666b7dbe to your computer and use it in GitHub Desktop.
Save unity3dcollege/506d10212a57f506195ad93f666b7dbe to your computer and use it in GitHub Desktop.
private void Initialize(IPoolable poolablePrefab, int initialSize = DEFUALT_POOL_SIZE)
{
this.prefab = (poolablePrefab as Component).gameObject;
for (int i = 0; i < initialSize; i++)
{
var pooledObject = (Instantiate(this.prefab) as GameObject).GetComponent<IPoolable>();
(pooledObject as Component).gameObject.name += " " + i;
pooledObject.OnDestroyEvent += () => AddObjectToAvailable(pooledObject);
(pooledObject as Component).gameObject.SetActive(false);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment