Example #1
0
    //similiar to Despawn(), but also yields for 'PoolTimeObject.time' seconds
    //started by Despawn(instance, time) above
    IEnumerator DespawnInTime(PoolTimeObject timeObject)
    {
        //cache instance to deactivate
        GameObject instance = timeObject.instance;

        //wait for defined seconds
        yield return(new WaitForSeconds(timeObject.time));

        //loop through all pool options of this component
        for (int cnt = 0; cnt < this._PoolOptions.Count; cnt++)
        {
            PoolOptions poolOptions = this._PoolOptions[cnt];
            //seach in active instances for this instance
            if (poolOptions.active.Contains(instance))
            {
                //in case it was unparented during runtime, reparent it now
                if (instance.transform.parent != container)
                {
                    instance.transform.parent = container;
                }

                //let Deactivate() of PoolOption disable this instance
                poolOptions.Deactivate(instance);

                //remove instance from our active list of this component
                this._AllActive.Remove(instance);
            }
        }
    }
Example #2
0
    //deactivate instance passed in
    public void Despawn(GameObject instance)
    {
        //loop through all pool options of this component
        for (int cnt = 0; cnt < this._PoolOptions.Count; cnt++)
        {
            PoolOptions poolOptions = this._PoolOptions[cnt];
            //seach in active instances for this instance
            if (poolOptions.active.Contains(instance))
            {
                //in case it was unparented during runtime, reparent it now
                if (instance.transform.parent != container)
                {
                    instance.transform.parent = container;
                }

                //let Deactivate() of PoolOption disable this instance
                poolOptions.Deactivate(instance);

                //remove instance from our active list of this component
                this._AllActive.Remove(instance);
                //skip further code
                return;
            }
        }

        //no PoolOption contains the passed in instance, debug a warning
        Debug.LogWarning("Can't despawn - Prefab not found: " + instance.name + " in Pool " + this.name);
    }