Ejemplo n.º 1
0
        public void SetLifetime(float newLifetime)
        {
            lifetimeInSeconds = newLifetime;
            PooledComponent component = base.gameObject.GetComponent <PooledComponent>();

            if (component != null && component.IsSpawned)
            {
                CancelInvoke("KillGameObject");
                Invoke("KillGameObject", lifetimeInSeconds);
            }
        }
Ejemplo 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);
     }
 }
Ejemplo n.º 3
0
        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);
            }
        }