예제 #1
0
        private void Awake()
        {
            if (Instance != null)
            {
                Destroy(gameObject);
                return;
            }
            Instance = this;

            for (int i = 0; i < pools.Length; i++)
            {
                nameToIndex.Add(pools[i].prefab.objectName, i);

                // Instantiating objects first time
                for (int j = 0; j < pools[i].startCount; j++)
                {
                    PoolObject _obj = Instantiate(pools[i].prefab, new Vector3(1000, 1000), Quaternion.identity, transform);
                    _obj.Deactivate();
                    pools[i].AddObject(_obj);
                }
            }
        }
예제 #2
0
        public PoolObject Spawn(PoolObjectIdentificator _name, Vector3 pos, Quaternion rot)
        {
            if (!nameToIndex.ContainsKey(_name))
            {
                Debug.LogError("<color=red>There is no pool named " + _name + " in Dictionary</color>");
                return(null);
            }
            // Adding objects if queue is empty
            if (pools[nameToIndex[_name]].ObjectsToUse <= 0)
            {
                for (int j = 0; j < pools[nameToIndex[_name]].growBy; j++)
                {
                    pools[nameToIndex[_name]].AddObject(Instantiate(pools[nameToIndex[_name]].prefab, transform));
                }
            }

            PoolObject _obj = pools[nameToIndex[_name]].GetObject();

            _obj.transform.SetPositionAndRotation(pos, rot);

            _obj.Activate(this);

            return(_obj);
        }
예제 #3
0
 internal void AddObject(PoolObject _obj)
 {
     objects.Enqueue(_obj);
     ObjectsToUse++;
 }
예제 #4
0
파일: Pool.cs 프로젝트: Wokarol/Asteroids
 void ReturnToPool(PoolObject poolObject)
 {
     poolObject.Deactivate();
     poolObjects.Push(poolObject);
 }