Exemple #1
0
        public static GameObject Instantiate(GameObject prefab, Vector3 position, Quaternion rotation)
        {
            PoolObject po = GetOrCreatePoolObject(prefab);

            List <GameObject> sceneObjectsList;

            if (objectsByPoolObject.TryGetValue(po, out sceneObjectsList))
            {
                if (sceneObjectsList.Any(x => !x.activeInHierarchy))
                {
                    return(ActivateAvailableObject(position, rotation, sceneObjectsList));
                }
            }

            else
            {
                objectsByPoolObject.Add(po, new List <GameObject>());
                CreateParent(po);
            }

            return(InstantiateNewObject(prefab, position, rotation, po));
        }
Exemple #2
0
 public void Add(PoolObject item)
 {
     poolObjects.Add(item);
 }
Exemple #3
0
        private static GameObject InstantiateNewObject(GameObject prefab, Vector3 position, Quaternion rotation, PoolObject po)
        {
            Transform parent = parentByPoolObject[po];

            GameObject createdObject = Object.Instantiate(prefab, position, rotation, parent);

            objectsByPoolObject[po].Add(createdObject);

            return(createdObject);
        }