Example #1
0
    public GameObject Spawn(GameObject prefab, Vector3 position, Quaternion rotation, Transform parent = null)
    {
        PoolablePrefabData data;

        if (inactiveList.Count > 0)
        {
            data = inactiveList.Dequeue();
        }
        else
        {
            GameObject newGameObject = GameObject.Instantiate(prefab, position, rotation, parent);

            data = new PoolablePrefabData
            {
                gameObject         = newGameObject,
                poolableComponents = newGameObject.GetComponents <IPoolableComponent>()
            };
        }

        // "Spawn" -------
        data.gameObject.SetActive(true);
        data.gameObject.transform.localPosition = position;
        data.gameObject.transform.localRotation = rotation;

        for (int i = 0; i < data.poolableComponents.Length; i++)
        {
            data.poolableComponents[i].Spawned();
        }

        activeList.Add(data.gameObject, data);
        // ----------------

        return(data.gameObject);
    }
Example #2
0
    public GameObject Spawn(GameObject prefab, Vector3 position, Quaternion rotation)
    {
        PoolablePrefabData data;

        if (_inactiveList.Count > 0)
        {
            data = _inactiveList.Dequeue();
        }
        else
        {
            GameObject newGO = GameObject.Instantiate(prefab, position, rotation) as GameObject;
            data    = new PoolablePrefabData();
            data.go = newGO;
            data.poolableComponents = newGO.GetComponents <IPoolableComponent>();
        }
        data.go.SetActive(true);
        data.go.transform.position = position;
        data.go.transform.rotation = rotation;
        for (int i = 0; i < data.poolableComponents.Length; ++i)
        {
            data.poolableComponents[i].Spawned();
        }
        _activeList.Add(data.go, data);
        return(data.go);
    }
Example #3
0
    public GameObject Spawn(GameObject prefab, Vector3 position, Quaternion rotation)
    {
        PoolablePrefabData data;

        if (_inactiveList.Count > 0)
        {
            data = _inactiveList.Dequeue();
        }
        else
        {
            GameObject newGo = GameObject.Instantiate(prefab, position, rotation) as GameObject;
            data                   = new PoolablePrefabData();
            data.gameObject        = newGo;
            data.poolableComponent = newGo.GetComponent <IPoolableComponent>();
        }

        data.gameObject.SetActive(true);
        data.gameObject.transform.position = position;
        data.gameObject.transform.rotation = rotation;

        data.poolableComponent.Spawned();

        _activeList.Add(data.gameObject, data);

        return(data.gameObject);
    }
    public GameObject Spawn(GameObject prefab)
    {
        PoolablePrefabData data;

        if (_inactiveList.Count > 0)
        {
            data = _inactiveList.Dequeue();
        }
        else
        {
            GameObject newGo = GameObject.Instantiate(prefab) as GameObject;
            data    = new PoolablePrefabData();
            data.go = newGo;
            data.poolableComponents = newGo.GetComponents <IPoolableComponent>();
        }

        data.go.SetActive(true);
        for (int i = 0; i < data.poolableComponents.Length; i++)
        {
            data.poolableComponents[i].Spawned();
        }

        _activeList.Add(data.go, data);
        return(data.go);
    }
Example #5
0
    public GameObject Spawn(GameObject obj, Vector3 position)
    {
        PoolablePrefabData data;

        if (inActiveList.Count >= 1)
        {
            data = inActiveList.Dequeue();
        }
        else
        {
            GameObject go = GameObject.Instantiate(obj);
            go.transform.SetParent(PoolingSystem.poolHolder, false);
            data                    = new PoolablePrefabData();
            data.gameObject         = go;
            data.poolableComponents = go.GetComponents <IPoolableComponent>();
        }

        if (data.gameObject != null)
        {
            data.gameObject.SetActive(true);
            data.gameObject.transform.position = position;
        }


        foreach (var x in data.poolableComponents)
        {
            x.Spawned();
        }


        activeList.Add(data.gameObject, data);

        return(data.gameObject);
    }
    public PoolablePrefabData Prespawn(GameObject prefab, Transform parent = null)
    {
        PoolablePrefabData data = Instantiate(prefab, Vector2.zero,
                                              Quaternion.identity, parent);

        data.go.SetActive(false);

        _inactiveList.Enqueue(data);

        return(data);
    }
    private PoolablePrefabData Instantiate(GameObject prefab, Vector2 position,
                                           Quaternion rotation, Transform parent = null)
    {
        var newGo      = Object.Instantiate(prefab, position, rotation, parent);
        var prefabData = new PoolablePrefabData
        {
            go = newGo,
            poolableComponent = newGo.GetComponent <IPoolableComponent>()
        };

        prefabData.poolableComponent.Init();
        return(prefabData);
    }
Example #8
0
    public void Prespawn(GameObject prefab, Transform parent)
    {
        GameObject newGameObject = GameObject.Instantiate(prefab, parent);

        PoolablePrefabData data = new PoolablePrefabData
        {
            gameObject         = newGameObject,
            poolableComponents = newGameObject.GetComponents <IPoolableComponent>()
        };

        data.gameObject.SetActive(false);
        inactiveList.Enqueue(data);
    }
    public bool Despawn(GameObject objToDespawn)
    {
        if (!_activeList.ContainsKey(objToDespawn))
        {
            Debug.LogError("This Object is not managed by this object pool!");
            return(false);
        }
        PoolablePrefabData data = _activeList[objToDespawn];

        for (int i = 0; i < data.poolableComponents.Length; ++i)
        {
            data.poolableComponents[i].Despawned();
        }
        data.go.SetActive(false);
        _activeList.Remove(objToDespawn);
        _inactiveList.Enqueue(data); return(true);
    }
Example #10
0
    public bool Despawn(GameObject objToDespawn)
    {
        if (!_activeList.ContainsKey(objToDespawn))
        {
            return(false);
        }

        PoolablePrefabData data = _activeList[objToDespawn];

        data.poolableComponent.Despawned();

        data.gameObject.SetActive(false);

        _activeList.Remove(objToDespawn);
        _inactiveList.Enqueue(data);

        return(true);
    }
    public PoolablePrefabData Spawn(GameObject prefab, Vector2 position,
                                    Quaternion rotation, Transform parent = null)
    {
        PoolablePrefabData data = _inactiveList.Count > 0
                                  ? _inactiveList.Dequeue()
                                  : Instantiate(prefab, position, Quaternion.identity);

        // loop for IPoolableComponents
        data.poolableComponent.Spawned();

        data.go.transform.position = position;
        data.go.transform.rotation = rotation;

        // Add to active list
        _activeList.Add(data.go, data);
        data.go.SetActive(true);

        return(data);
    }