Example #1
0
    public DiscScript GetDiscFromPool(DiscType discType)
    {
        if (allDiscPools.ContainsKey(discType))
        {
            DiscScript newDisc = null;

            if (allDiscPools[discType].Count > 0)
            {
                newDisc = allDiscPools[discType].Dequeue();
                newDisc.gameObject.SetActive(true);
            }
            else
            {
                newDisc = Instantiate(discTypeToPrefab[discType], discTypeToPoolParent[discType]);
                newDisc.SetUpModifiers();
                newDisc.SetDiscType(discType);
                newDisc.gameObject.SetActive(true);
            }

            inGameDiscs.Add(newDisc);

            return(newDisc);
        }

        return(null);
    }
Example #2
0
    public void SetUpPools()
    {
        allDiscPools         = new Dictionary <DiscType, Queue <DiscScript> >();
        discTypeToPrefab     = new Dictionary <DiscType, DiscScript>();
        discTypeToPoolParent = new Dictionary <DiscType, Transform>();

        DiscScript         newDisc       = null;
        Queue <DiscScript> newDiscQueue  = new Queue <DiscScript>();
        Transform          newPoolParent = null;

        foreach (DiscPoolParameters discPoolParameters in allDiscPoolParameters)
        {
            if (!allDiscPools.ContainsKey(discPoolParameters.discType))
            {
                newPoolParent = new GameObject().transform;
                newPoolParent.SetParent(poolsParent);
                newPoolParent.name = discPoolParameters.discType + "DiscsPool";
                newPoolParent.transform.localPosition = new Vector3();

                discTypeToPrefab.Add(discPoolParameters.discType, discPoolParameters.discPrefab);
                discTypeToPoolParent.Add(discPoolParameters.discType, newPoolParent);

                newDiscQueue = new Queue <DiscScript>();
                for (int i = 0; i < discPoolParameters.baseNumberOfElements; i++)
                {
                    newDisc = Instantiate(discPoolParameters.discPrefab, newPoolParent);
                    newDisc.SetUpModifiers();
                    newDisc.gameObject.SetActive(false);
                    newDisc.SetDiscType(discPoolParameters.discType);
                    newDiscQueue.Enqueue(newDisc);
                }

                allDiscPools.Add(discPoolParameters.discType, newDiscQueue);
            }
        }
    }
Example #3
0
    public DiscScript PeekDiscFromPool(DiscType discType)
    {
        if (allDiscPools.ContainsKey(discType))
        {
            DiscScript peekedDisc = null;

            if (allDiscPools[discType].Count > 0)
            {
                peekedDisc = allDiscPools[discType].Peek();
            }
            else
            {
                peekedDisc = Instantiate(discTypeToPrefab[discType], discTypeToPoolParent[discType]);
                peekedDisc.SetUpModifiers();
                peekedDisc.SetDiscType(discType);
                peekedDisc.gameObject.SetActive(false);
                allDiscPools[discType].Enqueue(peekedDisc);
            }

            return(peekedDisc);
        }

        return(null);
    }