예제 #1
0
        internal void Despawn(PoolObject clone)
        {
            if ((object)clone.Previous == null)
            {
                if ((object)_activeHead == _activeTail)
                {
                    _activeHead = null;
                    _activeTail = null;
                }
                else
                {
                    _activeHead          = _activeHead.Next;
                    _activeHead.Previous = null;
                }
            }
            else if ((object)clone.Next == null)
            {
                _activeTail      = _activeTail.Previous;
                _activeTail.Next = null;
            }
            else
            {
                clone.Previous.Next = clone.Next;
                clone.Next.Previous = clone.Previous;
            }

            clone.Previous = _inactiveTail;
            clone.Next     = null;

            if ((object)_inactiveTail != null)
            {
                _inactiveTail.Next = clone;
            }

            _inactiveTail = clone;

            clone.IsSpawned = false;

            clone.OnDespawn();
            clone.GameObject.SetActive(false);
        }
예제 #2
0
        public PoolObject Instantiate()
        {
            PoolObject clone;

            try
            {
                clone = Object.Instantiate(_source);
            }
            catch
            {
                clone = null;
            }

            if ((object)clone != null)
            {
                clone.GameObject           = clone.gameObject;
                clone.GameObject.hideFlags = HideFlags.HideInHierarchy;

                Object.DontDestroyOnLoad(clone.GameObject);

                clone.Pool = this;

                if ((object)_inactiveTail != null)
                {
                    clone.Previous = _inactiveTail;

                    _inactiveTail.Next = clone;
                }

                _inactiveTail = clone;

                clone.OnInstantiate();
                clone.GameObject.SetActive(false);
            }

            return(clone);
        }
예제 #3
0
        public PoolObject SpawnDebug()
        {
            PoolObject clone;

            if ((object)_inactiveTail == null)
            {
                try
                {
                    clone = Object.Instantiate(_source);
                }
                catch
                {
                    clone = null;
                }

                if ((object)clone == null)
                {
                    Debug.LogError(_source.gameObject.name +
                                   " instantiation failed: out of memory. Respawning clones instead.");

                    clone = _activeHead;

                    if ((object)_activeHead != _activeTail)
                    {
                        _activeHead          = _activeHead.Next;
                        _activeHead.Previous = null;

                        clone.Previous = _activeTail;
                        clone.Next     = null;

                        _activeTail.Next = clone;
                        _activeTail      = clone;
                    }

                    clone.OnRespawn();
                }
                else
                {
                    clone.GameObject           = clone.gameObject;
                    clone.GameObject.hideFlags = HideFlags.HideInHierarchy;

                    Object.DontDestroyOnLoad(clone.GameObject);

                    clone.Pool     = this;
                    clone.Previous = _activeTail;

                    _activeTail.Next = clone;
                    _activeTail      = clone;

                    clone.OnInstantiate();
                    clone.OnSpawn();

                    clone.IsSpawned = true;

                    clone.GameObject.SetActive(true);
                }
            }
            else
            {
                clone = _inactiveTail;

                _inactiveTail = _inactiveTail.Previous;

                if ((object)_inactiveTail != null)
                {
                    _inactiveTail.Next = null;
                }

                clone.Previous = _activeTail;

                if ((object)_activeHead == null)
                {
                    _activeHead = clone;
                    _activeTail = _activeHead;
                }
                else
                {
                    _activeTail.Next = clone;
                    _activeTail      = clone;
                }

                clone.OnSpawn();

                clone.IsSpawned = true;

                clone.GameObject.SetActive(true);
            }

            return(clone);
        }