コード例 #1
0
    // Use this for initialization
    void Awake()
    {
        instance = this;

        containerObject = new GameObject("ObjectPool");

        //Loop through the object prefabs and make a new list for each one.
        //We do this because the pool can only support prefabs set to it in the editor,
        //so we can assume the lists of pooled objects are in the same order as object prefabs in the array
        pooledObjects = new List <GameObject> [objectPrefabs.Length];

        int i = 0;

        foreach (GameObject objectPrefab in objectPrefabs)
        {
            pooledObjects[i] = new List <GameObject>();

            int bufferAmount;

            if (i < amountToBuffer.Length)
            {
                bufferAmount = amountToBuffer[i];
            }
            else
            {
                bufferAmount = defaultBufferAmount;
            }

            for (int n = 0; n < bufferAmount; n++)
            {
                GameObject newObj = Instantiate(objectPrefab) as GameObject;
                newObj.name = objectPrefab.name;
                PoolObject(newObj);
            }

            i++;
        }
    }
コード例 #2
0
 void Start()
 {
     //objectPool = GetComponent<ObjectPoolerSimple>();
     objectPool = GetComponent <VersatileObjectPooler>();
     Spawn();
 }