Example #1
0
    //this is a doc comment, it creates a tooltip for the method. hover over the method name to see it!
    /// <summary>
    /// This method gets a fresh object from the pool
    /// </summary>
    /// <param name="pos">The position to move the fresh object to</param>
    /// <param name="rot">The rotation to bestow upon the fresh object</param>
    /// <param name="recycleOp">An optional delegate for recycling old objects</param>
    /// <returns>The object that was activated, so you can do stuff to it</returns>
    public GameObject Activate(Vector3 pos, Quaternion rot, CleanupOperation recycleOp = null)
    {
        GameObject toActivate;

        if (available.Count == 1)
        {
            //Debug.LogWarning("Out of Objects");
            if (shouldGrow)
            {
                GrowPool(prefab);
            }
            else
            {
                Recycle(recycleOp);
            }
        }

        //Debug.Log("Activating");
        //DebugState();
        toActivate = available.Dequeue();
        //Debug.Log("Activating " + toActivate.name);
        toActivate.transform.position = pos;
        toActivate.transform.rotation = rot;
        toActivate.SetActive(true);
        inUse.Enqueue(toActivate);

        //Debug.Log("Done Activating");
        //DebugState();

        return(toActivate);
    }
Example #2
0
    /// <summary>
    /// This method manually tells the pool to recycle. By default the pool does this automatically
    /// </summary>
    /// <param name="cleanup">An optional delegate for recycling old objects</param>
    public void Recycle(CleanupOperation cleanup = null)
    {
        GameObject toRecycle;

        //Debug.Log("Recycling");
        //DebugState();
        toRecycle = inUse.Dequeue();
        //Debug.Log("Recycling " + toRecycle.name);

        if (cleanup != null)
        {
            cleanup.Invoke(toRecycle);
        }

        toRecycle.SetActive(false);
        available.Enqueue(toRecycle);
        //Debug.Log("Done Recyling");
        //DebugState();
    }