/// <summary> /// Get the pool holding the specified object. /// </summary> public FeatherPool GetPool(int objectID) { FeatherPool featherPool = null; PoolDictionary.TryGetValue(objectID, out featherPool); return(featherPool); }
// ---------------------------------------------------------------------------------------------------- #endregion #region Pool Handling // ---------------------------------------------------------------------------------------------------- /// <summary> /// Get the pool holding the specified object. /// </summary> public FeatherPool GetPool(string objectName) { FeatherPool featherPool = null; NamedPoolDictionary.TryGetValue(objectName, out featherPool); return(featherPool); }
/// <summary> /// Despawns the specified object. /// </summary> /// <param name="poolObjectId">The object to despawn.</param> public void Despawn(int poolObjectId) { if (!PoolDictionary.ContainsKey(poolObjectId)) { Debug.LogWarning(String.Format("The object ID '{0}' passed to Despawn is not in the FeatherPool. Not despawning.", poolObjectId)); return; } // Fetch PoolData containing FeatherPool and FeatherPoolGroup FeatherPool featherPool = PoolDictionary[poolObjectId]; // Despawn object featherPool.Despawn(poolObjectId); //FeatherLogManager.LogNotice(Instance.gameObject, String.Format("FeatherPool despawned '{0}' at {1}", itemName, Time.time), poolObject.gameObject); }
/// <summary> /// Adds the new pool. /// </summary> /// <param name="entry">The pool entry.</param> private void AddNewPool(FeatherPoolEntry entry) { // Check if object already in a pool if (FeatherPoolManager.Instance.Contains(entry.PrefabObject)) { Debug.LogError(String.Format("An instance of '<b>{0}</b>' already exists in a Pool, skipping object.", entry.PrefabObject.name)); return; } GameObject newPool = new GameObject(String.Format("Pool ({0})", entry.PrefabObject.name)); FeatherPool featherPool = newPool.AddComponent <FeatherPool>(); featherPool.transform.SetParent(this.transform); featherPool.PoolEntry = entry; featherPool.PoolEntry.ApplySettings(this.Settings); featherPool.Group = this; featherPool.Initialize(); PoolList.Add(entry.PrefabObject.name, featherPool); FeatherPoolManager.Instance.RegisterPool(featherPool); }
/// <summary> /// Spawns a new instance of a given prefab. /// </summary> public GameObject Spawn(int poolObjectId, Vector3 position, Quaternion rotation, Vector3 scale) { FeatherPool itemPool = null; PoolDictionary.TryGetValue(poolObjectId, out itemPool); if (itemPool == null) { Debug.LogError(String.Format("The object ID '{0}' passed to spawn is not in the FeatherPool.", poolObjectId)); return(null); } // Create a new instance GameObject poolInstance = itemPool.Spawn(position, rotation, scale); if (poolInstance == null) { Debug.LogWarning(String.Format("One or more of the prefab ID '{0}' in FeatherPool has been destroyed. You should never destroy objects in the Pool. Despawn instead. Not spawning anything for this call.", poolObjectId)); return(null); } return(poolInstance); }
/// <summary> /// Registers a new pool. /// </summary> /// <param name="featherPool">The pool.</param> public void RegisterPool(FeatherPool featherPool) { //Debug.LogWarning(String.Format("Registering Pool '{0}'.", featherPool.name), featherPool.gameObject); int itemId = featherPool.PrefabID; // Check for duplicates if (PoolDictionary.ContainsKey(itemId)) { Debug.LogError(String.Format("An instance of '<b>{0}</b>' already exists in Pool '<b>{1}</b>', skipping instance.", featherPool.PrefabName, featherPool.name)); return; } PoolDictionary.Add(featherPool.PrefabID, featherPool); NamedPoolDictionary.Add(featherPool.PrefabName, featherPool); #if UNITY_EDITOR PoolListReadOnly.Add(featherPool); #endif //Debug.LogWarning(String.Format("Registered Pool '{0}' with {1} Pool Items.", featherPool.name, featherPool.TotalInstances), featherPool.gameObject); }
/// <summary> /// Despawns the specified object. /// </summary> /// <param name="poolObject">The object to despawn.</param> public void Despawn(GameObject poolObject) { if (poolObject == null) { Debug.LogWarning("No Transform passed to Despawn method."); return; } FeatherPool featherPool = null; NamedPoolDictionary.TryGetValue(poolObject.name, out featherPool); if (featherPool == null) { Debug.LogWarning(String.Format("The Transform '{0}' passed to Despawn is not in the FeatherPool. Not despawning.", poolObject.name)); return; } // Despawn object featherPool.Despawn(poolObject); //FeatherLogManager.LogNotice(Instance.gameObject, String.Format("FeatherPool despawned '{0}' at {1}", itemName, Time.time), poolObject.gameObject); }
/// <summary> /// Registers a new pool instance. /// </summary> public void RegisterInstance(GameObject poolObject, FeatherPool pool) { PoolDictionary.Add(poolObject.GetInstanceID(), pool); }
// ---------------------------------------------------------------------------------------------------- #endregion #region Initialization // ---------------------------------------------------------------------------------------------------- /// <summary> /// Called upon starting this behavior. /// </summary> private void Start() { this.poolGroup = FeatherPoolManager.Instance.GetPool(this.name); this.hasPool = poolGroup != null; }