static GameObjectPoolGroup GetOrCreateGroup(string groupName) { GameObjectPoolGroup group; if (!_poolGroups.TryGetValue(groupName, out group)) { // create group if (_despawnParent == null) { // create base object to hold all despawned objects _despawnParent = new GameObject("Pooled Objects").transform; GameObject.DontDestroyOnLoad(_despawnParent.gameObject); } Transform groupParent = new GameObject(groupName).transform; groupParent.SetParent(_despawnParent); group = new GameObjectPoolGroup(groupName, groupParent); _poolGroups[groupName] = group; } return(group); }
/// <summary> /// Return the pool for the given source object, or creates it (with an optional overridden key) if it doesn't exist /// </summary> /// <param name="sourceObject"></param> /// <param name="overrideObjectKey"></param> /// <param name="poolGroupKey"></param> /// <param name="initialPoolSize"></param> /// <returns></returns> public static GameObjectPool GetOrCreatePoolForObject(GameObject sourceObject, string overrideObjectKey = "", string poolGroupKey = _DEFAULT_POOL_GROUP_KEY, int initialPoolSize = _DEFAULT_INITIAL_POOL_SIZE) { GameObjectPoolGroup group = GetOrCreateGroup(poolGroupKey); return(group.GetOrCreatePoolForObject(sourceObject, overrideObjectKey, initialPoolSize)); }