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 = component.Pool;
            }
            if (gameObjectPool != null)
            {
                gameObjectPool.Unspawn(base.gameObject);
            }
            else
            {
                Object.Destroy(base.gameObject);
            }
        }