Esempio n. 1
0
 public SpawnObserver(ObjectsEnums tag, Vector3 pos, Quaternion rot, ObjectPooler pool)
 {
     prefabTag     = tag;
     spawnPosition = pos;
     spawnRotation = rot;
     pooler        = pool;
 }
Esempio n. 2
0
    /// <summary>
    /// method for spawning one object from pool
    /// </summary>
    /// <param name="tag"> object tag to spawn </param>
    /// <param name="position"> spawning position </param>
    /// <param name="rotation"> spawning rotation </param>
    /// <returns> gameobject from pool based on selected tag </returns>
    public GameObject SpawnFromPool(ObjectsEnums tag, Vector3 position, Quaternion rotation)
    {
        if (!poolDictionary.ContainsKey(tag))
        {
            Debug.Log("ObjectPool doesn't contains object with " + tag + " tag.");
            return(null);
        }

        //if it is last item, extend pool by extend factor
        if (poolDictionary[tag].Count == 1)
        {
            ExtendPool(extendFactor, poolDictionary[tag], poolDictionary[tag].Dequeue());
        }

        GameObject objectToSpawn = poolDictionary[tag].Dequeue();

        objectToSpawn.SetActive(true);
        objectToSpawn.transform.position = position;
        objectToSpawn.transform.rotation = rotation;

        return(objectToSpawn);
    }