예제 #1
0
    public void returnObject(GameObject elementGO)
    {
        ObjectPoolElement element = elementGO.GetComponent <ObjectPoolElement> ();

        element.deactivate();
        freeElementIndexes.Add(pool.IndexOf(element));
    }
예제 #2
0
    void doubleCapacity(GameObject duplicateThis)
    {
        int poolCapacity = pool.Count;

        for (int i = 0; i < poolCapacity; i++)
        {
            GameObject clone = (GameObject)Instantiate(duplicateThis);
            clone.name = duplicateThis.name;
            clone.transform.SetParent(duplicateThis.transform.parent);
            ObjectPoolElement clonePoolElement = clone.GetComponent <ObjectPoolElement>();
            clonePoolElement.copyTransform(duplicateThis);
            pool.Add(clonePoolElement);
            freeElementIndexes.Add(pool.IndexOf(clonePoolElement));
        }
    }
예제 #3
0
    void Awake()
    {
        pool = new List <ObjectPoolElement> ();
        freeElementIndexes = new List <int> ();

        for (int i = 0; i < transform.childCount; i++)
        {
            ObjectPoolElement element = transform.GetChild(i).GetComponent <ObjectPoolElement> ();
            if (element == null)
            {
                Debug.Log(transform.GetChild(i).name + " does not contain a ObjectPoolElement attached");
            }
            else
            {
                pool.Add(element);
                freeElementIndexes.Add(i);
            }
        }
    }
예제 #4
0
    void Awake()
    {
        GameObject clone = (GameObject)Instantiate(prefabToPool, Vector3.zero, Quaternion.identity, transform);

        clone.SetActive(false);

        pool = new List <ObjectPoolElement>();
        freeElementIndexes = new List <int>();

        for (int i = 0; i < transform.childCount; i++)
        {
            ObjectPoolElement element = transform.GetChild(i).GetComponent <ObjectPoolElement>();
            if (element == null)
            {
                Debug.Log(transform.GetChild(i).name + " does not contain a ObjectPoolElement attached");
            }
            else
            {
                pool.Add(element);
                freeElementIndexes.Add(i);
            }
        }
    }