Beispiel #1
0
    public bool AddToPool(int objectIndex, int amount)
    {
        if (objectIndex > PoolableObjects.Length)
        {
            return(false);
        }

        // Check for first
        if (!objectPool.ContainsKey(objectIndex))
        {
            objectPool[objectIndex] = new Queue <GameObject>();
        }

        for (var i = 0; i < amount; i++)
        {
            GameObject newObject = Instantiate(PoolableObjects[objectIndex]);
            Assets.scripts.IPoolable poolable = newObject.GetComponent <Assets.scripts.IPoolable>();

            // Check if interface exists
            if (poolable == null)
            {
                return(false);
            }

            poolable.ReturnToPool();
            newObject.SetActive(false);
            objectPool[objectIndex].Enqueue(newObject);
        }

        return(true);
    }
Beispiel #2
0
    public bool ReturnToPool(int objectIndex, GameObject gameObject)
    {
        if (objectIndex > PoolableObjects.Length)
        {
            return(false);
        }


        // No pool for the object
        if (!objectPool.ContainsKey(objectIndex))
        {
            return(false);
        }

        Assets.scripts.IPoolable poolable = gameObject.GetComponent <Assets.scripts.IPoolable>();
        poolable.ReturnToPool();
        gameObject.SetActive(false);
        objectPool[objectIndex].Enqueue(gameObject);

        return(true);
    }