public void SetLifetime(float newLifetime) { lifetimeInSeconds = newLifetime; PooledComponent component = base.gameObject.GetComponent <PooledComponent>(); if (component != null && component.IsSpawned) { CancelInvoke("KillGameObject"); Invoke("KillGameObject", lifetimeInSeconds); } }
protected void OnObjectAllocated(GameObject allocatedObject, int count) { if (allocatedObject != null) { PooledComponent pooledComponent = allocatedObject.AddComponent <PooledComponent>(); pooledComponent.PrefabName = PrefabToInstance.name; pooledComponent.Pool = this; allocatedObject.name = $"[{count - 1}]{PrefabToInstance.name} (Pooled)"; SetObjectTransform(allocatedObject, base.gameObject.transform); allocatedObject.SetActive(value: false); } }
private void KillGameObject() { GameObjectPool gameObjectPool = null; PooledComponent component = base.gameObject.GetComponent <PooledComponent>(); if (component != null) { gameObjectPool = Singleton <GameObjectPoolManager> .Instance.GetPool(component.PrefabName); } if (gameObjectPool != null) { gameObjectPool.Unspawn(base.gameObject); } else { Object.Destroy(base.gameObject); } }