/// <summary>
        /// Return projectile with sent data
        /// </summary>
        /// <param name="data">Data</param>
        /// <returns>Projectile</returns>
        public AbstractProjectile GetProjectile(AbstractProjectileData data)
        {
            if (CheckData(data) == false)
            {
                AbstractProjectile projectile = CreateProjectile(data);

                if (isInitPreferedPoolSize)
                {
                    coroutines.Add(StartCoroutine(InitPoolCoroutine(data)));
                }

                return(projectile);
            }

            AbstractProjectile foundedProjectile = dictionary[data.Id].List.Where(p => p && p.IsActive == false).FirstOrDefault();

            if (foundedProjectile)
            {
                return(foundedProjectile);
            }

            if (isInitPreferedPoolSize)
            {
                coroutines.Add(StartCoroutine(AddProjectilesCoroutine(data, data.PreferedPoolSize - 1)));
            }

            return(CreateProjectile(data));
        }
        private AbstractProjectile CreateProjectile(AbstractProjectileData data)
        {
            AbstractProjectile createdProjectile
                = Instantiate(data.Prefab, dictionary[data.Id].Pool).GetComponent <AbstractProjectile>();

            createdProjectile.IsActive = false;

            dictionary[data.Id].List.Add(createdProjectile);

            return(createdProjectile);
        }
Example #3
0
        /// <summary>
        /// Cast projectile
        /// </summary>
        /// <param name="position">Position</param>
        /// <param name="direction">Direction</param>
        /// <param name="data">Data</param>
        public void Cast(ShootData shootData, AbstractProjectileData projectileData)
        {
            AbstractProjectile projectile = projectilePool.GetProjectile(projectileData);

            if (projectile == false)
            {
                Debug.LogError("projectile == null");

                return;
            }

            projectile.Init(shootData, projectileData);
        }