Exemple #1
0
    private ObjectPool CreateNewPool(ReturnToPool returnCondition)
    {
        ObjectPool pool = new ObjectPool(returnCondition.gameObject, ObjectPoolsHolder);

        CreateObjectPool(pool);
        objectPools.TryGetValue(returnCondition.Id, out pool);
        return(pool);
    }
Exemple #2
0
 public void Lasting(Transform target, float time, float d, bool isOverlay = false)
 {
     if (m_rtp == null)
         m_rtp = GetComponent<ReturnToPool>();
     m_rtp.deathTime = 0.1f + Mathf.Max(m_rtp.deathTime, time);
     GetControlled(target);
     if (m_ctrl.controlFuncDic.ContainsKey(type))
         StartCoroutine(m_ctrl.controlFuncDic[type](time, d));
 }
Exemple #3
0
    public void ReturnToPool(GameObject gameObject)
    {
        ReturnToPool returnCondition = gameObject.GetComponent <ReturnToPool>();

        if (returnCondition)
        {
            ReturnToPool(returnCondition);
        }
    }
Exemple #4
0
    public void ReturnToPool(ReturnToPool returnCondition)
    {
        ObjectPool pool;

        if (!objectPools.TryGetValue(returnCondition.Id, out pool))
        {
            pool = CreateNewPool(returnCondition);
        }

        pool.ReturnToPool(returnCondition.gameObject);
        spawnedObjects.Remove(returnCondition.gameObject);
    }
Exemple #5
0
 public void Lasting(Transform target, float time, float d, bool isOverlay = false)
 {
     if (m_rtp == null)
     {
         m_rtp = GetComponent <ReturnToPool>();
     }
     m_rtp.deathTime = 0.1f + Mathf.Max(m_rtp.deathTime, time);
     GetControlled(target);
     if (m_ctrl.controlFuncDic.ContainsKey(type))
     {
         StartCoroutine(m_ctrl.controlFuncDic[type](time, d));
     }
 }
Exemple #6
0
    private void AddProjectilesToPool(int amountToAdd)
    {
        ReturnToPool delegateToUse = HandleReturnToPool;

        for (int i = 0; i < amountToAdd; i++)
        {
            GameObject       newGameObject = Instantiate(_weaponProjectile, transform.position, Quaternion.identity);
            LinearProjectile projectile    = newGameObject.GetComponent <LinearProjectile>();
            projectile._returnToPool = delegateToUse;
            _projectilesNotInUse.Push(projectile);

            // turn projectile off
            newGameObject.SetActive(false);
        }
    }
    // Use this for initialization
    void Awake()
    {
        pool = new Stack <GameObject>();


        for (int i = 0; i < Max; i++)
        {
            pool.Push(Instantiate(Prefab));
            pool.Peek().transform.SetParent(transform);
            ReturnToPool rtp = pool.Peek().GetComponent <ReturnToPool>();
            if (rtp)
            {
                rtp.active = false;
            }
            pool.Peek().SetActive(false);
        }
        poolDirectory[Prefab] = this;
    }
 protected void OnReturnToPool()
 {
     ReturnToPool?.Invoke(this, null);
 }
Exemple #9
0
 public void Initialize(SpawnableObjectPool <Clone> PoolToReturn)
 {
     this.PoolToReturn = PoolToReturn;
     MyReturnToPool    = new ReturnToPool(PoolToReturn.ReturnObjectToPool);
 }
 private void AddPoolReference(GameObject newObject, ref ReturnToPool[] conditions)
 {
     conditions    = new ReturnToPool[1];
     conditions[0] = newObject.AddComponent <ReturnToPool>();
 }