Exemple #1
0
    private SJAudioSource GetFirstAvailable()
    {
        for (int i = 0; i < audioSourcesPool.Count; i++)
        {
            if (audioSourcesPool[i].IsPlaying == false)
            {
                return(audioSourcesPool[i]);
            }
        }

        SJAudioSource newSource = GameObject.Instantiate <SJAudioSource>(audioSourcePrefab);

        audioSourcesPool.Add(newSource);

        return(newSource);
    }
Exemple #2
0
    private SoundManager()
    {
        channels         = new Dictionary <SoundChannels, SoundChannel>();
        readOnlyChannels = new ReadOnlyDictionary <SoundChannels, SoundChannel>(channels);

        for (SoundChannels i = 0; i < SoundChannels.Count; i++)
        {
            channels.Add(i, new SoundChannel(this));
        }

        audioSourcesPool  = new List <SJAudioSource>();
        audioSourcePrefab = SJResources.Instance.LoadGameObjectAndGetComponent <SJAudioSource>("SJAudioSourcePrefab");

        for (int i = 0; i < initialPoolSize; i++)
        {
            audioSourcesPool.Add(GameObject.Instantiate <SJAudioSource>(audioSourcePrefab));
        }
    }
Exemple #3
0
    public void PlayOneShot(AudioClip clip)
    {
        SJAudioSource source = GetFirstAvailable();

        source.PlayOneShot(clip);
    }
Exemple #4
0
    public void PlayOneShotAtPosition(Vector3 position, AudioClip clip)
    {
        SJAudioSource source = GetFirstAvailable();

        source.PlayOneShotAtPosition(position, clip);
    }