Ejemplo n.º 1
0
            public GameObject Spawn(GameObject targetObject, Vector3 pos, Quaternion rotation)
            {
                if (!poolDictionary.ContainsKey(targetObject.name))
                {
                    SetUpPool(targetObject);
                    Debug.LogWarning("Pool whith name " + targetObject.name + " doesn´t exist, create it in editor to prevent lags");
                    //return ;
                }
                GameObject obj;

                if (poolDictionary[targetObject.name].Count == 0)
                {
                    Debug.LogWarning("Pool whith name " + targetObject.name + " has empty queue, try increase number of spawned objects");
                    obj = Instantiate(targetObject);
                }
                else
                {
                    obj = poolDictionary[targetObject.name].Dequeue();
                }
                obj.transform.position = pos;
                obj.transform.rotation = rotation;
                obj.SetActive(true);
                IPoolSystem pooledObj = obj.GetComponent <IPoolSystem>();

                if (pooledObj != null)
                {
                    pooledObj.OnPoolSpawn();
                }
                return(obj);
            }
Ejemplo n.º 2
0
            public void PlaySound(AudioClip clip, Vector3 pos, Quaternion rotation)
            {
                GameObject obj;

                if (poolDictionary["AudioProp"].Count == 0)
                {
                    Debug.LogWarning("Pool whith name AudioProp has empty queue, try increase number of spawned objects");
                    obj = Instantiate(audioProp);
                }
                else
                {
                    obj = poolDictionary["AudioProp"].Dequeue();
                }
                obj.GetComponent <AudioSource>().clip = clip;
                obj.transform.position = pos;
                obj.transform.rotation = rotation;
                obj.SetActive(true);
                IPoolSystem pooledObj = obj.GetComponent <IPoolSystem>();

                if (pooledObj != null)
                {
                    pooledObj.OnPoolSpawn();
                }
            }