/// <summary>
        /// Initialize selected object.
        /// </summary>
        /// <param name="_prefab"> Prefab asset reference. </param>
        /// <param name="_callBack"></param>
        /// <returns> False if there is no this prefab type in PoolHandler setup.
        /// True if you setted this type up. </returns>
        private bool InitializeObject(AssetReference _prefab, Action <PoolObject> _callBack)
        {
            PoolObject _poolObject = null;
            int        _poolIndex  = -1;

            if (TryFindPoolObjectDataByAssetReference(_prefab, ref _poolIndex) == false)
            {
                Debug.LogWarning("There is no this prefab type in setup");
                return(false);
            }

            ObjectsRegister _register = objectPools[_poolIndex].Register;

            if (_register.TryGetAvailableObject(ref _poolObject) == true)
            {
                objectPools[_poolIndex].UpdateRegister(_register);
                _poolObject.OnHandlerReturnInvoke += ReturnToPool;
                _callBack?.Invoke(_poolObject);
                _poolObject.GetFromPool(_poolIndex);
                return(true);
            }

            ObjectInstatniationCallback _instatniationCallback = InitializeNewPoolObject;

            InvokeData _invokeData = new InvokeData(_poolObject, _poolIndex, _callBack);

            StartCoroutine(InstantiateObject(_prefab, _instatniationCallback, _invokeData));

            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// Register pool object in register.
        /// </summary>
        public void RegisterObject(PoolObject _poolObject)
        {
            instancesCount++;

            ObjectsRegister _register = Register;

            _register.AddObjectToRegister(_poolObject);

            UpdateRegister(_register);
        }
Esempio n. 3
0
        /// <summary>
        /// Unregister pool object in register.
        /// </summary>
        public void UnregisterObject(PoolObject _poolObject)
        {
            instancesCount--;

            ObjectsRegister _register = Register;

            _register.RemoveObjectFromRegister(_poolObject);

            UpdateRegister(_register);
        }
Esempio n. 4
0
 public PoolObjectData(
     AssetReference _prefab,
     int _maxInstancesAmount,
     bool _instantiateObjectOnAwake,
     bool _destroyOverflowInstances,
     float _overflowInstancesLifeTime)
 {
     prefab                    = _prefab;
     maxInstancesAmount        = _maxInstancesAmount;
     instantiateObjectOnAwake  = _instantiateObjectOnAwake;
     destroyOverflowInstances  = _destroyOverflowInstances;
     overflowInstancesLifeTime = _overflowInstancesLifeTime;
     instancesCount            = 0;
     register                  = new ObjectsRegister();
     registerCreated           = true;
 }
Esempio n. 5
0
 public void UpdateRegister(ObjectsRegister _register)
 {
     register = _register;
 }