Ejemplo n.º 1
0
    public IPoolableClass Spawn(IPoolableClass prefab, Vector3 WorldPositionInit, Quaternion rotation = default(Quaternion), Transform parent = null)
    {
        IPoolableClass result = null;

        if (cachedObjects.Count > 0)
        {
            result = cachedObjects[0];
            cachedObjects.RemoveAt(0);
        }
        else
        {
            result = Populate(prefab, WorldPositionInit, rotation, parentPool);
        }
        if (parent != null)
        {
            result.transform.SetParent(parent, false);
        }

        result.transform.position = WorldPositionInit;
        // result.transform.gameObject.SetActive(true);

#if UNITY_EDITOR
        CurrentlyUsedFromPool++;
        result.gameObject.name = string.Format(nameOfPrefab, prefab.name, CurrentlyUsedFromPool);
#endif
        result.OnSpawn();
        return(result);
    }
Ejemplo n.º 2
0
 public void PopulateWith(IPoolableClass prefab, Vector3 WorldPositionInit, int amount)
 {
     for (int i = 0; i < amount; i++)
     {
         Spawn(prefab, WorldPositionInit);
     }
 }
Ejemplo n.º 3
0
    private IPoolableClass Populate(IPoolableClass prefab, Vector3 position = default(Vector3),
                                    Quaternion rotation = default(Quaternion), Transform parent = null)
    {
        IPoolableClass go = GameObject.Instantiate(prefab, position, rotation, parent);

        go.transform.position = position;
        return(go);
    }
Ejemplo n.º 4
0
    public void Despawn(IPoolableClass go, bool Reparent = true)
    {
        cachedObjects.Add(go);
#if UNITY_EDITOR
        CurrentlyUsedFromPool--;
        if (CurrentlyUsedFromPool < 0)
        {
            CurrentlyUsedFromPool = 0;
        }
#endif
        go.OnDespawn();
        // go.gameObject.SetActive(false);
        if (Reparent)
        {
            go.transform.SetParent(parentPool, false);
        }
    }