Ejemplo n.º 1
0
        public bool DespawnInstance(Transform xform, bool sendEventMessage)
        {
            if (this.logMessages)
            {
                Debug.Log(string.Format("SpawnPool {0} ({1}): Despawning '{2}'",
                                        this.spawnPool.poolName,
                                        this.prefab.name,
                                        xform.name));
            }

            this._spawned.Remove(xform);
            this._despawned.Add(xform);

            if (sendEventMessage)
            {
                xform.gameObject.BroadcastMessage(
                    "OnDespawned",
                    this.spawnPool,
                    SendMessageOptions.DontRequireReceiver
                    );
            }

            PoolManagerUtils.SetActive(xform.gameObject, false);

            if (!this.cullingActive && this.cullDespawned && this.totalCount > this.cullAbove)
            {
                this.cullingActive = true;
                this.spawnPool.StartCoroutine(CullDespawned());
            }
            return(true);
        }
Ejemplo n.º 2
0
        internal Transform SpawnInstance(Vector3 pos, Quaternion rot)
        {
            if (this.limitInstances && this.limitFIFO &&
                this._spawned.Count >= this.limitAmount)
            {
                Transform firstIn = this._spawned[0];

                if (this.logMessages)
                {
                    Debug.LogErrorFormat("SpawnPool {0} ({1}): LIMIT REACHED! FIFO=True. Calling despawning for {2}...",
                                         this.spawnPool.poolName,
                                         this.prefab.name,
                                         firstIn
                                         );
                }

                this.DespawnInstance(firstIn);
                this.spawnPool._spawned.Remove(firstIn);
            }

            Transform inst;

            if (this._despawned.Count == 0)
            {
                inst = this.SpawnNew(pos, rot);
            }
            else
            {
                inst = this._despawned[0];
                this._despawned.RemoveAt(0);
                this._spawned.Add(inst);

                if (inst == null)
                {
                    var msg = "Make sure you didn't delete a despawned instance directly.";
                    throw new MissingReferenceException(msg);
                }

                if (this.logMessages)
                {
                    Debug.Log(string.Format("SpawnPool {0} ({1}): respawning '{2}'.",
                                            this.spawnPool.poolName,
                                            this.prefab.name,
                                            inst.name));
                }


                inst.position = pos;
                inst.rotation = rot;
                PoolManagerUtils.SetActive(inst.gameObject, true);
            }
            return(inst);
        }
Ejemplo n.º 3
0
        internal void AddUnpooled(Transform inst, bool despawn)
        {
            this.nameInstance(inst);

            if (despawn)
            {
                PoolManagerUtils.SetActive(inst.gameObject, false);
                this._despawned.Add(inst);
            }
            else
            {
                this._spawned.Add(inst);
            }
        }