/// <summary> /// Destroy all gameObjects in this pool. /// </summary> public void DestroyAll(bool justInited = false) { var iterator = inaccessible.GetEnumerator(); while (iterator.MoveNext()) { if (!justInited) { IPooledObject interfacePooledObject = null; interfacePooledObject = iterator.Current.Value.GetComponent <IPooledObject>(); if (interfacePooledObject == null) { interfacePooledObject = iterator.Current.Value.AddComponent <PooledObject>(); } interfacePooledObject.DestroyPooledObject(); available[iterator.Current.Value] = iterator.Current.Value; iterator.Current.Value.SetActive(false); iterator.Current.Value.transform.parent = poolContainer.transform; } else { if (iterator.Current.Value != null) { GameObject.DestroyImmediate(iterator.Current.Value); } } } inaccessible.Clear(); }
/// <summary> /// Destroy instance of pooled gameObject. /// </summary> /// <param name="gameObject">Deleting gameObject.</param> public void Destroy(GameObject gameObject) { if (inaccessible.ContainsKey(gameObject)) { IPooledObject interfacePooledObject = null; interfacePooledObject = gameObject.GetComponent <IPooledObject>(); if (interfacePooledObject == null) { interfacePooledObject = gameObject.AddComponent <PooledObject>(); } interfacePooledObject.DestroyPooledObject(); inaccessible.Remove(gameObject); available[gameObject] = gameObject; gameObject.SetActive(false); gameObject.transform.parent = poolContainer.transform; } }
/// <summary> /// Destroy instance of pooled Component. /// </summary> /// <param name="Component">Deleting Component.</param> public void Destroy(Component Component) { if (inaccessible == null || Component == null) { return; } if (inaccessible.ContainsKey(Component)) { IPooledObject interfacePooledObject = null; interfacePooledObject = Component.GetComponent <IPooledObject>(); if (interfacePooledObject == null) { interfacePooledObject = Component.gameObject.AddComponent <PooledObject>(); } interfacePooledObject.DestroyPooledObject(); inaccessible.Remove(Component); available[Component] = Component; Component.transform.SetParent(poolContainer.transform); Component.gameObject.SetActive(false); } }