/// <summary> /// Generates the handle for the sound that needs to be played /// </summary> /// <param name="sound"></param> /// <returns></returns> private SoundHandle GetGlobalHandle(Sound sound) { var source = players[sound.id]; var handle = new SoundHandle { audioSource = source, sound = sound }; return(handle); }
/// <summary> /// Waits for a sound to end, /// assumes a sound /// </summary> /// <param name="handle"></param> /// <returns></returns> private IEnumerator WaitForSoundEnd(SoundHandle handle) { // Wait for the sound to play yield return(new WaitForSeconds(handle.sound.audioClip.length - handle.audioSource.time)); // Remove context from currently playing sounds handleGroups.Remove(handle); // Invoke the on end callback on the sound handle handle.onEnd?.Invoke(); }
public void RegisterHandle(SoundHandle handle) { // Remove the handle for the sound after finishing playing var endRoutine = Systems.Instance.StartCoroutine(WaitForSoundEnd(handle)); handle.onStop.AddListener(() => { handle.onEnd.Invoke(); handleGroups.Remove(handle); StopCoroutine(endRoutine); }); handleGroups.Add(handle); }
public void Add(SoundHandle handle) { dict[handle.sound.id].Add(handle); }
public void Remove(SoundHandle handle) { dict[handle.sound.id].Remove(handle); }