public void Initialize(ObjectPoolData data)
        {
            this.data       = data;
            currentPoolSize = data.startSize;

            for (int i = 0; i < currentPoolSize; i++)
            {
                Add(false);
            }
        }
Example #2
0
        void GeneratePool(ObjectPoolData data)
        {
            GameObject pool = new GameObject();

            pool.name             = data.prefab.name;
            pool.transform.parent = transform;

            if (data.prefab == null)
            {
                Debug.LogError("Prefab not set for " + pool.name + " object pool");
            }

            if (data.isOnOverlayCanvas)
            {
                var canvas = pool.AddComponent <Canvas>();
                canvas.renderMode = RenderMode.ScreenSpaceOverlay;
            }

            ObjectSpawner spawner = pool.AddComponent <ObjectSpawner>();

            spawner.Initialize(data);

            objectPoolDict.Add(data.prefab, spawner);
        }