public void SpawnProjectile()
    {
        if (!bulletPrefab)
        {
            Debug.LogError("Bullet prefab was not found.");
            return;
        }

        PoolableComponent poolableComponent = bulletPrefab.gameObject.GetComponent <PoolableComponent>();

        GameObject obj;

        if (poolableComponent)
        {
            obj = PoolManager.Instance.GetFromPool(poolableComponent.GetPoolableType());
        }
        else
        {
            obj = Instantiate(bulletPrefab);
        }

        // WARNING
        // BU COMPONENTIN TEK ISI, PROJECTILE SPAWNLAMAK!
        // ONU AYARLAMAK DEGIL, SIMDILIK BURAYA YAPIYORUM.
        HandleProjectile(obj);
    }
Пример #2
0
    /// <summary>
    /// Recycles a GameObject into the specified pool. If the GameObject contains Components implementing the PoolableComponent interface, OnDespawn is called for those components.
    /// </summary>
    /// <param name="gameObject">The GameObject to recycle.</param>
    public void RecycleObject(GameObject gameObject)
    {
        PoolableComponent[] pooledObjectComponents = gameObject.GetComponents <PoolableComponent>();
        for (int i = 0; i < pooledObjectComponents.Length; i++)
        {
            PoolableComponent pooledObjectComponent = pooledObjectComponents[i];
            pooledObjectComponent.OnDespawn();
        }

        spawnedObjects.Remove(gameObject);
        gameObject.SetActive(false);
        pooledObjects.Enqueue(gameObject);
    }
    public void Die()
    {
        // if the object has poolableComponent it should go to the pool otherwise destroy it.
        PoolableComponent poolableComponent = this.gameObject.GetComponent <PoolableComponent>();

        if (poolableComponent)
        {
            poolableComponent.AddToPool();
        }
        else
        {
            Destroy(this.gameObject);
        }

        // would you like to do anything when the object disappeard? (Animation, UI change, ...)
        onDie?.Invoke();
    }
Пример #4
0
    /// <summary>
    /// Spawns an object from the pool queue. If the GameObject contains Components implementing the PoolableComponent interface, OnSpawn is called for those components.
    /// </summary>
    /// <returns>The reused GameObject.</returns>
    public GameObject SpawnObject()
    {
        GameObject gameObject = null;

        if (pooledObjects.Count == 0)
        {
            InstantiatePooledObjects(lastCreatedAmount * 2);
        }
        gameObject = pooledObjects.Dequeue();
        gameObject.SetActive(true);
        gameObject.name             = pooledPrefab.name;
        gameObject.transform.parent = null;
        spawnedObjects.Add(gameObject);

        PoolableComponent[] pooledObjectComponents = gameObject.GetComponents <PoolableComponent>();
        for (int i = 0; i < pooledObjectComponents.Length; i++)
        {
            PoolableComponent pooledObjectComponent = pooledObjectComponents[i];
            pooledObjectComponent.OnSpawn();
        }
        return(gameObject);
    }
 private void Awake()
 {
     backStarPoolableComponent   = backStarPrefab.GetComponent <PoolableComponent>();
     middleStarPoolableComponent = middleStarPrefab.GetComponent <PoolableComponent>();
     frontStarPoolableComponent  = FrontStarPrefab.GetComponent <PoolableComponent>();
 }
Пример #6
0
 private void Awake()
 {
     poolableComponent = gameObject.GetComponent <PoolableComponent>();
 }
 private void Awake()
 {
     poolableComponent = pipePrefab.gameObject.GetComponent <PoolableComponent>();
 }
 // Start is called before the first frame update
 void Start()
 {
     poolableComponent = enemyPrefab.gameObject.GetComponent <PoolableComponent>();
 }