Esempio n. 1
0
    /// <summary>
    /// This fuction sets the params for the object pool that will be created.
    /// </summary>
    /// <param name="GenericObj">Choose from the pooledSubject enum what the secondary "generic" object is</param>
    /// <param name="PoolStartSize">the amount of objects the pool starts with</param>
    /// <param name="IncreaseIncrement">the amount of objects that will be added when the pool hits its current limit</param>
    /// <param name="ManagerTicksBeforeClean">the amount of ticks needed before the pool wil check for a clean</param>
    /// <param name="CleanThreshold">the amount of unused objects needed for a clean to happen example</param>
    public void Init(PooledSubObject GenericObj, int PoolStartSize = 20, int IncreaseIncrement = 5, int ManagerTicksBeforeClean = 5, int CleanThreshold = 20)
    {
        m_ObjectsAliveInPool = 0;


        m_objEnum = GenericObj;
        PoolObj TempData = ObjectPrefab.GetComponent <PoolObj>();

        TempData.Pool                 = this;
        this.m_CleanThreshold         = CleanThreshold;
        this.m_IncreaseIncrement      = IncreaseIncrement;
        this.m_anagerTicksBeforeClean = ManagerTicksBeforeClean;

        //m_DeadList = new Queue<GameObject>();
        m_DeadList = new Queue <PoolObj>();

        for (int i = 0; i < PoolStartSize; i++)
        {
            GameObject NewPoolGameObj = Instantiate(ObjectPrefab, transform);
            PoolObj    poolObj        = NewPoolGameObj.GetComponent <PoolObj>();
            switch (GenericObj)
            {
            case PooledSubObject.Default:
                poolObj.GenericObj = null;
                break;

            case PooledSubObject.GameObject:
                poolObj.GenericObj = poolObj.gameObject;
                break;

            case PooledSubObject.VisualEffect:
                poolObj.GenericObj = poolObj.gameObject.GetComponent <VisualEffect>();
                break;

            case PooledSubObject.Enemy:
                poolObj.GenericObj = poolObj.gameObject.GetComponent <Enemy>();
                break;

            case PooledSubObject.Rigidbody:
                poolObj.GenericObj = poolObj.gameObject.GetComponent <Rigidbody>();
                break;

            case PooledSubObject.TowerProjectile:
                poolObj.GenericObj = poolObj.gameObject.GetComponent <TowerProjectile>();
                break;

            default:
                //m_GenericObj = null;
                break;
            }
            m_DeadList.Enqueue(poolObj);

            m_ObjectsInPool++;
            NewPoolGameObj.SetActive(false);
        }
    }