Пример #1
0
 public ObjectPool NewPool(GameObject prefab)
 {
     ObjectPool.Options options = new ObjectPool.Options();
     options.prefab      = prefab;
     options.maxCapacity = capacityOfMissingPool;
     return(NewPool(options));
 }
Пример #2
0
        public ObjectPool NewPool(ObjectPool.Options options)
        {
            options.Preprocess();
            if (pools_.ContainsKey(options.name))
            {
                Debug.LogError(string.Format("There is already a ObjectPool of {0}, you must use unique name.", options.name));
                return(null);
            }
            else if (options.prefab == null)
            {
                Debug.LogError("Prefab of options must be set.");
                return(null);
            }

            Transform folder;

            if (options.poolFolder != null)
            {
                folder = options.poolFolder;
            }
            else
            {
                folder          = new GameObject(options.name).transform;
                folder.parent   = transform;
                folder.position = Vector3.zero;
            }

            var object_pool = new ObjectPool(options, folder);

            pools_[options.name] = object_pool;

            return(object_pool);
        }