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); }
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)); } }
public void PlayOneShot(AudioClip clip) { SJAudioSource source = GetFirstAvailable(); source.PlayOneShot(clip); }
public void PlayOneShotAtPosition(Vector3 position, AudioClip clip) { SJAudioSource source = GetFirstAvailable(); source.PlayOneShotAtPosition(position, clip); }