public void SetLifetime(float newLifetime)
        {
            lifetimeInSeconds = newLifetime;
            PooledComponent component = base.gameObject.GetComponent <PooledComponent>();

            if (component != null && component.IsSpawned)
            {
                CancelInvoke("killGameObject");
                Invoke("killGameObject", lifetimeInSeconds);
            }
        }
Esempio n. 2
0
 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 = component.Pool;
            }
            if (gameObjectPool != null)
            {
                gameObjectPool.Unspawn(base.gameObject);
            }
            else
            {
                Object.Destroy(base.gameObject);
            }
        }