コード例 #1
0
ファイル: Pool.cs プロジェクト: 8yDefault/Stack
        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);
            }
        }
コード例 #2
0
ファイル: Pool.cs プロジェクト: 8yDefault/Stack
        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);
        }