public CachingCreateDestroyItemsBehavior(ICreateDestroyItems createDestroyInfo, int initialPoolSize) { _createDestroyImpl = createDestroyInfo; // Instantiate the starting pool of GameObjects for (var i = 0; i < initialPoolSize; i++) { var newGameObject = InstantiateItem(); // These item GameObjects haven't been asigned yet so hide them newGameObject.SetActive(false); _gameObjectsCached.Add(newGameObject); } }
void Awake() { if (_destroyChildrenOnAwake) { for (var i = transform.childCount - 1; i >= 0; i--) { var cg = transform.GetChild(i).gameObject; if (cg == ItemTemplate) { cg.SetActive(false); } else if (_items.All(c => c.Control != cg)) { Destroy(cg); } } } // Caching items behavior doesn't support the use of an ItemTemplateSelector if (ItemTemplateSelector != null) { Debug.LogWarning("ItemsControl's caching behavior doesn't support an ItemTemplateSelector"); _cacheGameObjects = false; } if (_cacheGameObjects == true) { // Pass in the default behavior and the initial GameObject pool size _createDetroyItemsBehavior = new CachingCreateDestroyItemsBehavior(new DefaultCreateDestroyItemsBehavior(transform, _itemTemplate, _itemTemplateSelector), _cacheGameObjectPoolSize); } else { // Pass in the item parent transform, template, and selector _createDetroyItemsBehavior = new DefaultCreateDestroyItemsBehavior(transform, _itemTemplate, _itemTemplateSelector); } }