Esempio n. 1
0
    /// <summary>
    /// Takes an object from the Pool based on prefab
    /// </summary>
    /// <param name="prefabName"></param>
    /// <returns>A Tile</returns>
    public static Tile GetFromPool(GameObject prefab)
    {
        // Get the right queue from the Pool
        Queue <Tile> queue = instance.GetQueue(prefab.name);

        Tile tile;

        // Dequeue an object, if the queue is not empty.
        if (queue.Count > 0)
        {
            tile = queue.Dequeue();
        }
        // Create a new object, the queue was empty.
        else
        {
            tile = instance.GetNewTile(prefab);
        }

        // Set the game object to be active in the scene.
        tile.gameObject.SetActive(true);
        return(tile);
    }