Beispiel #1
0
        public void AddFreeEffectObj(EffectObj instance)
        {
            Queue <EffectObj> currentQueue = new Queue <EffectObj>();

            if (effectObjs.TryGetValue(instance.GetCode(), out currentQueue) == false) //if the queue for this effect object type is not found
            {
                effectObjs.Add(instance.GetCode(), currentQueue);                      //add it
            }

            currentQueue.Enqueue(instance); //add the effect object to the right queue
        }
Beispiel #2
0
        //this method searches for a hidden effect object with a certain code so that it can be used again.
        public EffectObj GetFreeEffectObj(EffectObj prefab)
        {
            Assert.IsTrue(prefab != null, "[Effect Object Pool] invalid effect object prefab.");

            Queue <EffectObj> currentQueue;

            if (effectObjs.TryGetValue(prefab.GetCode(), out currentQueue) == false) //if the queue for this effect object type is not found
            {
                currentQueue = new Queue <EffectObj>();
                effectObjs.Add(prefab.GetCode(), currentQueue); //add it
            }

            if (currentQueue.Count == 0) //if the queue is empty then we need to create a new effect object of this types
            {
                //create new effect object, init it and add it to the queue
                EffectObj newEffect = Instantiate(prefab.gameObject, Vector3.zero, Quaternion.identity).GetComponent <EffectObj>();
                newEffect.Init(gameMgr);
                currentQueue.Enqueue(newEffect);
            }
            return(currentQueue.Dequeue()); //return the first inactive effect object in this queue
        }