public void InitializePool(K key, GameObject prefab, int size) { if (ResourceDomain.ContainsPool(key)) { Debug.LogWarning("ZanzoObjectManager::InitializePool(): Cannot initialize pool, one is already present for key: " + key); return; } if (size <= 0) { Debug.LogWarning("ZanzoObjectManager::InitializePool(): pool size must be greater than zero: " + size); return; } ResourceDomain.CreatePool(key); for (int cnt = 0; cnt < size; ++cnt) { var obj = Instantiate(prefab); obj.transform.parent = transform; var cmp = obj.GetComponent <V>(); cmp.Initialize(); InitializeResource(cmp); cmp.Hide(); // Don't add event handlers until after the object has been initialized. // This allows the object to either start activated / deactivated without // unnecessarily notifying those event listeners (e.g. this). cmp.Activated += OnResourceActivated; cmp.Deactivated += OnResourceDeactivated; ResourceDomain.AddResource(key, cmp); } }
public V Retain(K key) { var res = ResourceDomain.Retain(key); res.Reinitialize(); return(res); }
public void Release(V res) { if (res.State.IsActive()) { Debug.LogWarning("ZanzoObjectManager::OnResourceReleased() - releasing an object without deactivating it: " + res); _activeResources.Remove(res); } ResourceDomain.Release(res); }
// +----------------------------------------------------------------------- // + Class Methods // +----------------------------------------------------------------------- // +--------------------------------------------------- // + C'tor & Init Methods // +--------------------------------------------------- // public ZanzoObjectManager<K, V> : ZanzoObject where K : System.Enum where V : ZanzoObject public ZanzoObjectManager() { ResourceDomain = new ResourceDomain <K, V>(); }