コード例 #1
0
        public void Initialize(ObjectPoolData data)
        {
            this.data       = data;
            currentPoolSize = data.startSize;

            for (int i = 0; i < currentPoolSize; i++)
            {
                Add(false);
            }
        }
コード例 #2
0
        private 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.isOnCanvas)
            {
                var canvas = pool.AddComponent <Canvas>();
                canvas.renderMode = RenderMode.ScreenSpaceOverlay;
            }

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

            spawner.Initialize(data);

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