Esempio n. 1
0
        public override void ReturnObject(APooledObject objectToReturn)
        {
            var pooledObject = objectToReturn.GetComponent <PooledObject>();

            if (pooledObject != null)
            {
                objectToReturn.transform.SetParent(transform);
                objectToReturn.gameObject.SetActive(false);
                objectToReturn.GetComponent <Rigidbody>().isKinematic = true;

                _availableObjects.Push(objectToReturn);
            }
            else
            {
                Destroy(objectToReturn);
            }
        }
Esempio n. 2
0
        public override APooledObject GetObject(Vector3 position = default, Vector3 scale = default)
        {
            APooledObject objectToGet = default(APooledObject);

            if (_availableObjects.Count > 0)
            {
                objectToGet = _availableObjects.Pop();
            }
            else
            {
                var pooledObject = Instantiate(_pooledObjectPrefab);
                pooledObject.Init(this);
                objectToGet = pooledObject;
            }

            objectToGet.transform.SetParent(null);
            objectToGet.transform.position   = position;
            objectToGet.transform.rotation   = Quaternion.identity;
            objectToGet.transform.localScale = scale;
            objectToGet.gameObject.SetActive(true);
            objectToGet.GetComponent <Rigidbody>().isKinematic = false;

            return(objectToGet);
        }