Esempio n. 1
0
    // Use this for initialization
    void Start ()
    {
        // Singleton instance
        instance = this;

        // Initialize effects pool
        if (poolItems.Length > 0)
        {
            pool = new Dictionary<Transform, Transform[]>();

            for (int i = 0; i < poolItems.Length; i++)
            {
                Transform[] itemArray = new Transform[poolLength[i]];

                for (int x = 0; x < poolLength[i]; x++)
                {
                    Transform newItem = (Transform)Instantiate(poolItems[i], Vector3.zero, Quaternion.identity);
                    newItem.gameObject.SetActive(false);
                    newItem.parent = transform;

                    itemArray[x] = newItem;
                }

                pool.Add(poolItems[i], itemArray);
            }
        }

        // Initialize audio pool
        if (audioPoolItems.Length > 0)
        {
            audioPool = new Dictionary<AudioClip, AudioSource[]>();

            for (int i = 0; i < audioPoolItems.Length; i++)
            {
                AudioSource[] audioArray = new AudioSource[audioPoolLength[i]];

                for (int x = 0; x < audioPoolLength[i]; x++)
                {
                    AudioSource newAudio = ((Transform)Instantiate(audioSourcePrefab, Vector3.zero, Quaternion.identity)).GetComponent<AudioSource>();
                    newAudio.clip = audioPoolItems[i];

                    newAudio.gameObject.SetActive(false);
                    newAudio.transform.parent = transform;

                    audioArray[x] = newAudio;
                }

                audioPool.Add(audioPoolItems[i], audioArray);
            }
        }
    }
Esempio n. 2
0
    // Use this for initialization
    void Start()
    {
        // Singleton instance
        instance = this;

        // Initialize effects pool
        if (poolItems.Length > 0)
        {
            pool = new Dictionary <Transform, Transform[]>();

            for (int i = 0; i < poolItems.Length; i++)
            {
                Transform[] itemArray = new Transform[poolLength[i]];

                for (int x = 0; x < poolLength[i]; x++)
                {
                    Transform newItem = (Transform)Instantiate(poolItems[i], Vector3.zero, Quaternion.identity);
                    newItem.gameObject.SetActive(false);
                    newItem.parent = transform;

                    itemArray[x] = newItem;
                }

                pool.Add(poolItems[i], itemArray);
            }
        }

        // Initialize audio pool
        if (audioPoolItems.Length > 0)
        {
            audioPool = new Dictionary <AudioClip, AudioSource[]>();

            for (int i = 0; i < audioPoolItems.Length; i++)
            {
                AudioSource[] audioArray = new AudioSource[audioPoolLength[i]];

                for (int x = 0; x < audioPoolLength[i]; x++)
                {
                    AudioSource newAudio = ((Transform)Instantiate(audioSourcePrefab, Vector3.zero, Quaternion.identity)).GetComponent <AudioSource>();
                    newAudio.clip = audioPoolItems[i];

                    newAudio.gameObject.SetActive(false);
                    newAudio.transform.parent = transform;

                    audioArray[x] = newAudio;
                }

                audioPool.Add(audioPoolItems[i], audioArray);
            }
        }
    }