Exemplo n.º 1
0
        public GameObject Instantiate(Vector3 position, Quaternion rotation)
        {
            GameObject gameObject;

            if (this.pool.Count > 0)
            {
                gameObject = this.pool.Pop();
                if (gameObject == null)
                {
                    gameObject = this.Instantiate(position, rotation);
                }
                else
                {
                    gameObject.transform.parent     = null;
                    gameObject.transform.position   = position;
                    gameObject.transform.rotation   = rotation;
                    gameObject.transform.localScale = Vector3.one;
                    gameObject.SetActive(true);
                }
                PoolReference component = gameObject.GetComponent <PoolReference>();
                component.inPool = false;
            }
            else
            {
                gameObject = Object.Instantiate <GameObject>(this.prefab, position, rotation);
                PoolReference poolReference = gameObject.AddComponent <PoolReference>();
                poolReference.pool   = this;
                poolReference.inPool = false;
            }
            return(gameObject);
        }
Exemplo n.º 2
0
        public void Destroy(PoolReference reference)
        {
            if (reference == null || reference.inPool || reference.pool != this)
            {
                return;
            }
            GameObject gameObject = reference.gameObject;

            gameObject.SetActive(false);
            this.pool.Push(gameObject);
            reference.inPool = true;
        }
        // Token: 0x060033F5 RID: 13301 RVA: 0x00152680 File Offset: 0x00150A80
        public void Destroy(GameObject element, float t)
        {
            if (element == null)
            {
                return;
            }
            PoolReference component = element.GetComponent <PoolReference>();

            if (component == null || component.pool == null)
            {
                UnityEngine.Object.Destroy(element);
                return;
            }
            component.Destroy(t);
        }